Replace avatar and thumbnail URLs attributes and methods to List<Image> in Infos

This commit is contained in:
AudricV 2022-07-22 15:22:14 +02:00
parent 9d8098576e
commit d56b880cae
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
3 changed files with 138 additions and 135 deletions

View File

@ -1,6 +1,27 @@
/*
* Created by Christian Schabesberger on 31.07.16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
* 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 <https://www.gnu.org/licenses/>.
*/
package org.schabi.newpipe.extractor.channel; package org.schabi.newpipe.extractor.channel;
import org.schabi.newpipe.extractor.Info; import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -11,26 +32,6 @@ import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
/*
* Created by Christian Schabesberger on 31.07.16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
* 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 <http://www.gnu.org/licenses/>.
*/
public class ChannelInfo extends Info { public class ChannelInfo extends Info {
public ChannelInfo(final int serviceId, public ChannelInfo(final int serviceId,
@ -64,13 +65,13 @@ public class ChannelInfo extends Info {
final ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name); final ChannelInfo info = new ChannelInfo(serviceId, id, url, originalUrl, name);
try { try {
info.setAvatarUrl(extractor.getAvatarUrl()); info.setAvatars(extractor.getAvatars());
} catch (final Exception e) { } catch (final Exception e) {
info.addError(e); info.addError(e);
} }
try { try {
info.setBannerUrl(extractor.getBannerUrl()); info.setBanners(extractor.getBanners());
} catch (final Exception e) { } catch (final Exception e) {
info.addError(e); info.addError(e);
} }
@ -106,7 +107,7 @@ public class ChannelInfo extends Info {
} }
try { try {
info.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl()); info.setParentChannelAvatars(extractor.getParentChannelAvatars());
} catch (final Exception e) { } catch (final Exception e) {
info.addError(e); info.addError(e);
} }
@ -132,15 +133,18 @@ public class ChannelInfo extends Info {
return info; return info;
} }
private String avatarUrl;
private String parentChannelName; private String parentChannelName;
private String parentChannelUrl; private String parentChannelUrl;
private String parentChannelAvatarUrl;
private String bannerUrl;
private String feedUrl; private String feedUrl;
private long subscriberCount = -1; private long subscriberCount = -1;
private String description; private String description;
private String[] donationLinks; private String[] donationLinks;
@Nonnull
private List<Image> avatars = List.of();
@Nonnull
private List<Image> banners = List.of();
@Nonnull
private List<Image> parentChannelAvatars = List.of();
private boolean verified; private boolean verified;
private List<ListLinkHandler> tabs = List.of(); private List<ListLinkHandler> tabs = List.of();
private List<String> tags = List.of(); private List<String> tags = List.of();
@ -161,28 +165,31 @@ public class ChannelInfo extends Info {
this.parentChannelUrl = parentChannelUrl; this.parentChannelUrl = parentChannelUrl;
} }
public String getParentChannelAvatarUrl() { @Nonnull
return parentChannelAvatarUrl; public List<Image> getParentChannelAvatars() {
return parentChannelAvatars;
} }
public void setParentChannelAvatarUrl(final String parentChannelAvatarUrl) { public void setParentChannelAvatars(@Nonnull final List<Image> parentChannelAvatars) {
this.parentChannelAvatarUrl = parentChannelAvatarUrl; this.parentChannelAvatars = parentChannelAvatars;
} }
public String getAvatarUrl() { @Nonnull
return avatarUrl; public List<Image> getAvatars() {
return avatars;
} }
public void setAvatarUrl(final String avatarUrl) { public void setAvatars(@Nonnull final List<Image> avatars) {
this.avatarUrl = avatarUrl; this.avatars = avatars;
} }
public String getBannerUrl() { @Nonnull
return bannerUrl; public List<Image> getBanners() {
return banners;
} }
public void setBannerUrl(final String bannerUrl) { public void setBanners(@Nonnull final List<Image> banners) {
this.bannerUrl = bannerUrl; this.banners = banners;
} }
public String getFeedUrl() { public String getFeedUrl() {

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor.playlist; package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe; 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.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.utils.ExtractorHelper; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -109,26 +111,23 @@ public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
info.addError(e); info.addError(e);
} }
try { try {
info.setThumbnailUrl(extractor.getThumbnailUrl()); info.setThumbnails(extractor.getThumbnails());
} catch (final Exception e) { } catch (final Exception e) {
info.addError(e); info.addError(e);
} }
try { try {
info.setUploaderUrl(extractor.getUploaderUrl()); info.setUploaderUrl(extractor.getUploaderUrl());
} catch (final Exception e) { } catch (final Exception e) {
info.setUploaderUrl("");
uploaderParsingErrors.add(e); uploaderParsingErrors.add(e);
} }
try { try {
info.setUploaderName(extractor.getUploaderName()); info.setUploaderName(extractor.getUploaderName());
} catch (final Exception e) { } catch (final Exception e) {
info.setUploaderName("");
uploaderParsingErrors.add(e); uploaderParsingErrors.add(e);
} }
try { try {
info.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl()); info.setUploaderAvatars(extractor.getUploaderAvatars());
} catch (final Exception e) { } catch (final Exception e) {
info.setUploaderAvatarUrl("");
uploaderParsingErrors.add(e); uploaderParsingErrors.add(e);
} }
try { try {
@ -142,12 +141,12 @@ public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
uploaderParsingErrors.add(e); uploaderParsingErrors.add(e);
} }
try { try {
info.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl()); info.setSubChannelAvatars(extractor.getSubChannelAvatars());
} catch (final Exception e) { } catch (final Exception e) {
uploaderParsingErrors.add(e); uploaderParsingErrors.add(e);
} }
try { try {
info.setBannerUrl(extractor.getBannerUrl()); info.setBanners(extractor.getBanners());
} catch (final Exception e) { } catch (final Exception e) {
info.addError(e); info.addError(e);
} }
@ -171,32 +170,38 @@ public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
return info; return info;
} }
private String thumbnailUrl; private String uploaderUrl = "";
private String bannerUrl; private String uploaderName = "";
private String uploaderUrl;
private String uploaderName;
private String uploaderAvatarUrl;
private String subChannelUrl; private String subChannelUrl;
private String subChannelName; private String subChannelName;
private String subChannelAvatarUrl;
private long streamCount = 0;
private Description description; private Description description;
@Nonnull
private List<Image> banners = List.of();
@Nonnull
private List<Image> subChannelAvatars = List.of();
@Nonnull
private List<Image> thumbnails = List.of();
@Nonnull
private List<Image> uploaderAvatars = List.of();
private long streamCount;
private PlaylistType playlistType; private PlaylistType playlistType;
public String getThumbnailUrl() { @Nonnull
return thumbnailUrl; public List<Image> getThumbnails() {
return thumbnails;
} }
public void setThumbnailUrl(final String thumbnailUrl) { public void setThumbnails(@Nonnull final List<Image> thumbnails) {
this.thumbnailUrl = thumbnailUrl; this.thumbnails = thumbnails;
} }
public String getBannerUrl() { @Nonnull
return bannerUrl; public List<Image> getBanners() {
return banners;
} }
public void setBannerUrl(final String bannerUrl) { public void setBanners(@Nonnull final List<Image> banners) {
this.bannerUrl = bannerUrl; this.banners = banners;
} }
public String getUploaderUrl() { public String getUploaderUrl() {
@ -215,12 +220,13 @@ public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
this.uploaderName = uploaderName; this.uploaderName = uploaderName;
} }
public String getUploaderAvatarUrl() { @Nonnull
return uploaderAvatarUrl; public List<Image> getUploaderAvatars() {
return uploaderAvatars;
} }
public void setUploaderAvatarUrl(final String uploaderAvatarUrl) { public void setUploaderAvatars(@Nonnull final List<Image> uploaderAvatars) {
this.uploaderAvatarUrl = uploaderAvatarUrl; this.uploaderAvatars = uploaderAvatars;
} }
public String getSubChannelUrl() { public String getSubChannelUrl() {
@ -239,12 +245,13 @@ public final class PlaylistInfo extends ListInfo<StreamInfoItem> {
this.subChannelName = subChannelName; this.subChannelName = subChannelName;
} }
public String getSubChannelAvatarUrl() { @Nonnull
return subChannelAvatarUrl; public List<Image> getSubChannelAvatars() {
return subChannelAvatars;
} }
public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) { public void setSubChannelAvatars(@Nonnull final List<Image> subChannelAvatars) {
this.subChannelAvatarUrl = subChannelAvatarUrl; this.subChannelAvatars = subChannelAvatars;
} }
public long getStreamCount() { public long getStreamCount() {

View File

@ -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. * Created by Christian Schabesberger on 26.08.15.
* *
@ -41,6 +18,28 @@ import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>. * along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
*/ */
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. * 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. // Important data, without it the content can't be displayed.
// If one of these is not available, the frontend will receive an exception directly. // 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 url = extractor.getUrl();
final String originalUrl = extractor.getOriginalUrl();
final StreamType streamType = extractor.getStreamType(); final StreamType streamType = extractor.getStreamType();
final String id = extractor.getId(); final String id = extractor.getId();
final String name = extractor.getName(); final String name = extractor.getName();
@ -148,7 +145,6 @@ public class StreamInfo extends Info {
streamInfo.addError(new ExtractionException("Couldn't get HLS manifest", e)); streamInfo.addError(new ExtractionException("Couldn't get HLS manifest", e));
} }
/* Load and extract audio */
try { try {
streamInfo.setAudioStreams(extractor.getAudioStreams()); streamInfo.setAudioStreams(extractor.getAudioStreams());
} catch (final ContentNotSupportedException e) { } catch (final ContentNotSupportedException e) {
@ -157,31 +153,18 @@ public class StreamInfo extends Info {
streamInfo.addError(new ExtractionException("Couldn't get audio streams", e)); streamInfo.addError(new ExtractionException("Couldn't get audio streams", e));
} }
/* Extract video stream url */
try { try {
streamInfo.setVideoStreams(extractor.getVideoStreams()); streamInfo.setVideoStreams(extractor.getVideoStreams());
} catch (final Exception e) { } catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get video streams", e)); streamInfo.addError(new ExtractionException("Couldn't get video streams", e));
} }
/* Extract video only stream url */
try { try {
streamInfo.setVideoOnlyStreams(extractor.getVideoOnlyStreams()); streamInfo.setVideoOnlyStreams(extractor.getVideoOnlyStreams());
} catch (final Exception e) { } catch (final Exception e) {
streamInfo.addError(new ExtractionException("Couldn't get video only streams", 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 // Either audio or video has to be available, otherwise we didn't get a stream (since
// videoOnly are optional, they don't count). // videoOnly are optional, they don't count).
if ((streamInfo.videoStreams.isEmpty()) && (streamInfo.audioStreams.isEmpty())) { 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. // so the frontend can afterwards check where errors happened.
try { try {
streamInfo.setThumbnailUrl(extractor.getThumbnailUrl()); streamInfo.setThumbnails(extractor.getThumbnails());
} catch (final Exception e) { } catch (final Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
@ -219,7 +202,7 @@ public class StreamInfo extends Info {
streamInfo.addError(e); streamInfo.addError(e);
} }
try { try {
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl()); streamInfo.setUploaderAvatars(extractor.getUploaderAvatars());
} catch (final Exception e) { } catch (final Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
@ -245,7 +228,7 @@ public class StreamInfo extends Info {
streamInfo.addError(e); streamInfo.addError(e);
} }
try { try {
streamInfo.setSubChannelAvatarUrl(extractor.getSubChannelAvatarUrl()); streamInfo.setSubChannelAvatars(extractor.getSubChannelAvatars());
} catch (final Exception e) { } catch (final Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
@ -353,7 +336,8 @@ public class StreamInfo extends Info {
} }
private StreamType streamType; private StreamType streamType;
private String thumbnailUrl = ""; @Nonnull
private List<Image> thumbnails = List.of();
private String textualUploadDate; private String textualUploadDate;
private DateWrapper uploadDate; private DateWrapper uploadDate;
private long duration = -1; private long duration = -1;
@ -366,24 +350,26 @@ public class StreamInfo extends Info {
private String uploaderName = ""; private String uploaderName = "";
private String uploaderUrl = ""; private String uploaderUrl = "";
private String uploaderAvatarUrl = ""; @Nonnull
private List<Image> uploaderAvatars = List.of();
private boolean uploaderVerified = false; private boolean uploaderVerified = false;
private long uploaderSubscriberCount = -1; private long uploaderSubscriberCount = -1;
private String subChannelName = ""; private String subChannelName = "";
private String subChannelUrl = ""; private String subChannelUrl = "";
private String subChannelAvatarUrl = ""; @Nonnull
private List<Image> subChannelAvatars = List.of();
private List<VideoStream> videoStreams = new ArrayList<>(); private List<VideoStream> videoStreams = List.of();
private List<AudioStream> audioStreams = new ArrayList<>(); private List<AudioStream> audioStreams = List.of();
private List<VideoStream> videoOnlyStreams = new ArrayList<>(); private List<VideoStream> videoOnlyStreams = List.of();
private String dashMpdUrl = ""; private String dashMpdUrl = "";
private String hlsUrl = ""; private String hlsUrl = "";
private List<InfoItem> relatedItems = new ArrayList<>(); private List<InfoItem> relatedItems = List.of();
private long startPosition = 0; private long startPosition = 0;
private List<SubtitlesStream> subtitles = new ArrayList<>(); private List<SubtitlesStream> subtitles = List.of();
private String host = ""; private String host = "";
private StreamExtractor.Privacy privacy; private StreamExtractor.Privacy privacy;
@ -391,15 +377,15 @@ public class StreamInfo extends Info {
private String licence = ""; private String licence = "";
private String supportInfo = ""; private String supportInfo = "";
private Locale language = null; private Locale language = null;
private List<String> tags = new ArrayList<>(); private List<String> tags = List.of();
private List<StreamSegment> streamSegments = new ArrayList<>(); private List<StreamSegment> streamSegments = List.of();
private List<MetaInfo> metaInfo = new ArrayList<>(); private List<MetaInfo> metaInfo = List.of();
private boolean shortFormContent = false; private boolean shortFormContent = false;
/** /**
* Preview frames, e.g. for the storyboard / seekbar thumbnail preview * Preview frames, e.g. for the storyboard / seekbar thumbnail preview
*/ */
private List<Frameset> previewFrames = Collections.emptyList(); private List<Frameset> previewFrames = List.of();
/** /**
* Get the stream type * Get the stream type
@ -419,12 +405,13 @@ public class StreamInfo extends Info {
* *
* @return the thumbnail url as a string * @return the thumbnail url as a string
*/ */
public String getThumbnailUrl() { @Nonnull
return thumbnailUrl; public List<Image> getThumbnails() {
return thumbnails;
} }
public void setThumbnailUrl(final String thumbnailUrl) { public void setThumbnails(@Nonnull final List<Image> thumbnails) {
this.thumbnailUrl = thumbnailUrl; this.thumbnails = thumbnails;
} }
public String getTextualUploadDate() { public String getTextualUploadDate() {
@ -522,12 +509,13 @@ public class StreamInfo extends Info {
this.uploaderUrl = uploaderUrl; this.uploaderUrl = uploaderUrl;
} }
public String getUploaderAvatarUrl() { @Nonnull
return uploaderAvatarUrl; public List<Image> getUploaderAvatars() {
return uploaderAvatars;
} }
public void setUploaderAvatarUrl(final String uploaderAvatarUrl) { public void setUploaderAvatars(@Nonnull final List<Image> uploaderAvatars) {
this.uploaderAvatarUrl = uploaderAvatarUrl; this.uploaderAvatars = uploaderAvatars;
} }
public boolean isUploaderVerified() { public boolean isUploaderVerified() {
@ -562,12 +550,13 @@ public class StreamInfo extends Info {
this.subChannelUrl = subChannelUrl; this.subChannelUrl = subChannelUrl;
} }
public String getSubChannelAvatarUrl() { @Nonnull
return subChannelAvatarUrl; public List<Image> getSubChannelAvatars() {
return subChannelAvatars;
} }
public void setSubChannelAvatarUrl(final String subChannelAvatarUrl) { public void setSubChannelAvatars(@Nonnull final List<Image> subChannelAvatars) {
this.subChannelAvatarUrl = subChannelAvatarUrl; this.subChannelAvatars = subChannelAvatars;
} }
public List<VideoStream> getVideoStreams() { public List<VideoStream> getVideoStreams() {