From 9fb0622a2422485da75549755aa8022aa5b91367 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Mon, 3 Sep 2018 00:11:40 +0530 Subject: [PATCH] better quality thumbnails --- .../comments/CommentsInfoItemsCollector.java | 136 +++++++++--------- .../extractors/YoutubeCommentsExtractor.java | 20 +-- .../newpipe/extractor/stream/StreamInfo.java | 15 +- 3 files changed, 90 insertions(+), 81 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java index 6bc925302..bf3bc3225 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java @@ -9,75 +9,81 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; public class CommentsInfoItemsCollector extends InfoItemsCollector { - public CommentsInfoItemsCollector(int serviceId) { - super(serviceId); - } + public CommentsInfoItemsCollector(int serviceId) { + super(serviceId); + } - @Override - public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws ParsingException { + @Override + public CommentsInfoItem extract(CommentsInfoItemExtractor extractor) throws ParsingException { - // important information - int serviceId = getServiceId(); - String url = extractor.getUrl(); - String name = extractor.getName(); + // important information + int serviceId = getServiceId(); + String url = extractor.getUrl(); + String name = extractor.getName(); - CommentsInfoItem resultItem = new CommentsInfoItem(serviceId, url, name); + CommentsInfoItem resultItem = new CommentsInfoItem(serviceId, url, name); - // optional information - try { - resultItem.setCommentId(extractor.getCommentId()); - } catch (Exception e) { - addError(e); - } - try { - resultItem.setCommentText(extractor.getCommentText()); - } catch (Exception e) { - addError(e); - } - try { - resultItem.setAuthorName(extractor.getAuthorName()); - } catch (Exception e) { - addError(e); - } - try { - resultItem.setAuthorThumbnail(extractor.getAuthorThumbnail()); - } catch (Exception e) { - addError(e); - } - try { - resultItem.setAuthorEndpoint(extractor.getAuthorEndpoint()); - } catch (Exception e) { - addError(e); - } - try { - resultItem.setPublishedTime(extractor.getPublishedTime()); - } catch (Exception e) { - addError(e); - } - try { - resultItem.setLikeCount(extractor.getLikeCount()); - } catch (Exception e) { - addError(e); - } - return resultItem; - } + // optional information + try { + resultItem.setCommentId(extractor.getCommentId()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setCommentText(extractor.getCommentText()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setAuthorName(extractor.getAuthorName()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setAuthorThumbnail(extractor.getAuthorThumbnail()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setAuthorEndpoint(extractor.getAuthorEndpoint()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setPublishedTime(extractor.getPublishedTime()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setLikeCount(extractor.getLikeCount()); + } catch (Exception e) { + addError(e); + } + try { + resultItem.setThumbnailUrl(extractor.getThumbnailUrl()); + } catch (Exception e) { + addError(e); + } - @Override - public void commit(CommentsInfoItemExtractor extractor) { - try { - addItem(extract(extractor)); - } catch (Exception e) { - addError(e); - } - } + return resultItem; + } - public List getCommentsInfoItemList() { - List siiList = new Vector<>(); - for (InfoItem ii : super.getItems()) { - if (ii instanceof CommentsInfoItem) { - siiList.add((CommentsInfoItem) ii); - } - } - return siiList; - } + @Override + public void commit(CommentsInfoItemExtractor extractor) { + try { + addItem(extract(extractor)); + } catch (Exception e) { + addError(e); + } + } + + public List getCommentsInfoItemList() { + List siiList = new Vector<>(); + for (InfoItem ii : super.getItems()) { + if (ii instanceof CommentsInfoItem) { + siiList.add((CommentsInfoItem) ii); + } + } + return siiList; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java index b203ed4b6..10e1beea7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java @@ -103,7 +103,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { @Override public String getThumbnailUrl() throws ParsingException { try { - return c.get("authorThumbnail").get("thumbnails").get(0).get("url").asText(); + return c.get("authorThumbnail").get("thumbnails").get(2).get("url").asText(); } catch (Exception e) { throw new ParsingException("Could not get thumbnail url", e); } @@ -114,7 +114,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { try { return c.get("authorText").get("simpleText").asText(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get author name", e); } } @@ -123,7 +123,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { try { return c.get("publishedTimeText").get("runs").get(0).get("text").asText(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get publishedTimeText", e); } } @@ -132,7 +132,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { try { return c.get("likeCount").intValue(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get like count", e); } } @@ -145,7 +145,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { return c.get("contentText").get("runs").get(0).get("text").asText(); } } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get comment text", e); } } @@ -154,16 +154,16 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { try { return c.get("commentId").asText(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get comment id", e); } } @Override public String getAuthorThumbnail() throws ParsingException { try { - return c.get("authorThumbnail").get("thumbnails").get(0).get("url").asText(); + return c.get("authorThumbnail").get("thumbnails").get(2).get("url").asText(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get author thumbnail", e); } } @@ -172,7 +172,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { try { return c.get("authorText").get("simpleText").asText(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get author name", e); } } @@ -182,7 +182,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { return "https://youtube.com" + c.get("authorEndpoint").get("browseEndpoint").get("canonicalBaseUrl").asText(); } catch (Exception e) { - throw new ParsingException("Could not get thumbnail url", e); + throw new ParsingException("Could not get author endpoint", e); } } }; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 74cb190fa..aa507fcaa 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -1,19 +1,22 @@ package org.schabi.newpipe.extractor.stream; -import org.schabi.newpipe.extractor.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.schabi.newpipe.extractor.Info; +import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.Subtitles; import org.schabi.newpipe.extractor.comments.CommentsExtractor; -import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.utils.DashMpdParser; import org.schabi.newpipe.extractor.utils.ExtractorHelper; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - /* * Created by Christian Schabesberger on 26.08.15. *