diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 2b76340..5b781ec 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,3 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 diff --git a/pom.xml b/pom.xml index 601ca70..4ff24fc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.axet vget jar - 1.0.36 + 1.0.37 vget vget java video download library https://github.com/axet/vget diff --git a/src/main/java/com/github/axet/vget/info/YouTubeParser.java b/src/main/java/com/github/axet/vget/info/YouTubeParser.java index 2407a39..bd7a1b3 100644 --- a/src/main/java/com/github/axet/vget/info/YouTubeParser.java +++ b/src/main/java/com/github/axet/vget/info/YouTubeParser.java @@ -1,6 +1,5 @@ package com.github.axet.vget.info; -import java.io.FileNotFoundException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -371,6 +370,48 @@ void extractUrlEncodedVideos(String sline) throws Exception { for (String urlString : urlStrings) { urlString = StringEscapeUtils.unescapeJava(urlString); + // simple request (catchup old movies) + { + String url = null; + { + Pattern link = Pattern.compile("([^&]*)&"); + Matcher linkMatch = link.matcher(urlString); + if (linkMatch.find()) { + url = linkMatch.group(1); + url = URLDecoder.decode(url, "UTF-8"); + } + } + String itag = null; + { + Pattern link = Pattern.compile("itag=(\\d+)"); + Matcher linkMatch = link.matcher(urlString); + if (linkMatch.find()) { + itag = linkMatch.group(1); + } + } + String sig = null; + { + Pattern link = Pattern.compile("sig=([^&]*)&"); + Matcher linkMatch = link.matcher(urlString); + if (linkMatch.find()) { + sig = linkMatch.group(1); + } + } + + if (url != null) { + try { + new URL(url); + + if (sig != null) + url += "&signature=" + sig; + if (itag != null) + addVideo(Integer.decode(itag), url); + } catch (MalformedURLException e) { + // ignore bad urls + } + } + } + { Pattern link = Pattern.compile("(.*)&quality=(.*)&fallback_host=(.*)&type=(.*)itag=(\\d+)"); Matcher linkMatch = link.matcher(urlString); @@ -391,14 +432,10 @@ void extractUrlEncodedVideos(String sline) throws Exception { if (linkMatch.find()) { String url = linkMatch.group(1); - String type = linkMatch.group(2); - String fallback_host = linkMatch.group(3); String sig = linkMatch.group(4); - String quality = linkMatch.group(5); String itag = linkMatch.group(6); url = URLDecoder.decode(url, "UTF-8"); - type = URLDecoder.decode(type, "UTF-8"); url += "&signature=" + sig; diff --git a/src/test/java/com/github/axet/vget/AppManagedDownload.java b/src/test/java/com/github/axet/vget/AppManagedDownload.java new file mode 100644 index 0000000..f887794 --- /dev/null +++ b/src/test/java/com/github/axet/vget/AppManagedDownload.java @@ -0,0 +1,82 @@ +package com.github.axet.vget; + +import java.io.File; +import java.net.URL; +import java.util.concurrent.atomic.AtomicBoolean; + +import com.github.axet.vget.info.VideoInfo; +import com.github.axet.wget.info.DownloadInfo; +import com.github.axet.wget.info.DownloadInfo.Part; +import com.github.axet.wget.info.DownloadInfo.Part.States; + +public class AppManagedDownload { + + VideoInfo info; + long last; + + public void run() { + try { + AtomicBoolean stop = new AtomicBoolean(false); + Runnable notify = new Runnable() { + @Override + public void run() { + VideoInfo i1 = info; + DownloadInfo i2 = i1.getInfo(); + + // notify app or save download state + // you can extract information from DownloadInfo info; + switch (i1.getState()) { + case EXTRACTING: + case EXTRACTING_DONE: + case DONE: + System.out.println(i1.getState()); + break; + case RETRYING: + System.out.println(i1.getState() + " " + i1.getDelay()); + break; + case DOWNLOADING: + long now = System.currentTimeMillis(); + if (now - 1000 > last) { + last = now; + + String parts = ""; + + for (Part p : i2.getParts()) { + if (p.getState().equals(States.DOWNLOADING)) { + parts += String.format("Part#%d(%.2f) ", p.getNumber(), + p.getCount() / (float) p.getLength()); + } + } + + System.out.println(String.format("%s %.2f %s", i1.getState(), + i2.getCount() / (float) i2.getLength(), parts)); + } + break; + default: + break; + } + } + }; + + info = new VideoInfo(new URL("http://vimeo.com/52716355")); + + VGet v = new VGet(info, new File("/Users/axet/Downloads")); + + // optional. only if you dlike to get video title before start + // download + v.extract(stop, notify); + System.out.println(info.getTitle()); + + v.download(stop, notify); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + AppManagedDownload e = new AppManagedDownload(); + e.run(); + } +} \ No newline at end of file diff --git a/src/test/java/com/github/axet/vget/DirectDownload.java b/src/test/java/com/github/axet/vget/DirectDownload.java new file mode 100644 index 0000000..58d1e1a --- /dev/null +++ b/src/test/java/com/github/axet/vget/DirectDownload.java @@ -0,0 +1,17 @@ +package com.github.axet.vget; + +import java.io.File; +import java.net.URL; + +public class DirectDownload { + + public static void main(String[] args) { + try { + VGet v = new VGet(new URL("http://www.youtube.com/watch?v=ZIPxGEaB5OM&feature=youtube_gdata"), new File("/Users/axet/Downloads")); + v.download(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} \ No newline at end of file