From d56b880cae7393ed71f31deec770182352f8e412 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Fri, 22 Jul 2022 15:22:14 +0200 Subject: [PATCH] Replace avatar and thumbnail URLs attributes and methods to List in Infos --- .../extractor/channel/ChannelInfo.java | 83 ++++++------ .../extractor/playlist/PlaylistInfo.java | 67 +++++----- .../newpipe/extractor/stream/StreamInfo.java | 123 ++++++++---------- 3 files changed, 138 insertions(+), 135 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java index 4c05de692..502901e29 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java @@ -1,6 +1,27 @@ +/* + * Created by Christian Schabesberger on 31.07.16. + * + * Copyright (C) Christian Schabesberger 2016 + * ChannelInfo.java is part of NewPipe Extractor. + * + * NewPipe Extractor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe Extractor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe Extractor. If not, see . + */ + package org.schabi.newpipe.extractor.channel; import org.schabi.newpipe.extractor.Info; +import org.schabi.newpipe.extractor.Image; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; @@ -11,26 +32,6 @@ import java.util.List; import javax.annotation.Nonnull; -/* - * Created by Christian Schabesberger on 31.07.16. - * - * Copyright (C) Christian Schabesberger 2016 - * ChannelInfo.java is part of NewPipe. - * - * NewPipe is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * NewPipe is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NewPipe. If not, see . - */ - public class ChannelInfo extends Info { public ChannelInfo(final int serviceId, @@ -64,13 +65,13 @@ public class ChannelInfo extends Info { final ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name); try { - info.setAvatarUrl(extractor.getAvatarUrl()); + info.setAvatars(extractor.getAvatars()); } catch (final Exception e) { info.addError(e); } try { - info.setBannerUrl(extractor.getBannerUrl()); + info.setBanners(extractor.getBanners()); } catch (final Exception e) { info.addError(e); } @@ -106,7 +107,7 @@ public class ChannelInfo extends Info { } try { - info.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl()); + info.setParentChannelAvatars(extractor.getParentChannelAvatars()); } catch (final Exception e) { info.addError(e); } @@ -132,15 +133,18 @@ public class ChannelInfo extends Info { return info; } - private String avatarUrl; private String parentChannelName; private String parentChannelUrl; - private String parentChannelAvatarUrl; - private String bannerUrl; private String feedUrl; private long subscriberCount = -1; private String description; private String[] donationLinks; + @Nonnull + private List avatars = List.of(); + @Nonnull + private List banners = List.of(); + @Nonnull + private List parentChannelAvatars = List.of(); private boolean verified; private List tabs = List.of(); private List tags = List.of(); @@ -161,28 +165,31 @@ public class ChannelInfo extends Info { this.parentChannelUrl = parentChannelUrl; } - public String getParentChannelAvatarUrl() { - return parentChannelAvatarUrl; + @Nonnull + public List getParentChannelAvatars() { + return parentChannelAvatars; } - public void setParentChannelAvatarUrl(final String parentChannelAvatarUrl) { - this.parentChannelAvatarUrl = parentChannelAvatarUrl; + public void setParentChannelAvatars(@Nonnull final List parentChannelAvatars) { + this.parentChannelAvatars = parentChannelAvatars; } - public String getAvatarUrl() { - return avatarUrl; + @Nonnull + public List getAvatars() { + return avatars; } - public void setAvatarUrl(final String avatarUrl) { - this.avatarUrl = avatarUrl; + public void setAvatars(@Nonnull final List avatars) { + this.avatars = avatars; } - public String getBannerUrl() { - return bannerUrl; + @Nonnull + public List getBanners() { + return banners; } - public void setBannerUrl(final String bannerUrl) { - this.bannerUrl = bannerUrl; + public void setBanners(@Nonnull final List banners) { + this.banners = banners; } public String getFeedUrl() { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index 97a0d530d..bb29ca7d0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor.playlist; +import org.schabi.newpipe.extractor.Image; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.NewPipe; @@ -12,6 +13,7 @@ import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.utils.ExtractorHelper; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -109,26 +111,23 @@ public final class PlaylistInfo extends ListInfo { info.addError(e); } try { - info.setThumbnailUrl(extractor.getThumbnailUrl()); + info.setThumbnails(extractor.getThumbnails()); } catch (final Exception e) { info.addError(e); } try { info.setUploaderUrl(extractor.getUploaderUrl()); } catch (final Exception e) { - info.setUploaderUrl(""); uploaderParsingErrors.add(e); } try { info.setUploaderName(extractor.getUploaderName()); } catch (final Exception e) { - info.setUploaderName(""); uploaderParsingErrors.add(e); } try { - info.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl()); + info.setUploaderAvatars(extractor.getUploaderAvatars()); } catch (final Exception e) { - info.setUploaderAvatarUrl(""); uploaderParsingErrors.add(e); } try { @@ -142,12 +141,12 @@ public final class PlaylistInfo extends ListInfo { uploaderParsingErrors.add(e); } try { - info.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl()); + info.setSubChannelAvatars(extractor.getSubChannelAvatars()); } catch (final Exception e) { uploaderParsingErrors.add(e); } try { - info.setBannerUrl(extractor.getBannerUrl()); + info.setBanners(extractor.getBanners()); } catch (final Exception e) { info.addError(e); } @@ -171,32 +170,38 @@ public final class PlaylistInfo extends ListInfo { return info; } - private String thumbnailUrl; - private String bannerUrl; - private String uploaderUrl; - private String uploaderName; - private String uploaderAvatarUrl; + private String uploaderUrl = ""; + private String uploaderName = ""; private String subChannelUrl; private String subChannelName; - private String subChannelAvatarUrl; - private long streamCount = 0; private Description description; + @Nonnull + private List banners = List.of(); + @Nonnull + private List subChannelAvatars = List.of(); + @Nonnull + private List thumbnails = List.of(); + @Nonnull + private List uploaderAvatars = List.of(); + private long streamCount; private PlaylistType playlistType; - public String getThumbnailUrl() { - return thumbnailUrl; + @Nonnull + public List getThumbnails() { + return thumbnails; } - public void setThumbnailUrl(final String thumbnailUrl) { - this.thumbnailUrl = thumbnailUrl; + public void setThumbnails(@Nonnull final List thumbnails) { + this.thumbnails = thumbnails; } - public String getBannerUrl() { - return bannerUrl; + @Nonnull + public List getBanners() { + return banners; } - public void setBannerUrl(final String bannerUrl) { - this.bannerUrl = bannerUrl; + public void setBanners(@Nonnull final List banners) { + this.banners = banners; } public String getUploaderUrl() { @@ -215,12 +220,13 @@ public final class PlaylistInfo extends ListInfo { this.uploaderName = uploaderName; } - public String getUploaderAvatarUrl() { - return uploaderAvatarUrl; + @Nonnull + public List getUploaderAvatars() { + return uploaderAvatars; } - public void setUploaderAvatarUrl(final String uploaderAvatarUrl) { - this.uploaderAvatarUrl = uploaderAvatarUrl; + public void setUploaderAvatars(@Nonnull final List uploaderAvatars) { + this.uploaderAvatars = uploaderAvatars; } public String getSubChannelUrl() { @@ -239,12 +245,13 @@ public final class PlaylistInfo extends ListInfo { this.subChannelName = subChannelName; } - public String getSubChannelAvatarUrl() { - return subChannelAvatarUrl; + @Nonnull + public List getSubChannelAvatars() { + return subChannelAvatars; } - public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) { - this.subChannelAvatarUrl = subChannelAvatarUrl; + public void setSubChannelAvatars(@Nonnull final List subChannelAvatars) { + this.subChannelAvatars = subChannelAvatars; } public long getStreamCount() { 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 fa979c34b..252bc7f14 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,26 +1,3 @@ -package org.schabi.newpipe.extractor.stream; - -import org.schabi.newpipe.extractor.Info; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.MetaInfo; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.StreamingService; -import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; -import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.localization.DateWrapper; -import org.schabi.newpipe.extractor.utils.ExtractorHelper; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -import javax.annotation.Nonnull; - -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; - /* * Created by Christian Schabesberger on 26.08.15. * @@ -38,9 +15,31 @@ import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with NewPipe Extractor. If not, see . + * along with NewPipe Extractor. If not, see . */ +package org.schabi.newpipe.extractor.stream; + +import org.schabi.newpipe.extractor.Image; +import org.schabi.newpipe.extractor.Info; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.MetaInfo; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; +import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.localization.DateWrapper; +import org.schabi.newpipe.extractor.utils.ExtractorHelper; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import javax.annotation.Nonnull; + +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; + /** * Info object for opened contents, i.e. the content ready to play. */ @@ -106,9 +105,7 @@ public class StreamInfo extends Info { // Important data, without it the content can't be displayed. // If one of these is not available, the frontend will receive an exception directly. - final int serviceId = extractor.getServiceId(); final String url = extractor.getUrl(); - final String originalUrl = extractor.getOriginalUrl(); final StreamType streamType = extractor.getStreamType(); final String id = extractor.getId(); final String name = extractor.getName(); @@ -148,7 +145,6 @@ public class StreamInfo extends Info { streamInfo.addError(new ExtractionException("Couldn't get HLS manifest", e)); } - /* Load and extract audio */ try { streamInfo.setAudioStreams(extractor.getAudioStreams()); } catch (final ContentNotSupportedException e) { @@ -157,31 +153,18 @@ public class StreamInfo extends Info { streamInfo.addError(new ExtractionException("Couldn't get audio streams", e)); } - /* Extract video stream url */ try { streamInfo.setVideoStreams(extractor.getVideoStreams()); } catch (final Exception e) { streamInfo.addError(new ExtractionException("Couldn't get video streams", e)); } - /* Extract video only stream url */ try { streamInfo.setVideoOnlyStreams(extractor.getVideoOnlyStreams()); } catch (final Exception e) { streamInfo.addError(new ExtractionException("Couldn't get video only streams", e)); } - // Lists can be null if an exception was thrown during extraction - if (streamInfo.getVideoStreams() == null) { - streamInfo.setVideoStreams(Collections.emptyList()); - } - if (streamInfo.getVideoOnlyStreams() == null) { - streamInfo.setVideoOnlyStreams(Collections.emptyList()); - } - if (streamInfo.getAudioStreams() == null) { - streamInfo.setAudioStreams(Collections.emptyList()); - } - // Either audio or video has to be available, otherwise we didn't get a stream (since // videoOnly are optional, they don't count). if ((streamInfo.videoStreams.isEmpty()) && (streamInfo.audioStreams.isEmpty())) { @@ -199,7 +182,7 @@ public class StreamInfo extends Info { // so the frontend can afterwards check where errors happened. try { - streamInfo.setThumbnailUrl(extractor.getThumbnailUrl()); + streamInfo.setThumbnails(extractor.getThumbnails()); } catch (final Exception e) { streamInfo.addError(e); } @@ -219,7 +202,7 @@ public class StreamInfo extends Info { streamInfo.addError(e); } try { - streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl()); + streamInfo.setUploaderAvatars(extractor.getUploaderAvatars()); } catch (final Exception e) { streamInfo.addError(e); } @@ -245,7 +228,7 @@ public class StreamInfo extends Info { streamInfo.addError(e); } try { - streamInfo.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl()); + streamInfo.setSubChannelAvatars(extractor.getSubChannelAvatars()); } catch (final Exception e) { streamInfo.addError(e); } @@ -353,7 +336,8 @@ public class StreamInfo extends Info { } private StreamType streamType; - private String thumbnailUrl = ""; + @Nonnull + private List thumbnails = List.of(); private String textualUploadDate; private DateWrapper uploadDate; private long duration = -1; @@ -366,24 +350,26 @@ public class StreamInfo extends Info { private String uploaderName = ""; private String uploaderUrl = ""; - private String uploaderAvatarUrl = ""; + @Nonnull + private List uploaderAvatars = List.of(); private boolean uploaderVerified = false; private long uploaderSubscriberCount = -1; private String subChannelName = ""; private String subChannelUrl = ""; - private String subChannelAvatarUrl = ""; + @Nonnull + private List subChannelAvatars = List.of(); - private List videoStreams = new ArrayList<>(); - private List audioStreams = new ArrayList<>(); - private List videoOnlyStreams = new ArrayList<>(); + private List videoStreams = List.of(); + private List audioStreams = List.of(); + private List videoOnlyStreams = List.of(); private String dashMpdUrl = ""; private String hlsUrl = ""; - private List relatedItems = new ArrayList<>(); + private List relatedItems = List.of(); private long startPosition = 0; - private List subtitles = new ArrayList<>(); + private List subtitles = List.of(); private String host = ""; private StreamExtractor.Privacy privacy; @@ -391,15 +377,15 @@ public class StreamInfo extends Info { private String licence = ""; private String supportInfo = ""; private Locale language = null; - private List tags = new ArrayList<>(); - private List streamSegments = new ArrayList<>(); - private List metaInfo = new ArrayList<>(); + private List tags = List.of(); + private List streamSegments = List.of(); + private List metaInfo = List.of(); private boolean shortFormContent = false; /** * Preview frames, e.g. for the storyboard / seekbar thumbnail preview */ - private List previewFrames = Collections.emptyList(); + private List previewFrames = List.of(); /** * Get the stream type @@ -419,12 +405,13 @@ public class StreamInfo extends Info { * * @return the thumbnail url as a string */ - public String getThumbnailUrl() { - return thumbnailUrl; + @Nonnull + public List getThumbnails() { + return thumbnails; } - public void setThumbnailUrl(final String thumbnailUrl) { - this.thumbnailUrl = thumbnailUrl; + public void setThumbnails(@Nonnull final List thumbnails) { + this.thumbnails = thumbnails; } public String getTextualUploadDate() { @@ -522,12 +509,13 @@ public class StreamInfo extends Info { this.uploaderUrl = uploaderUrl; } - public String getUploaderAvatarUrl() { - return uploaderAvatarUrl; + @Nonnull + public List getUploaderAvatars() { + return uploaderAvatars; } - public void setUploaderAvatarUrl(final String uploaderAvatarUrl) { - this.uploaderAvatarUrl = uploaderAvatarUrl; + public void setUploaderAvatars(@Nonnull final List uploaderAvatars) { + this.uploaderAvatars = uploaderAvatars; } public boolean isUploaderVerified() { @@ -562,12 +550,13 @@ public class StreamInfo extends Info { this.subChannelUrl = subChannelUrl; } - public String getSubChannelAvatarUrl() { - return subChannelAvatarUrl; + @Nonnull + public List getSubChannelAvatars() { + return subChannelAvatars; } - public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) { - this.subChannelAvatarUrl = subChannelAvatarUrl; + public void setSubChannelAvatars(@Nonnull final List subChannelAvatars) { + this.subChannelAvatars = subChannelAvatars; } public List getVideoStreams() {