Finish transition to use getters on Info classes

- Renamed Collector method
This commit is contained in:
Mauricio Colli 2018-03-11 17:50:40 -03:00
parent 6c07b7851b
commit 5dd2daad37
35 changed files with 393 additions and 398 deletions

View File

@ -31,7 +31,7 @@ public interface Collector<I, E> {
* Get all items * Get all items
* @return the items * @return the items
*/ */
List<I> getItemList(); List<I> getItems();
/** /**
* Get all errors * Get all errors

View File

@ -7,16 +7,16 @@ import java.util.List;
public abstract class Info implements Serializable { public abstract class Info implements Serializable {
public final int service_id; private final int serviceId;
/** /**
* Id of this Info object <br> * Id of this Info object <br>
* e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 &gt; RER5qCTzZ7 * e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 &gt; RER5qCTzZ7
*/ */
public final String id; private final String id;
public final String url; private final String url;
public final String name; private final String name;
public final List<Throwable> errors = new ArrayList<>(); private final List<Throwable> errors = new ArrayList<>();
public void addError(Throwable throwable) { public void addError(Throwable throwable) {
this.errors.add(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) { public Info(int serviceId, String id, String url, String name) {
this.service_id = serviceId; this.serviceId = serviceId;
this.id = id; this.id = id;
this.url = url; this.url = url;
this.name = name; this.name = name;
} }
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "[url=\"" + url + "\", name=\"" + name + "\"]"; return getClass().getSimpleName() + "[url=\"" + url + "\", name=\"" + name + "\"]";
} }
public int getServiceId() { public int getServiceId() {
return service_id; return serviceId;
} }
public String getId() { public String getId() {

View File

@ -23,25 +23,25 @@ package org.schabi.newpipe.extractor;
import java.io.Serializable; import java.io.Serializable;
public abstract class InfoItem implements Serializable { public abstract class InfoItem implements Serializable {
public final InfoType info_type; private final InfoType infoType;
public final int service_id; private final int serviceId;
public final String url; private final String url;
public final String name; private final String name;
public String thumbnail_url; private String thumbnailUrl;
public InfoItem(InfoType infoType, int serviceId, String url, String name) { public InfoItem(InfoType infoType, int serviceId, String url, String name) {
this.info_type = infoType; this.infoType = infoType;
this.service_id = serviceId; this.serviceId = serviceId;
this.url = url; this.url = url;
this.name = name; this.name = name;
} }
public InfoType getInfoType() { public InfoType getInfoType() {
return info_type; return infoType;
} }
public int getServiceId() { public int getServiceId() {
return service_id; return serviceId;
} }
public String getUrl() { public String getUrl() {
@ -53,11 +53,11 @@ public abstract class InfoItem implements Serializable {
} }
public void setThumbnailUrl(String thumbnailUrl) { public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnail_url = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
} }
public String getThumbnailUrl() { public String getThumbnailUrl() {
return thumbnail_url; return thumbnailUrl;
} }
@Override @Override

View File

@ -42,7 +42,7 @@ public abstract class InfoItemsCollector<I extends InfoItem, E> implements Colle
} }
@Override @Override
public List<I> getItemList() { public List<I> getItems() {
return Collections.unmodifiableList(itemList); return Collections.unmodifiableList(itemList);
} }

View File

@ -46,7 +46,7 @@ public abstract class ListExtractor extends Extractor {
private final List<Throwable> errors; private final List<Throwable> errors;
public InfoItemPage(InfoItemsCollector<T, ?> collector, String nextPageUrl) { public InfoItemPage(InfoItemsCollector<T, ?> collector, String nextPageUrl) {
this(collector.getItemList(), nextPageUrl, collector.getErrors()); this(collector.getItems(), nextPageUrl, collector.getErrors());
} }
public InfoItemPage(List<T> itemsList, String nextPageUrl, List<Throwable> errors) { public InfoItemPage(List<T> itemsList, String nextPageUrl, List<Throwable> errors) {

View File

@ -2,20 +2,20 @@ package org.schabi.newpipe.extractor;
import java.util.List; import java.util.List;
public abstract class ListInfo extends Info { public abstract class ListInfo<T extends InfoItem> extends Info {
public List<InfoItem> related_streams; private List<T> relatedItems;
public String nextPageUrl = null; private String nextPageUrl = null;
public ListInfo(int serviceId, String id, String url, String name) { public ListInfo(int serviceId, String id, String url, String name) {
super(serviceId, id, url, name); super(serviceId, id, url, name);
} }
public List<InfoItem> getRelatedStreams() { public List<T> getRelatedItems() {
return related_streams; return relatedItems;
} }
public void setRelatedStreams(List<InfoItem> related_streams) { public void setRelatedItems(List<T> relatedItems) {
this.related_streams = related_streams; this.relatedItems = relatedItems;
} }
public boolean hasNextPage() { public boolean hasNextPage() {

View File

@ -79,7 +79,7 @@ public class ChannelInfo extends ListInfo {
info.addError(e); info.addError(e);
} }
info.setRelatedStreams(ExtractorHelper.getInfoItemsOrLogError(info, extractor)); info.setRelatedItems(ExtractorHelper.getInfoItemsOrLogError(info, extractor));
try { try {
info.setSubscriberCount(extractor.getSubscriberCount()); info.setSubscriberCount(extractor.getSubscriberCount());
@ -96,42 +96,42 @@ public class ChannelInfo extends ListInfo {
return info; return info;
} }
public String avatar_url; private String avatarUrl;
public String banner_url; private String bannerUrl;
public String feed_url; private String feedUrl;
public long subscriber_count = -1; private long subscriberCount = -1;
public String description; private String description;
public String getAvatarUrl() { public String getAvatarUrl() {
return avatar_url; return avatarUrl;
} }
public void setAvatarUrl(String avatarUrl) { public void setAvatarUrl(String avatarUrl) {
this.avatar_url = avatarUrl; this.avatarUrl = avatarUrl;
} }
public String getBannerUrl() { public String getBannerUrl() {
return banner_url; return bannerUrl;
} }
public void setBannerUrl(String bannerUrl) { public void setBannerUrl(String bannerUrl) {
this.banner_url = bannerUrl; this.bannerUrl = bannerUrl;
} }
public String getFeedUrl() { public String getFeedUrl() {
return feed_url; return feedUrl;
} }
public void setFeedUrl(String feedUrl) { public void setFeedUrl(String feedUrl) {
this.feed_url = feedUrl; this.feedUrl = feedUrl;
} }
public long getSubscriberCount() { public long getSubscriberCount() {
return subscriber_count; return subscriberCount;
} }
public void setSubscriberCount(long subscriberCount) { public void setSubscriberCount(long subscriberCount) {
this.subscriber_count = subscriberCount; this.subscriberCount = subscriberCount;
} }
public String getDescription() { public String getDescription() {

View File

@ -24,9 +24,9 @@ import org.schabi.newpipe.extractor.InfoItem;
public class ChannelInfoItem extends InfoItem { public class ChannelInfoItem extends InfoItem {
public String description; private String description;
public long subscriber_count = -1; private long subscriberCount = -1;
public long stream_count = -1; private long streamCount = -1;
public ChannelInfoItem(int serviceId, String url, String name) { public ChannelInfoItem(int serviceId, String url, String name) {
@ -42,18 +42,18 @@ public class ChannelInfoItem extends InfoItem {
} }
public long getSubscriberCount() { public long getSubscriberCount() {
return subscriber_count; return subscriberCount;
} }
public void setSubscriberCount(long subscriber_count) { public void setSubscriberCount(long subscriber_count) {
this.subscriber_count = subscriber_count; this.subscriberCount = subscriber_count;
} }
public long getStreamCount() { public long getStreamCount() {
return stream_count; return streamCount;
} }
public void setStreamCount(long stream_count) { public void setStreamCount(long stream_count) {
this.stream_count = stream_count; this.streamCount = stream_count;
} }
} }

View File

@ -75,7 +75,7 @@ public class KioskInfo extends ListInfo {
KioskInfo info = new KioskInfo(serviceId, id, name, url); KioskInfo info = new KioskInfo(serviceId, id, name, url);
info.related_streams = ExtractorHelper.getInfoItemsOrLogError(info, extractor); info.setRelatedItems(ExtractorHelper.getInfoItemsOrLogError(info, extractor));
return info; return info;
} }

View File

@ -75,63 +75,63 @@ public class PlaylistInfo extends ListInfo {
info.addError(e); info.addError(e);
} }
info.setRelatedStreams(getInfoItemsOrLogError(info, extractor)); info.setRelatedItems(getInfoItemsOrLogError(info, extractor));
info.setNextPageUrl(extractor.getNextPageUrl()); info.setNextPageUrl(extractor.getNextPageUrl());
return info; return info;
} }
public String thumbnail_url; private String thumbnailUrl;
public String banner_url; private String bannerUrl;
public String uploader_url; private String uploaderUrl;
public String uploader_name; private String uploaderName;
public String uploader_avatar_url; private String uploaderAvatarUrl;
public long stream_count = 0; private long streamCount = 0;
public String getThumbnailUrl() { public String getThumbnailUrl() {
return thumbnail_url; return thumbnailUrl;
}
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;
} }
public void setThumbnailUrl(String thumbnailUrl) { public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnail_url = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
}
public String getBannerUrl() {
return bannerUrl;
} }
public void setBannerUrl(String bannerUrl) { public void setBannerUrl(String bannerUrl) {
this.banner_url = bannerUrl; this.bannerUrl = bannerUrl;
}
public String getUploaderUrl() {
return uploaderUrl;
} }
public void setUploaderUrl(String uploaderUrl) { public void setUploaderUrl(String uploaderUrl) {
this.uploader_url = uploaderUrl; this.uploaderUrl = uploaderUrl;
}
public String getUploaderName() {
return uploaderName;
} }
public void setUploaderName(String uploaderName) { public void setUploaderName(String uploaderName) {
this.uploader_name = uploaderName; this.uploaderName = uploaderName;
}
public String getUploaderAvatarUrl() {
return uploaderAvatarUrl;
} }
public void setUploaderAvatarUrl(String uploaderAvatarUrl) { public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
this.uploader_avatar_url = uploaderAvatarUrl; this.uploaderAvatarUrl = uploaderAvatarUrl;
}
public long getStreamCount() {
return streamCount;
} }
public void setStreamCount(long streamCount) { public void setStreamCount(long streamCount) {
this.stream_count = streamCount; this.streamCount = streamCount;
} }
} }

View File

@ -4,29 +4,29 @@ import org.schabi.newpipe.extractor.InfoItem;
public class PlaylistInfoItem extends InfoItem { public class PlaylistInfoItem extends InfoItem {
public String uploader_name; private String uploaderName;
/** /**
* How many streams this playlist have * How many streams this playlist have
*/ */
public long stream_count = 0; private long streamCount = 0;
public PlaylistInfoItem(int serviceId, String url, String name) { public PlaylistInfoItem(int serviceId, String url, String name) {
super(InfoType.PLAYLIST, serviceId, url, name); super(InfoType.PLAYLIST, serviceId, url, name);
} }
public String getUploaderName() { public String getUploaderName() {
return uploader_name; return uploaderName;
} }
public void setUploaderName(String uploader_name) { public void setUploaderName(String uploader_name) {
this.uploader_name = uploader_name; this.uploaderName = uploader_name;
} }
public long getStreamCount() { public long getStreamCount() {
return stream_count; return streamCount;
} }
public void setStreamCount(long stream_count) { public void setStreamCount(long stream_count) {
this.stream_count = stream_count; this.streamCount = stream_count;
} }
} }

View File

@ -1,14 +1,16 @@
package org.schabi.newpipe.extractor.search; package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector; 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.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; 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.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.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
/* /*
* Created by Christian Schabesberger on 12.02.17. * Created by Christian Schabesberger on 12.02.17.
@ -60,7 +62,7 @@ public class InfoItemsSearchCollector extends InfoItemsCollector<InfoItem, InfoI
} }
public SearchResult getSearchResult() throws ExtractionException { public SearchResult getSearchResult() throws ExtractionException {
return new SearchResult(getServiceId(), suggestion, getItemList(), getErrors()); return new SearchResult(getServiceId(), suggestion, getItems(), getErrors());
} }
@Override @Override

View File

@ -119,7 +119,7 @@ public class SoundcloudParsingHelper {
public static String getUsersFromApiMinItems(int minItems, ChannelInfoItemsCollector collector, String apiUrl) throws IOException, ReCaptchaException, ParsingException { public static String getUsersFromApiMinItems(int minItems, ChannelInfoItemsCollector collector, String apiUrl) throws IOException, ReCaptchaException, ParsingException {
String nextPageUrl = SoundcloudParsingHelper.getUsersFromApi(collector, apiUrl); String nextPageUrl = SoundcloudParsingHelper.getUsersFromApi(collector, apiUrl);
while (!nextPageUrl.isEmpty() && collector.getItemList().size() < minItems) { while (!nextPageUrl.isEmpty() && collector.getItems().size() < minItems) {
nextPageUrl = SoundcloudParsingHelper.getUsersFromApi(collector, nextPageUrl); nextPageUrl = SoundcloudParsingHelper.getUsersFromApi(collector, nextPageUrl);
} }
@ -170,7 +170,7 @@ public class SoundcloudParsingHelper {
public static String getStreamsFromApiMinItems(int minItems, StreamInfoItemsCollector collector, String apiUrl) throws IOException, ReCaptchaException, ParsingException { public static String getStreamsFromApiMinItems(int minItems, StreamInfoItemsCollector collector, String apiUrl) throws IOException, ReCaptchaException, ParsingException {
String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl); String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl);
while (!nextPageUrl.isEmpty() && collector.getItemList().size() < minItems) { while (!nextPageUrl.isEmpty() && collector.getItems().size() < minItems) {
nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, nextPageUrl); nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, nextPageUrl);
} }

View File

@ -71,9 +71,9 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
// if it also fails, return null // if it also fails, return null
try { try {
final StreamInfoItemsCollector infoItems = getInfoItems(); final StreamInfoItemsCollector infoItems = getInfoItems();
if (infoItems.getItemList().isEmpty()) return null; if (infoItems.getItems().isEmpty()) return null;
for (StreamInfoItem item : infoItems.getItemList()) { for (StreamInfoItem item : infoItems.getItems()) {
final String thumbnailUrl = item.getThumbnailUrl(); final String thumbnailUrl = item.getThumbnailUrl();
if (thumbnailUrl == null || thumbnailUrl.isEmpty()) continue; if (thumbnailUrl == null || thumbnailUrl.isEmpty()) continue;

View File

@ -43,7 +43,7 @@ public class SoundcloudSubscriptionExtractor extends SubscriptionExtractor {
// ± 2000 is the limit of followings on SoundCloud, so this minimum should be enough // ± 2000 is the limit of followings on SoundCloud, so this minimum should be enough
SoundcloudParsingHelper.getUsersFromApiMinItems(2500, collector, apiUrl); SoundcloudParsingHelper.getUsersFromApiMinItems(2500, collector, apiUrl);
return toSubscriptionItems(collector.getItemList()); return toSubscriptionItems(collector.getItems());
} }
private String getUrlFrom(String channelUrl) { private String getUrlFrom(String channelUrl) {

View File

@ -477,7 +477,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
collector.commit(extractVideoPreviewInfo(doc.select("div[class=\"watch-sidebar-section\"]") collector.commit(extractVideoPreviewInfo(doc.select("div[class=\"watch-sidebar-section\"]")
.first().select("li").first())); .first().select("li").first()));
return collector.getItemList().get(0); return collector.getItems().get(0);
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException("Could not get next video", e); throw new ParsingException("Could not get next video", e);
} }

View File

@ -7,7 +7,7 @@ import org.schabi.newpipe.extractor.utils.DashMpdParser;
import org.schabi.newpipe.extractor.utils.ExtractorHelper; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
/* /*
@ -33,209 +33,20 @@ import java.util.List;
/** /**
* Info object for opened videos, ie the video ready to play. * Info object for opened videos, ie the video ready to play.
*/ */
@SuppressWarnings("WeakerAccess")
public class StreamInfo extends Info { public class StreamInfo extends Info {
public StreamInfo(int serviceId, String url, StreamType streamType, String id, String name, int ageLimit) {
super(serviceId, id, url, name);
this.stream_type = streamType;
this.age_limit = ageLimit;
}
/**
* Get the stream type
* @return the stream type
*/
public StreamType getStreamType() {
return stream_type;
}
/**
* Get the thumbnail url
* @return the thumbnail url as a string
*/
public String getThumbnailUrl() {
return thumbnail_url;
}
public String getUploadDate() {
return upload_date;
}
/**
* Get the duration in seconds
* @return the duration in seconds
*/
public long getDuration() {
return duration;
}
public int getAgeLimit() {
return age_limit;
}
public String getDescription() {
return description;
}
public long getViewCount() {
return view_count;
}
/**
* Get the number of likes.
* @return The number of likes or -1 if this information is not available
*/
public long getLikeCount() {
return like_count;
}
/**
* Get the number of dislikes.
* @return The number of likes or -1 if this information is not available
*/
public long getDislikeCount() {
return dislike_count;
}
public String getUploaderName() {
return uploader_name;
}
public String getUploaderUrl() {
return uploader_url;
}
public String getUploaderAvatarUrl() {
return uploader_avatar_url;
}
public List<VideoStream> getVideoStreams() {
return video_streams;
}
public List<AudioStream> getAudioStreams() {
return audio_streams;
}
public List<VideoStream> getVideoOnlyStreams() {
return video_only_streams;
}
public String getDashMpdUrl() {
return dashMpdUrl;
}
public String getHlsUrl() {
return hlsUrl;
}
public StreamInfoItem getNextVideo() {
return next_video;
}
public List<InfoItem> getRelatedStreams() {
return related_streams;
}
public long getStartPosition() {
return start_position;
}
public List<Subtitles> 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<VideoStream> video_streams) {
this.video_streams = video_streams;
}
public void setAudioStreams(List<AudioStream> audio_streams) {
this.audio_streams = audio_streams;
}
public void setVideoOnlyStreams(List<VideoStream> 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<InfoItem> related_streams) {
this.related_streams = related_streams;
}
public void setStartPosition(long start_position) {
this.start_position = start_position;
}
public void setSubtitles(List<Subtitles> subtitles) {
this.subtitles = subtitles;
}
public static class StreamExtractException extends ExtractionException { public static class StreamExtractException extends ExtractionException {
StreamExtractException(String message) { StreamExtractException(String message) {
super(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 { public static StreamInfo getInfo(String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url); return getInfo(NewPipe.getServiceByUrl(url), url);
} }
@ -244,10 +55,6 @@ public class StreamInfo extends Info {
return getInfo(service.getStreamExtractor(url)); 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 { private static StreamInfo getInfo(StreamExtractor extractor) throws ExtractionException, IOException {
extractor.fetchPage(); extractor.fetchPage();
StreamInfo streamInfo; StreamInfo streamInfo;
@ -332,9 +139,9 @@ public class StreamInfo extends Info {
} }
// Lists can be null if a exception was thrown during extraction // Lists can be null if a exception was thrown during extraction
if (streamInfo.getVideoStreams() == null) streamInfo.setVideoStreams(Collections.<VideoStream>emptyList()); if (streamInfo.getVideoStreams() == null) streamInfo.setVideoStreams(new ArrayList<VideoStream>());
if (streamInfo.getVideoOnlyStreams()== null) streamInfo.setVideoOnlyStreams(Collections.<VideoStream>emptyList()); if (streamInfo.getVideoOnlyStreams() == null) streamInfo.setVideoOnlyStreams(new ArrayList<VideoStream>());
if (streamInfo.getAudioStreams() == null) streamInfo.setAudioStreams(Collections.<AudioStream>emptyList()); if (streamInfo.getAudioStreams() == null) streamInfo.setAudioStreams(new ArrayList<AudioStream>());
Exception dashMpdError = null; Exception dashMpdError = null;
if (streamInfo.getDashMpdUrl() != null && !streamInfo.getDashMpdUrl().isEmpty()) { 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). // 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()) if ((streamInfo.videoStreams.isEmpty())
&& (streamInfo.audio_streams.isEmpty())) { && (streamInfo.audioStreams.isEmpty())) {
if (dashMpdError != null) { if (dashMpdError != null) {
// If we don't have any video or audio and the dashMpd 'errored', add it to the error list // 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) { } catch (Exception e) {
streamInfo.addError(e); streamInfo.addError(e);
} }
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor)); streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
return streamInfo; return streamInfo;
} }
public StreamType stream_type; private StreamType streamType;
public String thumbnail_url; private String thumbnailUrl;
public String upload_date; private String uploadDate;
public long duration = -1; private long duration = -1;
public int age_limit = -1; private int ageLimit = -1;
public String description; private String description;
public long view_count = -1; private long viewCount = -1;
public long like_count = -1; private long likeCount = -1;
public long dislike_count = -1; private long dislikeCount = -1;
public String uploader_name; private String uploaderName;
public String uploader_url; private String uploaderUrl;
public String uploader_avatar_url; private String uploaderAvatarUrl;
public List<VideoStream> video_streams; private List<VideoStream> videoStreams;
public List<AudioStream> audio_streams; private List<AudioStream> audioStreams;
public List<VideoStream> video_only_streams; private List<VideoStream> videoOnlyStreams;
// 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;
public StreamInfoItem next_video; private String dashMpdUrl;
public List<InfoItem> related_streams; private String hlsUrl;
//in seconds. some metadata is not passed using a StreamInfo object! private StreamInfoItem nextVideo;
public long start_position = 0; private List<InfoItem> relatedStreams;
public List<Subtitles> subtitles; private long startPosition = 0;
private List<Subtitles> 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<VideoStream> getVideoStreams() {
return videoStreams;
}
public void setVideoStreams(List<VideoStream> videoStreams) {
this.videoStreams = videoStreams;
}
public List<AudioStream> getAudioStreams() {
return audioStreams;
}
public void setAudioStreams(List<AudioStream> audioStreams) {
this.audioStreams = audioStreams;
}
public List<VideoStream> getVideoOnlyStreams() {
return videoOnlyStreams;
}
public void setVideoOnlyStreams(List<VideoStream> 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<InfoItem> getRelatedStreams() {
return relatedStreams;
}
public void setRelatedStreams(List<InfoItem> relatedStreams) {
this.relatedStreams = relatedStreams;
}
public long getStartPosition() {
return startPosition;
}
public void setStartPosition(long startPosition) {
this.startPosition = startPosition;
}
public List<Subtitles> getSubtitles() {
return subtitles;
}
public void setSubtitles(List<Subtitles> subtitles) {
this.subtitles = subtitles;
}
} }

View File

@ -26,42 +26,46 @@ import org.schabi.newpipe.extractor.InfoItem;
* Info object for previews of unopened videos, eg search results, related videos * Info object for previews of unopened videos, eg search results, related videos
*/ */
public class StreamInfoItem extends InfoItem { public class StreamInfoItem extends InfoItem {
public final StreamType stream_type; private final StreamType streamType;
public String uploader_name; private String uploaderName;
public String upload_date; private String uploadDate;
public long view_count = -1; private long viewCount = -1;
public long duration = -1; private long duration = -1;
private String uploaderUrl = null; private String uploaderUrl = null;
public StreamInfoItem(int serviceId, String url, String name, StreamType streamType) { public StreamInfoItem(int serviceId, String url, String name, StreamType streamType) {
super(InfoType.STREAM, serviceId, url, name); super(InfoType.STREAM, serviceId, url, name);
this.stream_type = streamType; this.streamType = streamType;
}
public void setUploaderUrl(String uploaderUrl) {
this.uploaderUrl = uploaderUrl;
}
public String getUploaderUrl() {
return uploaderUrl;
} }
public StreamType getStreamType() { public StreamType getStreamType() {
return stream_type; return streamType;
} }
public String getUploaderName() { public String getUploaderName() {
return uploader_name; return uploaderName;
}
public void setUploaderName(String uploader_name) {
this.uploaderName = uploader_name;
} }
public String getUploadDate() { public String getUploadDate() {
return upload_date; return uploadDate;
}
public void setUploadDate(String upload_date) {
this.uploadDate = upload_date;
} }
public long getViewCount() { public long getViewCount() {
return view_count; return viewCount;
}
public void setViewCount(long view_count) {
this.viewCount = view_count;
} }
public long getDuration() { public long getDuration() {
@ -72,32 +76,28 @@ public class StreamInfoItem extends InfoItem {
this.duration = duration; this.duration = duration;
} }
public void setUploaderName(String uploader_name) { public String getUploaderUrl() {
this.uploader_name = uploader_name; return uploaderUrl;
} }
public void setUploadDate(String upload_date) { public void setUploaderUrl(String uploaderUrl) {
this.upload_date = upload_date; this.uploaderUrl = uploaderUrl;
}
public void setViewCount(long view_count) {
this.view_count = view_count;
} }
@Override @Override
public String toString() { public String toString() {
return "StreamInfoItem{" + return "StreamInfoItem{" +
"stream_type=" + stream_type + "streamType=" + streamType +
", uploader_name='" + uploader_name + '\'' + ", uploaderName='" + uploaderName + '\'' +
", upload_date='" + upload_date + '\'' + ", uploadDate='" + uploadDate + '\'' +
", view_count=" + view_count + ", viewCount=" + viewCount +
", duration=" + duration + ", duration=" + duration +
", uploaderUrl='" + uploaderUrl + '\'' + ", uploaderUrl='" + uploaderUrl + '\'' +
", info_type=" + info_type + ", infoType=" + getInfoType() +
", service_id=" + service_id + ", serviceId=" + getServiceId() +
", url='" + url + '\'' + ", url='" + getUrl() + '\'' +
", name='" + name + '\'' + ", name='" + getName() + '\'' +
", thumbnail_url='" + thumbnail_url + '\'' + ", thumbnailUrl='" + getThumbnailUrl() + '\'' +
'}'; '}';
} }
} }

View File

@ -96,7 +96,7 @@ public class StreamInfoItemsCollector extends InfoItemsCollector<StreamInfoItem,
public List<StreamInfoItem> getStreamInfoItemList() { public List<StreamInfoItem> getStreamInfoItemList() {
List<StreamInfoItem> siiList = new Vector<>(); List<StreamInfoItem> siiList = new Vector<>();
for(InfoItem ii : super.getItemList()) { for(InfoItem ii : super.getItems()) {
if(ii instanceof StreamInfoItem) { if(ii instanceof StreamInfoItem) {
siiList.add((StreamInfoItem) ii); siiList.add((StreamInfoItem) ii);
} }

View File

@ -64,9 +64,9 @@ public class DashMpdParser {
String dashDoc; String dashDoc;
Downloader downloader = NewPipe.getDownloader(); Downloader downloader = NewPipe.getDownloader();
try { try {
dashDoc = downloader.download(streamInfo.dashMpdUrl); dashDoc = downloader.download(streamInfo.getDashMpdUrl());
} catch (IOException ioe) { } 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) { } catch (ReCaptchaException e) {
throw new ReCaptchaException("reCaptcha Challenge needed"); throw new ReCaptchaException("reCaptcha Challenge needed");
} }
@ -92,19 +92,19 @@ public class DashMpdParser {
if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) { if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) {
AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate); AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate);
if (!Stream.containSimilarStream(audioStream, streamInfo.audio_streams)) { if (!Stream.containSimilarStream(audioStream, streamInfo.getAudioStreams())) {
streamInfo.audio_streams.add(audioStream); streamInfo.getAudioStreams().add(audioStream);
} }
} else { } else {
boolean isVideoOnly = itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY); boolean isVideoOnly = itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY);
VideoStream videoStream = new VideoStream(url, mediaFormat, itag.resolutionString, isVideoOnly); VideoStream videoStream = new VideoStream(url, mediaFormat, itag.resolutionString, isVideoOnly);
if (isVideoOnly) { if (isVideoOnly) {
if (!Stream.containSimilarStream(videoStream, streamInfo.video_only_streams)) { if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoOnlyStreams())) {
streamInfo.video_only_streams.add(videoStream); streamInfo.getVideoOnlyStreams().add(videoStream);
} }
} else if (!Stream.containSimilarStream(videoStream, streamInfo.video_streams)) { } else if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoStreams())) {
streamInfo.video_streams.add(videoStream); streamInfo.getVideoStreams().add(videoStream);
} }
} }
} }

