From d59618d0e729ddceec3245e02632edec1df70cf4 Mon Sep 17 00:00:00 2001 From: Coffeemakr Date: Sat, 25 Nov 2017 03:14:15 +0100 Subject: [PATCH] Ignore deleted playlist items and add uploader url --- .../youtube/YoutubePlaylistExtractor.java | 31 ++++++++++++++++++- .../extractor/stream/StreamInfoItem.java | 17 ++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java index bf2c1ee1f..02619fc6e 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractor.java @@ -203,7 +203,13 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { final UrlIdHandler streamUrlIdHandler = getService().getStreamUrlIdHandler(); for (final Element li : element.children()) { + if(isDeletedItem(li)) { + continue; + } + collector.commit(new YoutubeStreamInfoItemExtractor(li) { + public Element uploaderLink; + @Override public boolean isAd() throws ParsingException { return false; @@ -245,9 +251,23 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { } } + + private Element getUploaderLink() { + // should always be present since we filter deleted items + if(uploaderLink == null) { + uploaderLink = li.select("div[class=pl-video-owner] a").first(); + } + return uploaderLink; + } + @Override public String getUploaderName() throws ParsingException { - return li.select("div[class=pl-video-owner] a").text(); + return getUploaderLink().text(); + } + + @Override + public String getUploaderUrl() throws ParsingException { + return getUploaderLink().attr("href"); } @Override @@ -271,4 +291,13 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { }); } } + + /** + * Check if the playlist item is deleted + * @param li the list item + * @return true if the item is deleted + */ + private boolean isDeletedItem(Element li) { + return li.select("div[class=pl-video-owner] a").isEmpty(); + } } diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java index 03525c8bf..f97500167 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java @@ -83,4 +83,21 @@ public class StreamInfoItem extends InfoItem { public void setViewCount(long view_count) { this.view_count = view_count; } + + @Override + public String toString() { + return "StreamInfoItem{" + + "stream_type=" + stream_type + + ", uploader_name='" + uploader_name + '\'' + + ", upload_date='" + upload_date + '\'' + + ", view_count=" + view_count + + ", duration=" + duration + + ", uploaderUrl='" + uploaderUrl + '\'' + + ", info_type=" + info_type + + ", service_id=" + service_id + + ", url='" + url + '\'' + + ", name='" + name + '\'' + + ", thumbnail_url='" + thumbnail_url + '\'' + + '}'; + } } \ No newline at end of file