diff --git a/pom.xml b/pom.xml
index 49abaca..ac73655 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.github.axet
vget
jar
- 1.0.33
+ 1.0.34
vget
vget java video download library
https://github.com/axet/vget
diff --git a/src/main/java/com/github/axet/vget/VGet.java b/src/main/java/com/github/axet/vget/VGet.java
index 96e8a04..f2f0d64 100644
--- a/src/main/java/com/github/axet/vget/VGet.java
+++ b/src/main/java/com/github/axet/vget/VGet.java
@@ -205,6 +205,7 @@ void target(DownloadInfo dinfo) {
boolean retry(Throwable e) {
if (e == null)
return true;
+
if (e instanceof DownloadIOCodeError) {
DownloadIOCodeError c = (DownloadIOCodeError) e;
switch (c.getCode()) {
@@ -215,19 +216,62 @@ boolean retry(Throwable e) {
return false;
}
}
+
return false;
}
+ /**
+ * return status of download information. subclassing for VideoInfo.empty();
+ *
+ * @return
+ */
+ public boolean empty() {
+ return getVideo().empty();
+ }
+
+ /**
+ * extract video information, retry until success
+ *
+ * @param stop
+ * @param notify
+ */
+ public void extract(AtomicBoolean stop, Runnable notify) {
+ while (!done(stop)) {
+ try {
+ if (info.empty()) {
+ info.extract(stop, notify);
+ info.setState(States.EXTRACTING_DONE);
+ notify.run();
+ }
+ return;
+ } catch (DownloadRetry e) {
+ retry(stop, notify, e);
+ } catch (DownloadMultipartError e) {
+ for (Part ee : e.getInfo().getParts()) {
+ if (!retry(ee.getException())) {
+ throw e;
+ }
+ }
+ retry(stop, notify, e);
+ } catch (DownloadIOCodeError e) {
+ if (retry(e))
+ retry(stop, notify, e);
+ else
+ throw e;
+ } catch (DownloadIOError e) {
+ retry(stop, notify, e);
+ }
+ }
+ }
+
public void download(final AtomicBoolean stop, final Runnable notify) {
try {
+ if (empty()) {
+ extract(stop, notify);
+ }
+
while (!done(stop)) {
try {
- if (info.empty()) {
- info.extract(stop, notify);
- info.setState(States.EXTRACTING_DONE);
- notify.run();
- }
-
final DownloadInfo dinfo = info.getInfo();
if (dinfo.getContentType() == null || !dinfo.getContentType().contains("video/")) {
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 97c95e7..2407a39 100644
--- a/src/main/java/com/github/axet/vget/info/YouTubeParser.java
+++ b/src/main/java/com/github/axet/vget/info/YouTubeParser.java
@@ -25,6 +25,17 @@
public class YouTubeParser extends VGetParser {
+ public static class VideoUnavailablePlayer extends DownloadError {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 10905065542230199L;
+
+ public VideoUnavailablePlayer() {
+ super("unavailable-player");
+ }
+ }
+
public static class AgeException extends DownloadError {
private static final long serialVersionUID = 1L;
@@ -281,71 +292,76 @@ public static Map getQueryMap(String qs) {
}
void extractHtmlInfo(VideoInfo info, String html) throws Exception {
- Pattern age = Pattern.compile("(verify_age)");
- Matcher ageMatch = age.matcher(html);
- if (ageMatch.find())
- throw new AgeException();
-
- Pattern gen = Pattern.compile("\"(http(.*)generate_204(.*))\"");
- Matcher genMatch = gen.matcher(html);
- if (genMatch.find()) {
- String sline = genMatch.group(1);
-
- sline = StringEscapeUtils.unescapeJava(sline);
+ {
+ Pattern age = Pattern.compile("(verify_age)");
+ Matcher ageMatch = age.matcher(html);
+ if (ageMatch.find())
+ throw new AgeException();
}
- Pattern urlencod = Pattern.compile("\"url_encoded_fmt_stream_map\": \"([^\"]*)\"");
- Matcher urlencodMatch = urlencod.matcher(html);
- if (urlencodMatch.find()) {
- String url_encoded_fmt_stream_map;
- url_encoded_fmt_stream_map = urlencodMatch.group(1);
-
- // normal embedded video, unable to grab age restricted videos
- Pattern encod = Pattern.compile("url=(.*)");
- Matcher encodMatch = encod.matcher(url_encoded_fmt_stream_map);
- if (encodMatch.find()) {
- String sline = encodMatch.group(1);
+ {
+ Pattern age = Pattern.compile("(unavailable-player)");
+ Matcher ageMatch = age.matcher(html);
+ if (ageMatch.find())
+ throw new VideoUnavailablePlayer();
+ }
- extractUrlEncodedVideos(sline);
- }
+ {
+ Pattern urlencod = Pattern.compile("\"url_encoded_fmt_stream_map\": \"([^\"]*)\"");
+ Matcher urlencodMatch = urlencod.matcher(html);
+ if (urlencodMatch.find()) {
+ String url_encoded_fmt_stream_map;
+ url_encoded_fmt_stream_map = urlencodMatch.group(1);
+
+ // normal embedded video, unable to grab age restricted videos
+ Pattern encod = Pattern.compile("url=(.*)");
+ Matcher encodMatch = encod.matcher(url_encoded_fmt_stream_map);
+ if (encodMatch.find()) {
+ String sline = encodMatch.group(1);
+
+ extractUrlEncodedVideos(sline);
+ }
- // stream video
- Pattern encodStream = Pattern.compile("stream=(.*)");
- Matcher encodStreamMatch = encodStream.matcher(url_encoded_fmt_stream_map);
- if (encodStreamMatch.find()) {
- String sline = encodStreamMatch.group(1);
+ // stream video
+ Pattern encodStream = Pattern.compile("stream=(.*)");
+ Matcher encodStreamMatch = encodStream.matcher(url_encoded_fmt_stream_map);
+ if (encodStreamMatch.find()) {
+ String sline = encodStreamMatch.group(1);
- String[] urlStrings = sline.split("stream=");
+ String[] urlStrings = sline.split("stream=");
- for (String urlString : urlStrings) {
- urlString = StringEscapeUtils.unescapeJava(urlString);
+ for (String urlString : urlStrings) {
+ urlString = StringEscapeUtils.unescapeJava(urlString);
- Pattern link = Pattern.compile("(sparams.*)&itag=(\\d+)&.*&conn=rtmpe(.*),");
- Matcher linkMatch = link.matcher(urlString);
- if (linkMatch.find()) {
+ Pattern link = Pattern.compile("(sparams.*)&itag=(\\d+)&.*&conn=rtmpe(.*),");
+ Matcher linkMatch = link.matcher(urlString);
+ if (linkMatch.find()) {
- String sparams = linkMatch.group(1);
- String itag = linkMatch.group(2);
- String url = linkMatch.group(3);
+ String sparams = linkMatch.group(1);
+ String itag = linkMatch.group(2);
+ String url = linkMatch.group(3);
- url = "http" + url + "?" + sparams;
+ url = "http" + url + "?" + sparams;
- url = URLDecoder.decode(url, "UTF-8");
+ url = URLDecoder.decode(url, "UTF-8");
- addVideo(Integer.decode(itag), url);
+ addVideo(Integer.decode(itag), url);
+ }
}
}
}
}
- Pattern title = Pattern.compile("");
- name = StringEscapeUtils.unescapeHtml4(name);
- info.setTitle(name);
+ {
+ Pattern title = Pattern.compile("");
+ name = StringEscapeUtils.unescapeHtml4(name);
+ info.setTitle(name);
+ }
}
}