View File

@ -42,7 +42,7 @@ public class ExtractorHelper {
private static List<InfoItem> getInfoItems(Info info, InfoItemsCollector collector) { private static List<InfoItem> getInfoItems(Info info, InfoItemsCollector collector) {
List<InfoItem> result; List<InfoItem> result;
try { try {
result = collector.getItemList(); result = collector.getItems();
info.addAllErrors(collector.getErrors()); info.addAllErrors(collector.getErrors());
} catch (Exception e) { } catch (Exception e) {
info.addError(e); info.addError(e);

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.extractor.utils; package org.schabi.newpipe.extractor.utils;
import org.schabi.newpipe.extractor.Collector;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.List; import java.util.List;
@ -40,8 +39,7 @@ public class Utils {
} }
} }
public static void printErrors(Collector c) { public static void printErrors(List<Throwable> errors) {
List<Throwable> errors = c.getErrors();
for(Throwable e : errors) { for(Throwable e : errors) {
e.printStackTrace(); e.printStackTrace();
System.err.println("----------------"); System.err.println("----------------");

View File

@ -34,7 +34,7 @@ public final class DefaultTests {
public static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception { public static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception {
final InfoItemsCollector<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems(); final InfoItemsCollector<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems();
final List<? extends InfoItem> itemsList = itemsCollector.getItemList(); final List<? extends InfoItem> itemsList = itemsCollector.getItems();
List<Throwable> errors = itemsCollector.getErrors(); List<Throwable> errors = itemsCollector.getErrors();
defaultTestListOfItems(expectedServiceId, itemsList, errors); defaultTestListOfItems(expectedServiceId, itemsList, errors);

View File

@ -57,7 +57,7 @@ public class SoundcloudChartsExtractorTest {
} }
} }
assertTrue("no streams are received", assertTrue("no streams are received",
!collector.getItemList().isEmpty() !collector.getItems().isEmpty()
&& collector.getErrors().isEmpty()); && collector.getErrors().isEmpty());
} }
@ -80,7 +80,7 @@ public class SoundcloudChartsExtractorTest {
@Test @Test
public void testGetNextPage() throws Exception { public void testGetNextPage() throws Exception {
extractor.getInfoItems().getItemList(); extractor.getInfoItems().getItems();
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|| extractor.getPage(extractor.getNextPageUrl()).getItemsList().isEmpty()); || extractor.getPage(extractor.getNextPageUrl()).getItemsList().isEmpty());
} }

View File

@ -31,7 +31,7 @@ public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest
@Test @Test
public void testResultsItemType() { public void testResultsItemType() {
for (InfoItem infoItem : result.resultList) { for (InfoItem infoItem : result.resultList) {
assertEquals(InfoItem.InfoType.CHANNEL, infoItem.info_type); assertEquals(InfoItem.InfoType.CHANNEL, infoItem.getInfoType());
} }
} }

View File

@ -51,7 +51,7 @@ public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest
@Test @Test
public void testUserItemType() { public void testUserItemType() {
for (InfoItem infoItem : result.resultList) { for (InfoItem infoItem : result.resultList) {
assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type); assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.getInfoType());
} }
} }

View File

@ -31,7 +31,7 @@ public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest {
@Test @Test
public void testResultsItemType() { public void testResultsItemType() {
for (InfoItem infoItem : result.resultList) { for (InfoItem infoItem : result.resultList) {
assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type); assertEquals(InfoItem.InfoType.STREAM, infoItem.getInfoType());
} }
} }

View File

@ -101,7 +101,7 @@ public class SoundcloudStreamExtractorDefaultTest {
@Test @Test
public void testGetRelatedVideos() throws ExtractionException, IOException { public void testGetRelatedVideos() throws ExtractionException, IOException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos();
assertFalse(relatedVideos.getItemList().isEmpty()); assertFalse(relatedVideos.getItems().isEmpty());
assertTrue(relatedVideos.getErrors().isEmpty()); assertTrue(relatedVideos.getErrors().isEmpty());
} }

View File

@ -52,8 +52,8 @@ public class YoutubeSearchEngineAllTest extends BaseYoutubeSearchTest {
// THe channel should be the first item // THe channel should be the first item
assertTrue(firstInfoItem instanceof ChannelInfoItem); assertTrue(firstInfoItem instanceof ChannelInfoItem);
assertEquals("name", "PewDiePie", firstInfoItem.name); assertEquals("name", "PewDiePie", firstInfoItem.getName());
assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.url); assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.getUrl());
} }
@Ignore @Ignore

