Skip to content

Commit

Permalink
Merge branch 'vget-1.0.37'
Browse files Browse the repository at this point in the history
  • Loading branch information
axet committed Dec 19, 2012
2 parents a20b884 + 33306d9 commit aab54ca
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 6 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.github.axet</groupId>
<artifactId>vget</artifactId>
<packaging>jar</packaging>
<version>1.0.36</version>
<version>1.0.37</version>
<name>vget</name>
<description>vget java video download library</description>
<url>https://github.com/axet/vget</url>
Expand Down
47 changes: 42 additions & 5 deletions src/main/java/com/github/axet/vget/info/YouTubeParser.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
82 changes: 82 additions & 0 deletions src/test/java/com/github/axet/vget/AppManagedDownload.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
17 changes: 17 additions & 0 deletions src/test/java/com/github/axet/vget/DirectDownload.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

}

0 comments on commit aab54ca

Please sign in to comment.