Skip to content

Commit

Permalink
Download youtube-dl from GitHub
Browse files Browse the repository at this point in the history
The dedicated website for youtube-dl wasn't reliably serving the .exe
file.
  • Loading branch information
joelamos committed Jan 29, 2017
1 parent 403508b commit 7e09772
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/com/joelchristophel/sourceradio/Playlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -111,7 +110,7 @@ public static void main(String[] args) {
System.out.println("Game: " + game.getFriendlyName());
System.out.println("Checking for SourceRadio updates...");
try {
String latestVersion = getLatestVersion();
String latestVersion = getLatestVersion("joelamos", "SourceRadio");
if (version.compareTo(latestVersion) < 0) {
System.out.println("Update found: " + "SourceRadio v" + latestVersion);
}
Expand Down Expand Up @@ -1052,9 +1051,9 @@ private static String normalizeQuery(String query) {
return query.toLowerCase(Locale.ENGLISH).trim();
}

private static String getLatestVersion() throws Exception {
static String getLatestVersion(String githubUser, String repository) throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL("https://github.com/joelamos/SourceRadio/releases/latest");
URL url = new URL("https://github.com/" + githubUser + "/" + repository + "/releases/latest");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Expand All @@ -1063,7 +1062,7 @@ private static String getLatestVersion() throws Exception {
result.append(line);
}
reader.close();
String needle = "SourceRadio/tree/";
String needle = repository + "/tree/";
String html = result.toString();
int needlePosition = html.indexOf(needle);
String version = html.substring(needlePosition + needle.length(), html.indexOf('"', needlePosition));
Expand Down
4 changes: 3 additions & 1 deletion src/com/joelchristophel/sourceradio/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ public Song copy(Player requester) {

static void downloadYoutubedl(String downloadDirectory) {
try {
URL website = new URL("https://yt-dl.org/downloads/latest/youtube-dl");
String version = Playlist.getLatestVersion("rg3", "youtube-dl");
System.out.println(version);
URL website = new URL("https://github.com/rg3/youtube-dl/releases/download/" + version + "/youtube-dl.exe");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream((downloadDirectory + "/youtube-dl.exe").replace("//", "/"));
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
Expand Down

0 comments on commit 7e09772

Please sign in to comment.