View File

@ -52,7 +52,7 @@ public class YoutubeSearchEngineChannelTest extends BaseYoutubeSearchTest {
@Test @Test
public void testResultsItemType() { public void testResultsItemType() {
for (InfoItem infoItem : result.resultList) { for (InfoItem infoItem : result.resultList) {
assertEquals(InfoItem.InfoType.CHANNEL, infoItem.info_type); assertEquals(InfoItem.InfoType.CHANNEL, infoItem.getInfoType());
} }
} }

View File

@ -54,7 +54,7 @@ public class YoutubeSearchEnginePlaylistTest extends BaseYoutubeSearchTest {
public void testInfoItemType() { public void testInfoItemType() {
for (InfoItem infoItem : result.resultList) { for (InfoItem infoItem : result.resultList) {
assertTrue(infoItem instanceof PlaylistInfoItem); assertTrue(infoItem instanceof PlaylistInfoItem);
assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type); assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.getInfoType());
} }
} }

View File

@ -52,7 +52,7 @@ public class YoutubeSearchEngineStreamTest extends BaseYoutubeSearchTest {
@Test @Test
public void testResultsItemType() { public void testResultsItemType() {
for (InfoItem infoItem : result.resultList) { for (InfoItem infoItem : result.resultList) {
assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type); assertEquals(InfoItem.InfoType.STREAM, infoItem.getInfoType());
} }
} }

