Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main/java/uk/co/probablyfine/aoko/download/ArtDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
Expand Down Expand Up @@ -32,9 +34,9 @@ public void getVimeoArt(String vimeoUrl, String vimeoId) throws IOException {
}

public void getYoutubeArt(String youtubeId) throws IOException {
final String url = "http://img.youtube.com/vi/"+youtubeId+"/1.jpg";
final String url = "http://img.youtube.com/vi/"+youtubeId+"/default.jpg";
final String path = new File(downloadPath,youtubeId+".jpg").getAbsolutePath();
downloadFile(path, url);
downloadFile(url, path);//flipped the order of the arguments from (path, url) to (url, path)
}

public void getAlbumArt(Map<String,String> args, String filename) throws ParserConfigurationException, MalformedURLException, SAXException, IOException {
Expand All @@ -57,11 +59,36 @@ public void getAlbumArt(Map<String,String> args, String filename) throws ParserC

public void downloadFile(String url, String downloadLocation) throws IOException {
log.debug("Downloading art from {} to {}", url, downloadLocation);

try {
URL imageUrl = new URL(url);
InputStream is = imageUrl.openStream();
OutputStream os = new FileOutputStream(downloadLocation);

byte[] b = new byte[2048];
int length;

while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
}

is.close();
os.close();

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
/*
URL imageRequest = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(imageRequest.openStream());
FileOutputStream fos = new FileOutputStream(downloadLocation);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
*/


}

}