From 5dd2daad3720b0a5aed51b49df967957fd78f583 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sun, 11 Mar 2018 17:50:40 -0300 Subject: [PATCH] Finish transition to use getters on Info classes - Renamed Collector method --- .../schabi/newpipe/extractor/Collector.java | 2 +- .../org/schabi/newpipe/extractor/Info.java | 15 +- .../schabi/newpipe/extractor/InfoItem.java | 22 +- .../newpipe/extractor/InfoItemsCollector.java | 2 +- .../newpipe/extractor/ListExtractor.java | 2 +- .../schabi/newpipe/extractor/ListInfo.java | 14 +- .../extractor/channel/ChannelInfo.java | 28 +- .../extractor/channel/ChannelInfoItem.java | 14 +- .../newpipe/extractor/kiosk/KioskInfo.java | 2 +- .../extractor/playlist/PlaylistInfo.java | 68 +-- .../extractor/playlist/PlaylistInfoItem.java | 12 +- .../search/InfoItemsSearchCollector.java | 12 +- .../soundcloud/SoundcloudParsingHelper.java | 4 +- .../SoundcloudPlaylistExtractor.java | 4 +- .../SoundcloudSubscriptionExtractor.java | 2 +- .../youtube/YoutubeStreamExtractor.java | 2 +- .../newpipe/extractor/stream/StreamInfo.java | 458 +++++++++--------- .../extractor/stream/StreamInfoItem.java | 70 +-- .../stream/StreamInfoItemsCollector.java | 2 +- .../extractor/utils/DashMpdParser.java | 16 +- .../extractor/utils/ExtractorHelper.java | 2 +- .../schabi/newpipe/extractor/utils/Utils.java | 4 +- .../extractor/services/DefaultTests.java | 2 +- .../SoundcloudChartsExtractorTest.java | 4 +- .../SoundcloudSearchEngineChannelTest.java | 2 +- .../SoundcloudSearchEnginePlaylistTest.java | 2 +- .../SoundcloudSearchEngineStreamTest.java | 2 +- .../SoundcloudStreamExtractorDefaultTest.java | 2 +- .../youtube/YoutubeSearchEngineAllTest.java | 4 +- .../YoutubeSearchEngineChannelTest.java | 2 +- .../YoutubeSearchEnginePlaylistTest.java | 2 +- .../YoutubeSearchEngineStreamTest.java | 2 +- .../YoutubeStreamExtractorDefaultTest.java | 4 +- .../youtube/YoutubeTrendingExtractorTest.java | 4 +- .../youtube/YoutubeTrendingKioskInfoTest.java | 2 +- 35 files changed, 393 insertions(+), 398 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/Collector.java b/src/main/java/org/schabi/newpipe/extractor/Collector.java index f7067f714..411058266 100644 --- a/src/main/java/org/schabi/newpipe/extractor/Collector.java +++ b/src/main/java/org/schabi/newpipe/extractor/Collector.java @@ -31,7 +31,7 @@ public interface Collector { * Get all items * @return the items */ - List getItemList(); + List getItems(); /** * Get all errors diff --git a/src/main/java/org/schabi/newpipe/extractor/Info.java b/src/main/java/org/schabi/newpipe/extractor/Info.java index 8e9fc79d0..2f02a460b 100644 --- a/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -7,16 +7,16 @@ import java.util.List; public abstract class Info implements Serializable { - public final int service_id; + private final int serviceId; /** * Id of this Info object
* e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 > RER5qCTzZ7 */ - public final String id; - public final String url; - public final String name; + private final String id; + private final String url; + private final String name; - public final List errors = new ArrayList<>(); + private final List errors = new ArrayList<>(); public void addError(Throwable throwable) { this.errors.add(throwable); @@ -27,20 +27,19 @@ public abstract class Info implements Serializable { } public Info(int serviceId, String id, String url, String name) { - this.service_id = serviceId; + this.serviceId = serviceId; this.id = id; this.url = url; this.name = name; } - @Override public String toString() { return getClass().getSimpleName() + "[url=\"" + url + "\", name=\"" + name + "\"]"; } public int getServiceId() { - return service_id; + return serviceId; } public String getId() { diff --git a/src/main/java/org/schabi/newpipe/extractor/InfoItem.java b/src/main/java/org/schabi/newpipe/extractor/InfoItem.java index 44ec1f651..4bed6bfbb 100644 --- a/src/main/java/org/schabi/newpipe/extractor/InfoItem.java +++ b/src/main/java/org/schabi/newpipe/extractor/InfoItem.java @@ -23,25 +23,25 @@ package org.schabi.newpipe.extractor; import java.io.Serializable; public abstract class InfoItem implements Serializable { - public final InfoType info_type; - public final int service_id; - public final String url; - public final String name; - public String thumbnail_url; + private final InfoType infoType; + private final int serviceId; + private final String url; + private final String name; + private String thumbnailUrl; public InfoItem(InfoType infoType, int serviceId, String url, String name) { - this.info_type = infoType; - this.service_id = serviceId; + this.infoType = infoType; + this.serviceId = serviceId; this.url = url; this.name = name; } public InfoType getInfoType() { - return info_type; + return infoType; } public int getServiceId() { - return service_id; + return serviceId; } public String getUrl() { @@ -53,11 +53,11 @@ public abstract class InfoItem implements Serializable { } public void setThumbnailUrl(String thumbnailUrl) { - this.thumbnail_url = thumbnailUrl; + this.thumbnailUrl = thumbnailUrl; } public String getThumbnailUrl() { - return thumbnail_url; + return thumbnailUrl; } @Override diff --git a/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java b/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java index 706f2912e..c9ee7401c 100644 --- a/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java +++ b/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java @@ -42,7 +42,7 @@ public abstract class InfoItemsCollector implements Colle } @Override - public List getItemList() { + public List getItems() { return Collections.unmodifiableList(itemList); } diff --git a/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java b/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java index 06cded295..aeeff6251 100644 --- a/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java @@ -46,7 +46,7 @@ public abstract class ListExtractor extends Extractor { private final List errors; public InfoItemPage(InfoItemsCollector collector, String nextPageUrl) { - this(collector.getItemList(), nextPageUrl, collector.getErrors()); + this(collector.getItems(), nextPageUrl, collector.getErrors()); } public InfoItemPage(List itemsList, String nextPageUrl, List errors) { diff --git a/src/main/java/org/schabi/newpipe/extractor/ListInfo.java b/src/main/java/org/schabi/newpipe/extractor/ListInfo.java index a8e391206..74cbcc1f2 100644 --- a/src/main/java/org/schabi/newpipe/extractor/ListInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/ListInfo.java @@ -2,20 +2,20 @@ package org.schabi.newpipe.extractor; import java.util.List; -public abstract class ListInfo extends Info { - public List related_streams; - public String nextPageUrl = null; +public abstract class ListInfo extends Info { + private List relatedItems; + private String nextPageUrl = null; public ListInfo(int serviceId, String id, String url, String name) { super(serviceId, id, url, name); } - public List getRelatedStreams() { - return related_streams; + public List getRelatedItems() { + return relatedItems; } - public void setRelatedStreams(List related_streams) { - this.related_streams = related_streams; + public void setRelatedItems(List relatedItems) { + this.relatedItems = relatedItems; } public boolean hasNextPage() { diff --git a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java index 7695368b2..0d9066c42 100644 --- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java @@ -79,7 +79,7 @@ public class ChannelInfo extends ListInfo { info.addError(e); } - info.setRelatedStreams(ExtractorHelper.getInfoItemsOrLogError(info, extractor)); + info.setRelatedItems(ExtractorHelper.getInfoItemsOrLogError(info, extractor)); try { info.setSubscriberCount(extractor.getSubscriberCount()); @@ -96,42 +96,42 @@ public class ChannelInfo extends ListInfo { return info; } - public String avatar_url; - public String banner_url; - public String feed_url; - public long subscriber_count = -1; - public String description; + private String avatarUrl; + private String bannerUrl; + private String feedUrl; + private long subscriberCount = -1; + private String description; public String getAvatarUrl() { - return avatar_url; + return avatarUrl; } public void setAvatarUrl(String avatarUrl) { - this.avatar_url = avatarUrl; + this.avatarUrl = avatarUrl; } public String getBannerUrl() { - return banner_url; + return bannerUrl; } public void setBannerUrl(String bannerUrl) { - this.banner_url = bannerUrl; + this.bannerUrl = bannerUrl; } public String getFeedUrl() { - return feed_url; + return feedUrl; } public void setFeedUrl(String feedUrl) { - this.feed_url = feedUrl; + this.feedUrl = feedUrl; } public long getSubscriberCount() { - return subscriber_count; + return subscriberCount; } public void setSubscriberCount(long subscriberCount) { - this.subscriber_count = subscriberCount; + this.subscriberCount = subscriberCount; } public String getDescription() { diff --git a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItem.java b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItem.java index cd6d37071..6d2e61a33 100644 --- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItem.java +++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItem.java @@ -24,9 +24,9 @@ import org.schabi.newpipe.extractor.InfoItem; public class ChannelInfoItem extends InfoItem { - public String description; - public long subscriber_count = -1; - public long stream_count = -1; + private String description; + private long subscriberCount = -1; + private long streamCount = -1; public ChannelInfoItem(int serviceId, String url, String name) { @@ -42,18 +42,18 @@ public class ChannelInfoItem extends InfoItem { } public long getSubscriberCount() { - return subscriber_count; + return subscriberCount; } public void setSubscriberCount(long subscriber_count) { - this.subscriber_count = subscriber_count; + this.subscriberCount = subscriber_count; } public long getStreamCount() { - return stream_count; + return streamCount; } public void setStreamCount(long stream_count) { - this.stream_count = stream_count; + this.streamCount = stream_count; } } diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java index 4a60f0bd6..6ae47ed9e 100644 --- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java @@ -75,7 +75,7 @@ public class KioskInfo extends ListInfo { KioskInfo info = new KioskInfo(serviceId, id, name, url); - info.related_streams = ExtractorHelper.getInfoItemsOrLogError(info, extractor); + info.setRelatedItems(ExtractorHelper.getInfoItemsOrLogError(info, extractor)); return info; } diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index 407e4deea..c854233b9 100644 --- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -75,63 +75,63 @@ public class PlaylistInfo extends ListInfo { info.addError(e); } - info.setRelatedStreams(getInfoItemsOrLogError(info, extractor)); + info.setRelatedItems(getInfoItemsOrLogError(info, extractor)); info.setNextPageUrl(extractor.getNextPageUrl()); return info; } - public String thumbnail_url; - public String banner_url; - public String uploader_url; - public String uploader_name; - public String uploader_avatar_url; - public long stream_count = 0; + private String thumbnailUrl; + private String bannerUrl; + private String uploaderUrl; + private String uploaderName; + private String uploaderAvatarUrl; + private long streamCount = 0; public String getThumbnailUrl() { - return thumbnail_url; - } - - public String getBannerUrl() { - return banner_url; - } - - public String getUploaderUrl() { - return uploader_url; - } - - public String getUploaderName() { - return uploader_name; - } - - public String getUploaderAvatarUrl() { - return uploader_avatar_url; - } - - public long getStreamCount() { - return stream_count; + return thumbnailUrl; } public void setThumbnailUrl(String thumbnailUrl) { - this.thumbnail_url = thumbnailUrl; + this.thumbnailUrl = thumbnailUrl; + } + + public String getBannerUrl() { + return bannerUrl; } public void setBannerUrl(String bannerUrl) { - this.banner_url = bannerUrl; + this.bannerUrl = bannerUrl; + } + + public String getUploaderUrl() { + return uploaderUrl; } public void setUploaderUrl(String uploaderUrl) { - this.uploader_url = uploaderUrl; + this.uploaderUrl = uploaderUrl; + } + + public String getUploaderName() { + return uploaderName; } public void setUploaderName(String uploaderName) { - this.uploader_name = uploaderName; + this.uploaderName = uploaderName; + } + + public String getUploaderAvatarUrl() { + return uploaderAvatarUrl; } public void setUploaderAvatarUrl(String uploaderAvatarUrl) { - this.uploader_avatar_url = uploaderAvatarUrl; + this.uploaderAvatarUrl = uploaderAvatarUrl; + } + + public long getStreamCount() { + return streamCount; } public void setStreamCount(long streamCount) { - this.stream_count = streamCount; + this.streamCount = streamCount; } } diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java index 62a440bdf..bfe31f1ca 100644 --- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java +++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java @@ -4,29 +4,29 @@ import org.schabi.newpipe.extractor.InfoItem; public class PlaylistInfoItem extends InfoItem { - public String uploader_name; + private String uploaderName; /** * How many streams this playlist have */ - public long stream_count = 0; + private long streamCount = 0; public PlaylistInfoItem(int serviceId, String url, String name) { super(InfoType.PLAYLIST, serviceId, url, name); } public String getUploaderName() { - return uploader_name; + return uploaderName; } public void setUploaderName(String uploader_name) { - this.uploader_name = uploader_name; + this.uploaderName = uploader_name; } public long getStreamCount() { - return stream_count; + return streamCount; } public void setStreamCount(long stream_count) { - this.stream_count = stream_count; + this.streamCount = stream_count; } } diff --git a/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java b/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java index 9779120e5..d8f4ca0f9 100644 --- a/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java +++ b/src/main/java/org/schabi/newpipe/extractor/search/InfoItemsSearchCollector.java @@ -1,14 +1,16 @@ package org.schabi.newpipe.extractor.search; -import org.schabi.newpipe.extractor.*; -import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.InfoItemExtractor; +import org.schabi.newpipe.extractor.InfoItemsCollector; import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor; +import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; +import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; /* * Created by Christian Schabesberger on 12.02.17. @@ -60,7 +62,7 @@ public class InfoItemsSearchCollector extends InfoItemsCollector getVideoStreams() { - return video_streams; - } - - public List getAudioStreams() { - return audio_streams; - } - - public List getVideoOnlyStreams() { - return video_only_streams; - } - - public String getDashMpdUrl() { - return dashMpdUrl; - } - - public String getHlsUrl() { - return hlsUrl; - } - - public StreamInfoItem getNextVideo() { - return next_video; - } - - public List getRelatedStreams() { - return related_streams; - } - - public long getStartPosition() { - return start_position; - } - - public List getSubtitles() { - return subtitles; - } - - public void setStreamType(StreamType stream_type) { - this.stream_type = stream_type; - } - - public void setThumbnailUrl(String thumbnail_url) { - this.thumbnail_url = thumbnail_url; - } - - public void setUploadDate(String upload_date) { - this.upload_date = upload_date; - } - - public void setDuration(long duration) { - this.duration = duration; - } - - public void setAgeLimit(int age_limit) { - this.age_limit = age_limit; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setViewCount(long view_count) { - this.view_count = view_count; - } - - public void setLikeCount(long like_count) { - this.like_count = like_count; - } - - public void setDislikeCount(long dislike_count) { - this.dislike_count = dislike_count; - } - - public void setUploaderName(String uploader_name) { - this.uploader_name = uploader_name; - } - - public void setUploaderUrl(String uploader_url) { - this.uploader_url = uploader_url; - } - - public void setUploaderAvatarUrl(String uploader_avatar_url) { - this.uploader_avatar_url = uploader_avatar_url; - } - - public void setVideoStreams(List video_streams) { - this.video_streams = video_streams; - } - - public void setAudioStreams(List audio_streams) { - this.audio_streams = audio_streams; - } - - public void setVideoOnlyStreams(List video_only_streams) { - this.video_only_streams = video_only_streams; - } - - public void setDashMpdUrl(String dashMpdUrl) { - this.dashMpdUrl = dashMpdUrl; - } - - public void setHlsUrl(String hlsUrl) { - this.hlsUrl = hlsUrl; - } - - public void setNextVideo(StreamInfoItem next_video) { - this.next_video = next_video; - } - - public void setRelatedStreams(List related_streams) { - this.related_streams = related_streams; - } - - public void setStartPosition(long start_position) { - this.start_position = start_position; - } - - public void setSubtitles(List subtitles) { - this.subtitles = subtitles; - } - public static class StreamExtractException extends ExtractionException { StreamExtractException(String message) { super(message); } } + public StreamInfo(int serviceId, String url, StreamType streamType, String id, String name, int ageLimit) { + super(serviceId, id, url, name); + this.streamType = streamType; + this.ageLimit = ageLimit; + } + public static StreamInfo getInfo(String url) throws IOException, ExtractionException { return getInfo(NewPipe.getServiceByUrl(url), url); } @@ -244,10 +55,6 @@ public class StreamInfo extends Info { return getInfo(service.getStreamExtractor(url)); } - /** - * Fills out the video info fields which are common to all services. - * Probably needs to be overridden by subclasses - */ private static StreamInfo getInfo(StreamExtractor extractor) throws ExtractionException, IOException { extractor.fetchPage(); StreamInfo streamInfo; @@ -332,9 +139,9 @@ public class StreamInfo extends Info { } // Lists can be null if a 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()); + if (streamInfo.getVideoStreams() == null) streamInfo.setVideoStreams(new ArrayList()); + if (streamInfo.getVideoOnlyStreams() == null) streamInfo.setVideoOnlyStreams(new ArrayList()); + if (streamInfo.getAudioStreams() == null) streamInfo.setAudioStreams(new ArrayList()); Exception dashMpdError = null; if (streamInfo.getDashMpdUrl() != null && !streamInfo.getDashMpdUrl().isEmpty()) { @@ -348,8 +155,8 @@ public class StreamInfo extends Info { } // 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.video_streams.isEmpty()) - && (streamInfo.audio_streams.isEmpty())) { + if ((streamInfo.videoStreams.isEmpty()) + && (streamInfo.audioStreams.isEmpty())) { if (dashMpdError != null) { // If we don't have any video or audio and the dashMpd 'errored', add it to the error list @@ -434,39 +241,228 @@ public class StreamInfo extends Info { } catch (Exception e) { streamInfo.addError(e); } + streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); return streamInfo; } - public StreamType stream_type; - public String thumbnail_url; - public String upload_date; - public long duration = -1; - public int age_limit = -1; - public String description; + private StreamType streamType; + private String thumbnailUrl; + private String uploadDate; + private long duration = -1; + private int ageLimit = -1; + private String description; - public long view_count = -1; - public long like_count = -1; - public long dislike_count = -1; + private long viewCount = -1; + private long likeCount = -1; + private long dislikeCount = -1; - public String uploader_name; - public String uploader_url; - public String uploader_avatar_url; + private String uploaderName; + private String uploaderUrl; + private String uploaderAvatarUrl; - public List video_streams; - public List audio_streams; - public List video_only_streams; - // video streams provided by the dash mpd do not need to be provided as VideoStream. - // Later on this will also apply to audio streams. Since dash mpd is standarized, - // crawling such a file is not service dependent. Therefore getting audio only streams by yust - // providing the dash mpd file will be possible in the future. - public String dashMpdUrl; - public String hlsUrl; + private List videoStreams; + private List audioStreams; + private List videoOnlyStreams; - public StreamInfoItem next_video; - public List related_streams; - //in seconds. some metadata is not passed using a StreamInfo object! - public long start_position = 0; + private String dashMpdUrl; + private String hlsUrl; + private StreamInfoItem nextVideo; + private List relatedStreams; - public List subtitles; + private long startPosition = 0; + private List subtitles; + + /** + * Get the stream type + * + * @return the stream type + */ + public StreamType getStreamType() { + return streamType; + } + + public void setStreamType(StreamType streamType) { + this.streamType = streamType; + } + + /** + * Get the thumbnail url + * + * @return the thumbnail url as a string + */ + public String getThumbnailUrl() { + return thumbnailUrl; + } + + public void setThumbnailUrl(String thumbnailUrl) { + this.thumbnailUrl = thumbnailUrl; + } + + public String getUploadDate() { + return uploadDate; + } + + public void setUploadDate(String uploadDate) { + this.uploadDate = uploadDate; + } + + /** + * Get the duration in seconds + * + * @return the duration in seconds + */ + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + public int getAgeLimit() { + return ageLimit; + } + + public void setAgeLimit(int ageLimit) { + this.ageLimit = ageLimit; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public long getViewCount() { + return viewCount; + } + + public void setViewCount(long viewCount) { + this.viewCount = viewCount; + } + + /** + * Get the number of likes. + * + * @return The number of likes or -1 if this information is not available + */ + public long getLikeCount() { + return likeCount; + } + + public void setLikeCount(long likeCount) { + this.likeCount = likeCount; + } + + /** + * Get the number of dislikes. + * + * @return The number of likes or -1 if this information is not available + */ + public long getDislikeCount() { + return dislikeCount; + } + + public void setDislikeCount(long dislikeCount) { + this.dislikeCount = dislikeCount; + } + + public String getUploaderName() { + return uploaderName; + } + + public void setUploaderName(String uploaderName) { + this.uploaderName = uploaderName; + } + + public String getUploaderUrl() { + return uploaderUrl; + } + + public void setUploaderUrl(String uploaderUrl) { + this.uploaderUrl = uploaderUrl; + } + + public String getUploaderAvatarUrl() { + return uploaderAvatarUrl; + } + + public void setUploaderAvatarUrl(String uploaderAvatarUrl) { + this.uploaderAvatarUrl = uploaderAvatarUrl; + } + + public List getVideoStreams() { + return videoStreams; + } + + public void setVideoStreams(List videoStreams) { + this.videoStreams = videoStreams; + } + + public List getAudioStreams() { + return audioStreams; + } + + public void setAudioStreams(List audioStreams) { + this.audioStreams = audioStreams; + } + + public List getVideoOnlyStreams() { + return videoOnlyStreams; + } + + public void setVideoOnlyStreams(List videoOnlyStreams) { + this.videoOnlyStreams = videoOnlyStreams; + } + + public String getDashMpdUrl() { + return dashMpdUrl; + } + + public void setDashMpdUrl(String dashMpdUrl) { + this.dashMpdUrl = dashMpdUrl; + } + + public String getHlsUrl() { + return hlsUrl; + } + + public void setHlsUrl(String hlsUrl) { + this.hlsUrl = hlsUrl; + } + + public StreamInfoItem getNextVideo() { + return nextVideo; + } + + public void setNextVideo(StreamInfoItem nextVideo) { + this.nextVideo = nextVideo; + } + + public List getRelatedStreams() { + return relatedStreams; + } + + public void setRelatedStreams(List relatedStreams) { + this.relatedStreams = relatedStreams; + } + + public long getStartPosition() { + return startPosition; + } + + public void setStartPosition(long startPosition) { + this.startPosition = startPosition; + } + + public List getSubtitles() { + return subtitles; + } + + public void setSubtitles(List subtitles) { + this.subtitles = subtitles; + } } 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 f97500167..375739160 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java @@ -26,42 +26,46 @@ import org.schabi.newpipe.extractor.InfoItem; * Info object for previews of unopened videos, eg search results, related videos */ public class StreamInfoItem extends InfoItem { - public final StreamType stream_type; + private final StreamType streamType; - public String uploader_name; - public String upload_date; - public long view_count = -1; - public long duration = -1; + private String uploaderName; + private String uploadDate; + private long viewCount = -1; + private long duration = -1; private String uploaderUrl = null; public StreamInfoItem(int serviceId, String url, String name, StreamType streamType) { super(InfoType.STREAM, serviceId, url, name); - this.stream_type = streamType; - } - - public void setUploaderUrl(String uploaderUrl) { - this.uploaderUrl = uploaderUrl; - } - - public String getUploaderUrl() { - return uploaderUrl; + this.streamType = streamType; } public StreamType getStreamType() { - return stream_type; + return streamType; } public String getUploaderName() { - return uploader_name; + return uploaderName; + } + + public void setUploaderName(String uploader_name) { + this.uploaderName = uploader_name; } public String getUploadDate() { - return upload_date; + return uploadDate; + } + + public void setUploadDate(String upload_date) { + this.uploadDate = upload_date; } public long getViewCount() { - return view_count; + return viewCount; + } + + public void setViewCount(long view_count) { + this.viewCount = view_count; } public long getDuration() { @@ -72,32 +76,28 @@ public class StreamInfoItem extends InfoItem { this.duration = duration; } - public void setUploaderName(String uploader_name) { - this.uploader_name = uploader_name; + public String getUploaderUrl() { + return uploaderUrl; } - public void setUploadDate(String upload_date) { - this.upload_date = upload_date; - } - - public void setViewCount(long view_count) { - this.view_count = view_count; + public void setUploaderUrl(String uploaderUrl) { + this.uploaderUrl = uploaderUrl; } @Override public String toString() { return "StreamInfoItem{" + - "stream_type=" + stream_type + - ", uploader_name='" + uploader_name + '\'' + - ", upload_date='" + upload_date + '\'' + - ", view_count=" + view_count + + "streamType=" + streamType + + ", uploaderName='" + uploaderName + '\'' + + ", uploadDate='" + uploadDate + '\'' + + ", viewCount=" + viewCount + ", duration=" + duration + ", uploaderUrl='" + uploaderUrl + '\'' + - ", info_type=" + info_type + - ", service_id=" + service_id + - ", url='" + url + '\'' + - ", name='" + name + '\'' + - ", thumbnail_url='" + thumbnail_url + '\'' + + ", infoType=" + getInfoType() + + ", serviceId=" + getServiceId() + + ", url='" + getUrl() + '\'' + + ", name='" + getName() + '\'' + + ", thumbnailUrl='" + getThumbnailUrl() + '\'' + '}'; } } \ No newline at end of file diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemsCollector.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemsCollector.java index ba9975c6d..b838e7ac8 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemsCollector.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemsCollector.java @@ -96,7 +96,7 @@ public class StreamInfoItemsCollector extends InfoItemsCollector getStreamInfoItemList() { List siiList = new Vector<>(); - for(InfoItem ii : super.getItemList()) { + for(InfoItem ii : super.getItems()) { if(ii instanceof StreamInfoItem) { siiList.add((StreamInfoItem) ii); } diff --git a/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java b/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java index d035fea53..1fb32c13c 100644 --- a/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java +++ b/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java @@ -64,9 +64,9 @@ public class DashMpdParser { String dashDoc; Downloader downloader = NewPipe.getDownloader(); try { - dashDoc = downloader.download(streamInfo.dashMpdUrl); + dashDoc = downloader.download(streamInfo.getDashMpdUrl()); } catch (IOException ioe) { - throw new DashMpdParsingException("Could not get dash mpd: " + streamInfo.dashMpdUrl, ioe); + throw new DashMpdParsingException("Could not get dash mpd: " + streamInfo.getDashMpdUrl(), ioe); } catch (ReCaptchaException e) { throw new ReCaptchaException("reCaptcha Challenge needed"); } @@ -92,19 +92,19 @@ public class DashMpdParser { if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) { AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate); - if (!Stream.containSimilarStream(audioStream, streamInfo.audio_streams)) { - streamInfo.audio_streams.add(audioStream); + if (!Stream.containSimilarStream(audioStream, streamInfo.getAudioStreams())) { + streamInfo.getAudioStreams().add(audioStream); } } else { boolean isVideoOnly = itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY); VideoStream videoStream = new VideoStream(url, mediaFormat, itag.resolutionString, isVideoOnly); if (isVideoOnly) { - if (!Stream.containSimilarStream(videoStream, streamInfo.video_only_streams)) { - streamInfo.video_only_streams.add(videoStream); + if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoOnlyStreams())) { + streamInfo.getVideoOnlyStreams().add(videoStream); } - } else if (!Stream.containSimilarStream(videoStream, streamInfo.video_streams)) { - streamInfo.video_streams.add(videoStream); + } else if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoStreams())) { + streamInfo.getVideoStreams().add(videoStream); } } } diff --git a/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java b/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java index e5b961d85..e50cdf07a 100644 --- a/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java +++ b/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java @@ -42,7 +42,7 @@ public class ExtractorHelper { private static List getInfoItems(Info info, InfoItemsCollector collector) { List result; try { - result = collector.getItemList(); + result = collector.getItems(); info.addAllErrors(collector.getErrors()); } catch (Exception e) { info.addError(e); diff --git a/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index cc49d78f3..663fd093b 100644 --- a/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -1,6 +1,5 @@ package org.schabi.newpipe.extractor.utils; -import org.schabi.newpipe.extractor.Collector; import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.util.List; @@ -40,8 +39,7 @@ public class Utils { } } - public static void printErrors(Collector c) { - List errors = c.getErrors(); + public static void printErrors(List errors) { for(Throwable e : errors) { e.printStackTrace(); System.err.println("----------------"); diff --git a/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java b/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java index 18fea5432..33c8d58cd 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java @@ -34,7 +34,7 @@ public final class DefaultTests { public static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception { final InfoItemsCollector itemsCollector = extractor.getInfoItems(); - final List itemsList = itemsCollector.getItemList(); + final List itemsList = itemsCollector.getItems(); List errors = itemsCollector.getErrors(); defaultTestListOfItems(expectedServiceId, itemsList, errors); diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java index 7c1aa16c4..3c725970a 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java @@ -57,7 +57,7 @@ public class SoundcloudChartsExtractorTest { } } assertTrue("no streams are received", - !collector.getItemList().isEmpty() + !collector.getItems().isEmpty() && collector.getErrors().isEmpty()); } @@ -80,7 +80,7 @@ public class SoundcloudChartsExtractorTest { @Test public void testGetNextPage() throws Exception { - extractor.getInfoItems().getItemList(); + extractor.getInfoItems().getItems(); assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null || extractor.getPage(extractor.getNextPageUrl()).getItemsList().isEmpty()); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java index 44c395d52..b5b31596a 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineChannelTest.java @@ -31,7 +31,7 @@ public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest @Test public void testResultsItemType() { for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.CHANNEL, infoItem.info_type); + assertEquals(InfoItem.InfoType.CHANNEL, infoItem.getInfoType()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java index 492911d47..9106855b9 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEnginePlaylistTest.java @@ -51,7 +51,7 @@ public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest @Test public void testUserItemType() { for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type); + assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.getInfoType()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java index 7aba4720b..da222d338 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudSearchEngineStreamTest.java @@ -31,7 +31,7 @@ public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest { @Test public void testResultsItemType() { for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type); + assertEquals(InfoItem.InfoType.STREAM, infoItem.getInfoType()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java index 37b3e0883..a637d3803 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java @@ -101,7 +101,7 @@ public class SoundcloudStreamExtractorDefaultTest { @Test public void testGetRelatedVideos() throws ExtractionException, IOException { StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); - assertFalse(relatedVideos.getItemList().isEmpty()); + assertFalse(relatedVideos.getItems().isEmpty()); assertTrue(relatedVideos.getErrors().isEmpty()); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java index cefb56655..57422ad70 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineAllTest.java @@ -52,8 +52,8 @@ public class YoutubeSearchEngineAllTest extends BaseYoutubeSearchTest { // THe channel should be the first item assertTrue(firstInfoItem instanceof ChannelInfoItem); - assertEquals("name", "PewDiePie", firstInfoItem.name); - assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.url); + assertEquals("name", "PewDiePie", firstInfoItem.getName()); + assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.getUrl()); } @Ignore diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java index a31a8c933..f8170a4ab 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineChannelTest.java @@ -52,7 +52,7 @@ public class YoutubeSearchEngineChannelTest extends BaseYoutubeSearchTest { @Test public void testResultsItemType() { for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.CHANNEL, infoItem.info_type); + assertEquals(InfoItem.InfoType.CHANNEL, infoItem.getInfoType()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java index a4bd8c5a9..235ba1527 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEnginePlaylistTest.java @@ -54,7 +54,7 @@ public class YoutubeSearchEnginePlaylistTest extends BaseYoutubeSearchTest { public void testInfoItemType() { for (InfoItem infoItem : result.resultList) { assertTrue(infoItem instanceof PlaylistInfoItem); - assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type); + assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.getInfoType()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java index 619e290d5..41d15a736 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSearchEngineStreamTest.java @@ -52,7 +52,7 @@ public class YoutubeSearchEngineStreamTest extends BaseYoutubeSearchTest { @Test public void testResultsItemType() { for (InfoItem infoItem : result.resultList) { - assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type); + assertEquals(InfoItem.InfoType.STREAM, infoItem.getInfoType()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java index ae5920a96..88aa1b96e 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java @@ -139,8 +139,8 @@ public class YoutubeStreamExtractorDefaultTest { @Test public void testGetRelatedVideos() throws ExtractionException, IOException { StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); - Utils.printErrors(relatedVideos); - assertFalse(relatedVideos.getItemList().isEmpty()); + Utils.printErrors(relatedVideos.getErrors()); + assertFalse(relatedVideos.getItems().isEmpty()); assertTrue(relatedVideos.getErrors().isEmpty()); } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java index 760e14e45..0f3288bc1 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java @@ -67,8 +67,8 @@ public class YoutubeTrendingExtractorTest { @Test public void testGetStreamsQuantity() throws Exception { InfoItemsCollector collector = extractor.getInfoItems(); - Utils.printErrors(collector); - assertTrue("no streams are received", collector.getItemList().size() >= 20); + Utils.printErrors(collector.getErrors()); + assertTrue("no streams are received", collector.getItems().size() >= 20); } @Test diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java index 2599df932..3fff4419e 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java @@ -50,7 +50,7 @@ public class YoutubeTrendingKioskInfoTest { @Test public void getStreams() { - assertFalse(kioskInfo.getRelatedStreams().isEmpty()); + assertFalse(kioskInfo.getRelatedItems().isEmpty()); } @Test