View File

@ -139,8 +139,8 @@ public class YoutubeStreamExtractorDefaultTest {
@Test @Test
public void testGetRelatedVideos() throws ExtractionException, IOException { public void testGetRelatedVideos() throws ExtractionException, IOException {
StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos(); StreamInfoItemsCollector relatedVideos = extractor.getRelatedVideos();
Utils.printErrors(relatedVideos); Utils.printErrors(relatedVideos.getErrors());
assertFalse(relatedVideos.getItemList().isEmpty()); assertFalse(relatedVideos.getItems().isEmpty());
assertTrue(relatedVideos.getErrors().isEmpty()); assertTrue(relatedVideos.getErrors().isEmpty());
} }

View File

@ -67,8 +67,8 @@ public class YoutubeTrendingExtractorTest {
@Test @Test
public void testGetStreamsQuantity() throws Exception { public void testGetStreamsQuantity() throws Exception {
InfoItemsCollector collector = extractor.getInfoItems(); InfoItemsCollector collector = extractor.getInfoItems();
Utils.printErrors(collector); Utils.printErrors(collector.getErrors());
assertTrue("no streams are received", collector.getItemList().size() >= 20); assertTrue("no streams are received", collector.getItems().size() >= 20);
} }
@Test @Test

View File

@ -50,7 +50,7 @@ public class YoutubeTrendingKioskInfoTest {
@Test @Test
public void getStreams() { public void getStreams() {
assertFalse(kioskInfo.getRelatedStreams().isEmpty()); assertFalse(kioskInfo.getRelatedItems().isEmpty());
} }
@Test @Test