From 7e09772ec4058471ee90618a19138771bc70f6e1 Mon Sep 17 00:00:00 2001 From: Joel Christophel Date: Sun, 29 Jan 2017 02:52:25 -0500 Subject: [PATCH] Download youtube-dl from GitHub The dedicated website for youtube-dl wasn't reliably serving the .exe file. --- src/com/joelchristophel/sourceradio/Playlist.java | 9 ++++----- src/com/joelchristophel/sourceradio/Song.java | 4 +++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/com/joelchristophel/sourceradio/Playlist.java b/src/com/joelchristophel/sourceradio/Playlist.java index b9b7603..5b78cec 100644 --- a/src/com/joelchristophel/sourceradio/Playlist.java +++ b/src/com/joelchristophel/sourceradio/Playlist.java @@ -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; @@ -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); } @@ -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())); @@ -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)); diff --git a/src/com/joelchristophel/sourceradio/Song.java b/src/com/joelchristophel/sourceradio/Song.java index b9add12..5001d44 100644 --- a/src/com/joelchristophel/sourceradio/Song.java +++ b/src/com/joelchristophel/sourceradio/Song.java @@ -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);