From 9d5951765ffc8d4d5099cfa6f2523a626214884b Mon Sep 17 00:00:00 2001 From: David Date: Wed, 8 Jun 2016 12:35:54 -0300 Subject: [PATCH] Fix for #310 --- .../schabi/newpipe/extractor/StreamInfo.java | 20 +++++++++++-------- .../extractor/StreamPreviewInfoCollector.java | 2 +- .../youtube/YoutubeStreamUrlIdHandler.java | 13 ++++++++++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java index cd7a51741..cd79e463f 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java @@ -230,15 +230,19 @@ public class StreamInfo extends AbstractVideoInfo { } try { // get next video - System.out.println(extractor.getUrlIdHandler()); - StreamPreviewInfoCollector c = new StreamPreviewInfoCollector( - extractor.getUrlIdHandler(), extractor.getServiceId()); - c.commit(extractor.getNextVideo()); - if(c.getItemList().size() != 0) { - streamInfo.next_video = c.getItemList().get(0); + if(streamInfo.next_video != null) + { + StreamPreviewInfoCollector c = new StreamPreviewInfoCollector( + extractor.getUrlIdHandler(), extractor.getServiceId()); + StreamPreviewInfoExtractor nextVideo = extractor.getNextVideo(); + c.commit(nextVideo); + if(c.getItemList().size() != 0) { + streamInfo.next_video = c.getItemList().get(0); + } + streamInfo.errors.addAll(c.getErrors()); } - streamInfo.errors.addAll(c.getErrors()); - } catch(Exception e) { + } + catch(Exception e) { streamInfo.addException(e); } try { diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java index 7e100960c..df7291f71 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamPreviewInfoCollector.java @@ -56,7 +56,7 @@ public class StreamPreviewInfoCollector { resultItem.webpage_url = extractor.getWebPageUrl(); if (urlIdHandler == null) { throw new ParsingException("Error: UrlIdHandler not set"); - } else { + } else if(!resultItem.webpage_url.isEmpty()) { resultItem.id = (new YoutubeStreamUrlIdHandler()).getVideoId(resultItem.webpage_url); } resultItem.title = extractor.getTitle(); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java index 998e93a51..cc95aa401 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java @@ -36,7 +36,11 @@ public class YoutubeStreamUrlIdHandler implements StreamUrlIdHandler { @SuppressWarnings("WeakerAccess") @Override - public String getVideoId(String url) throws ParsingException { + public String getVideoId(String url) throws ParsingException, IllegalArgumentException { + if(url.isEmpty()) + { + throw new IllegalArgumentException("The url parameter should not be empty"); + } String id; if(url.contains("youtube")) { @@ -48,7 +52,12 @@ public class YoutubeStreamUrlIdHandler implements StreamUrlIdHandler { } catch(UnsupportedEncodingException uee) { throw new ParsingException("Could not parse attribution_link", uee); } - } else { + } + else if(url.contains("vnd.youtube")) + { + id = Parser.matchGroup1("vnd.youtube\\:([\\-a-zA-Z0-9_]{11}).*", url); + } + else { id = Parser.matchGroup1("[?&]v=([\\-a-zA-Z0-9_]{11})", url); } }