import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
int row = convertRowIndexToModel(rowAtPoint(e.getPoint()));
TableModel m = getModel();
final String videoId = (String) m.getValueAt(row, 0);
- final Thumbnail thumbnail = thumbRepository.getThumnail(videoId);
- if(thumbnail == null){
- return "動画情報取得中...";
+ try {
+ final Thumbnail thumbnail = thumbRepository.getThumnail(videoId);
+ if (thumbnail == null) {
+ return videoId + ": 動画情報未取得";
+ }
+
+ final URL imageUrl = thumbnail.getImageFile().toURI().toURL();
+
+ return "<html>" + videoId + ": " + thumbnail.getTitle()
+ + " (" + thumbnail.getLength() + ")" + "<br/>"
+ + "<img src=\"" + imageUrl + "\"/>"
+ + "</html>";
+ } catch (Throwable ex) {
+ logger.warn(null, ex);
+ return videoId + ": 情報取得できません";
}
- return "<html>" + videoId + ":" + thumbnail.getTitle() + "</html>";
}
};
tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
logger.debug(downProf.toString());
logger.debug(convProf.toString());
- thumbRepository.request(downProf.getProxyProfile(), id);
+ final File tempDir = new File(Config.INSTANCE.getSystemTempDir());
+ thumbRepository.request(downProf.getProxyProfile(), tempDir, id);
final RequestProcess rp = new RequestProcess(downProf, id, convProf);
taskManager.add(rp);
package yukihane.inqubus.thumbnail;
import java.awt.image.BufferedImage;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.imageio.ImageIO;
-import javax.swing.ImageIcon;
import nicobrowser.NicoHttpClient;
import nicobrowser.util.RssContent;
import nicobrowser.util.RssContentParser;
private final ExecutorService executorService = Executors.newCachedThreadPool();
private final Map<String, Thumbnail> thumbnailMap = new HashMap<>();
- public void request(ProxyProfile proxy, String videoId) {
+ public void request(ProxyProfile proxy, File tempDir, String videoId) {
synchronized (thumbnailMap) {
final Thumbnail value = thumbnailMap.get(videoId);
if (value != null) {
}
}
- executorService.execute(new ThumnailFetchWorker(proxy, videoId));
+ executorService.execute(new ThumnailFetchWorker(proxy, tempDir, videoId));
}
public Thumbnail getThumnail(String videoId) {
private final ProxyProfile proxy;
private final String videoId;
+ private final File tempDir;
- private ThumnailFetchWorker(ProxyProfile proxy, String videoId) {
+ private ThumnailFetchWorker(ProxyProfile proxy, File tempDir, String videoId) {
this.proxy = proxy;
this.videoId = videoId;
+ this.tempDir = tempDir;
}
@Override
final RssContent cont = new RssContentParser().parse(is);
final URL thumbUrl = new URL(cont.getThumbnail_url());
- ImageIcon icon;
+ final File imageFile;
try (InputStream imageStream = client.get(thumbUrl)) {
final BufferedImage image = ImageIO.read(imageStream);
- icon = new ImageIcon(image);
+ imageFile = File.createTempFile("thumb", ".jpg", tempDir);
+ imageFile.deleteOnExit();
+ ImageIO.write(image, "jpeg", imageFile);
}
- final Thumbnail thumb = new Thumbnail(cont.getTitle(), icon);
+ final Thumbnail thumb = new Thumbnail(cont.getTitle(), cont.getLength(), imageFile);
synchronized (thumbnailMap) {
thumbnailMap.put(videoId, thumb);
package yukihane.inqubus.thumbnail;
+import java.io.File;
import javax.swing.ImageIcon;
/**
public class Thumbnail {
private final String title;
- private final ImageIcon image;
+ private final String length;
+ private final File imageFile;
- public Thumbnail(String title, ImageIcon image) {
+ Thumbnail(String title, String length, File imageFile) {
this.title = title;
- this.image = image;
+ this.length = length;
+ this.imageFile = imageFile;
}
public String getTitle() {
return title;
}
- public ImageIcon getImage() {
- return image;
+ public String getLength() {
+ return length;
+ }
+
+ public File getImageFile() {
+ return imageFile;
}
}