Add and use setters

This commit is contained in:
Coffeemakr 2017-11-11 02:55:56 +01:00
parent e11c6e35f6
commit bc44557bdb
No known key found for this signature in database
GPG Key ID: 3F35676D8FF6E743
16 changed files with 543 additions and 190 deletions

View File

@ -2,23 +2,60 @@ package org.schabi.newpipe.extractor;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
public abstract class Info implements Serializable { public abstract class Info implements Serializable {
public int service_id = -1; public final int service_id;
/** /**
* Id of this Info object <br> * Id of this Info object <br>
* e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 > RER5qCTzZ7 * e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 > RER5qCTzZ7
*/ */
public String id; public final String id;
public String url; public final String url;
public String name; public final String name;
public List<Throwable> errors = new ArrayList<>(); public List<Throwable> errors = new ArrayList<>();
public void addError(Throwable throwable) {
this.errors.add(throwable);
}
public void addAllErrors(Collection<Throwable> errors) {
this.errors.addAll(errors);
}
public Info(int serviceId, String id, String url, String name) {
this.service_id = serviceId;
this.id = id;
this.url = url;
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() {
return service_id;
}
public String getId() {
return id;
}
public String getUrl() {
return url;
}
public String getName() {
return name;
}
public List<Throwable> getErrors() {
return errors;
}
} }

View File

@ -20,6 +20,8 @@ package org.schabi.newpipe.extractor;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
import org.schabi.newpipe.extractor.stream.StreamType;
import java.io.Serializable; import java.io.Serializable;
public abstract class InfoItem implements Serializable { public abstract class InfoItem implements Serializable {
@ -29,8 +31,11 @@ public abstract class InfoItem implements Serializable {
public String name; public String name;
public String thumbnail_url; public String thumbnail_url;
public InfoItem(InfoType infoType) { public InfoItem(InfoType infoType, int serviceId, String url, String name) {
this.info_type = infoType; this.info_type = infoType;
this.service_id = serviceId;
this.url = url;
this.name = name;
} }
public InfoType getInfoType() { public InfoType getInfoType() {
@ -49,6 +54,10 @@ public abstract class InfoItem implements Serializable {
return name; return name;
} }
public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnail_url = thumbnailUrl;
}
public String getThumbnailUrl() { public String getThumbnailUrl() {
return thumbnail_url; return thumbnail_url;
} }

View File

@ -6,4 +6,32 @@ public abstract class ListInfo extends Info {
public List<InfoItem> related_streams; public List<InfoItem> related_streams;
public boolean has_more_streams; public boolean has_more_streams;
public String next_streams_url; public String next_streams_url;
public ListInfo(int serviceId, String id, String url, String name) {
super(serviceId, id, url, name);
}
public List<InfoItem> getRelated_streams() {
return related_streams;
}
public void setRelatedStreams(List<InfoItem> related_streams) {
this.related_streams = related_streams;
}
public boolean isHas_more_streams() {
return has_more_streams;
}
public void setHasMoreStreams(boolean has_more_streams) {
this.has_more_streams = has_more_streams;
}
public String getNext_streams_url() {
return next_streams_url;
}
public void setNextStreamsUrl(String next_streams_url) {
this.next_streams_url = next_streams_url;
}
} }

View File

@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.StreamingService;
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.stream.StreamInfoItemCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,6 +35,11 @@ import java.util.ArrayList;
public class ChannelInfo extends ListInfo { public class ChannelInfo extends ListInfo {
public ChannelInfo(int serviceId, String url, String id, String name) {
super(serviceId, id, url, name);
}
public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException { public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl); return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
} }
@ -55,52 +61,47 @@ public class ChannelInfo extends ListInfo {
} }
public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException { public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException {
ChannelInfo info = new ChannelInfo();
// important data // important data
info.service_id = extractor.getServiceId(); int serviceId = extractor.getServiceId();
info.url = extractor.getCleanUrl(); String url = extractor.getCleanUrl();
info.id = extractor.getId(); String id = extractor.getId();
info.name = extractor.getName(); String name = extractor.getName();
ChannelInfo info = new ChannelInfo(serviceId, url, id, name);
try { try {
info.avatar_url = extractor.getAvatarUrl(); info.setAvatarUrl(extractor.getAvatarUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.banner_url = extractor.getBannerUrl(); info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.feed_url = extractor.getFeedUrl(); info.setFeedUrl(extractor.getFeedUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
}
try {
StreamInfoItemCollector c = extractor.getStreams();
info.related_streams = c.getItemList();
info.errors.addAll(c.getErrors());
} catch (Exception e) {
info.errors.add(e);
}
try {
info.subscriber_count = extractor.getSubscriberCount();
} catch (Exception e) {
info.errors.add(e);
}
try {
info.description = extractor.getDescription();
} catch (Exception e) {
info.errors.add(e);
} }
// Lists can be null if a exception was thrown during extraction info.setRelatedStreams(ExtractorHelper.getStreamsOrLogError(info, extractor));
if (info.related_streams == null) info.related_streams = new ArrayList<>();
info.has_more_streams = extractor.hasMoreStreams(); try {
info.next_streams_url = extractor.getNextStreamsUrl(); info.setSubscriberCount(extractor.getSubscriberCount());
} catch (Exception e) {
info.addError(e);
}
try {
info.setDescription(extractor.getDescription());
} catch (Exception e) {
info.addError(e);
}
info.setHasMoreStreams(extractor.hasMoreStreams());
info.setNextStreamsUrl(extractor.getNextStreamsUrl());
return info; return info;
} }
@ -109,4 +110,44 @@ public class ChannelInfo extends ListInfo {
public String feed_url; public String feed_url;
public long subscriber_count = -1; public long subscriber_count = -1;
public String description; public String description;
public String getAvatarUrl() {
return avatar_url;
}
public void setAvatarUrl(String avatarUrl) {
this.avatar_url = avatarUrl;
}
public String getBannerUrl() {
return banner_url;
}
public void setBannerUrl(String bannerUrl) {
this.banner_url = bannerUrl;
}
public String getFeedUrl() {
return feed_url;
}
public void setFeedUrl(String feedUrl) {
this.feed_url = feedUrl;
}
public long getSubscriberCount() {
return subscriber_count;
}
public void setSubscriberCount(long subscriberCount) {
this.subscriber_count = subscriberCount;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
} }

View File

@ -28,7 +28,32 @@ public class ChannelInfoItem extends InfoItem {
public long subscriber_count = -1; public long subscriber_count = -1;
public long stream_count = -1; public long stream_count = -1;
public ChannelInfoItem() {
super(InfoType.CHANNEL); public ChannelInfoItem(int serviceId, String url, String name) {
super(InfoType.CHANNEL, serviceId, url, name);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public long getSubscriberCount() {
return subscriber_count;
}
public void setSubscriberCount(long subscriber_count) {
this.subscriber_count = subscriber_count;
}
public long getStreamCount() {
return stream_count;
}
public void setStreamCount(long stream_count) {
this.stream_count = stream_count;
} }
} }

View File

@ -29,30 +29,32 @@ public class ChannelInfoItemCollector extends InfoItemCollector {
} }
public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws ParsingException { public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws ParsingException {
ChannelInfoItem resultItem = new ChannelInfoItem();
// important information // important information
resultItem.service_id = getServiceId(); int serviceId = getServiceId();
resultItem.name = extractor.getName(); String name = extractor.getName();
resultItem.url = extractor.getUrl(); String url = extractor.getUrl();
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, name, url);
// optional information // optional information
try { try {
resultItem.subscriber_count = extractor.getSubscriberCount(); resultItem.setSubscriberCount(extractor.getSubscriberCount());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.stream_count = extractor.getStreamCount(); resultItem.setStreamCount(extractor.getStreamCount());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.thumbnail_url = extractor.getThumbnailUrl(); resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.description = extractor.getDescription(); resultItem.setDescription(extractor.getDescription());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }

View File

@ -22,14 +22,18 @@ package org.schabi.newpipe.extractor.kiosk;
import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
public class KioskInfo extends ListInfo { public class KioskInfo extends ListInfo {
public KioskInfo(int serviceId, String id, String url, String name) {
super(serviceId, id, url, name);
}
public static ListExtractor.NextItemsResult getMoreItems(ServiceList serviceItem, public static ListExtractor.NextItemsResult getMoreItems(ServiceList serviceItem,
String url, String url,
String nextStreamsUrl) throws IOException, ExtractionException { String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl); return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
} }
@ -63,20 +67,17 @@ public class KioskInfo extends ListInfo {
public static KioskInfo getInfo(KioskExtractor extractor, public static KioskInfo getInfo(KioskExtractor extractor,
String contentCountry) throws IOException, ExtractionException { String contentCountry) throws IOException, ExtractionException {
KioskInfo info = new KioskInfo();
extractor.setContentCountry(contentCountry); extractor.setContentCountry(contentCountry);
extractor.fetchPage(); extractor.fetchPage();
info.name = extractor.getName();
info.id = extractor.getId();
info.url = extractor.getCleanUrl();
try { int serviceId = extractor.getServiceId();
StreamInfoItemCollector c = extractor.getStreams(); String name = extractor.getName();
info.related_streams = c.getItemList(); String id = extractor.getId();
info.errors.addAll(c.getErrors()); String url = extractor.getCleanUrl();
} catch (Exception e) {
info.errors.add(e); KioskInfo info = new KioskInfo(serviceId, name, id, url);
}
info.related_streams = ExtractorHelper.getStreamsOrLogError(info, extractor);
return info; return info;
} }

View File

@ -1,19 +1,21 @@
package org.schabi.newpipe.extractor.playlist; package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult; import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService;
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.stream.StreamInfoItemCollector; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import static org.schabi.newpipe.extractor.utils.ExtractorHelper.getStreamsOrLogError;
public class PlaylistInfo extends ListInfo { public class PlaylistInfo extends ListInfo {
public PlaylistInfo(int serviceId, String id, String url, String name) {
super(serviceId, id, url, name);
}
public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException { public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl); return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
} }
@ -35,56 +37,47 @@ public class PlaylistInfo extends ListInfo {
} }
public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws ParsingException { public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws ParsingException {
PlaylistInfo info = new PlaylistInfo();
info.service_id = extractor.getServiceId(); int serviceId = extractor.getServiceId();
info.url = extractor.getCleanUrl(); String url = extractor.getCleanUrl();
info.id = extractor.getId(); String id = extractor.getId();
info.name = extractor.getName(); String name = extractor.getName();
PlaylistInfo info = new PlaylistInfo(serviceId, url, id, name);
try { try {
info.stream_count = extractor.getStreamCount(); info.setStreamCount(extractor.getStreamCount());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.thumbnail_url = extractor.getThumbnailUrl(); info.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.uploader_url = extractor.getUploaderUrl(); info.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.uploader_name = extractor.getUploaderName(); info.setUploaderName(extractor.getUploaderName());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.uploader_avatar_url = extractor.getUploaderAvatarUrl(); info.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
} }
try { try {
info.banner_url = extractor.getBannerUrl(); info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) { } catch (Exception e) {
info.errors.add(e); info.addError(e);
}
try {
StreamInfoItemCollector c = extractor.getStreams();
info.related_streams = c.getItemList();
info.errors.addAll(c.getErrors());
} catch (Exception e) {
info.errors.add(e);
} }
// Lists can be null if a exception was thrown during extraction info.setRelatedStreams(getStreamsOrLogError(info, extractor));
if (info.related_streams == null) info.related_streams = new ArrayList<>(); info.setHasMoreStreams(extractor.hasMoreStreams());
info.setNextStreamsUrl(extractor.getNextStreamsUrl());
info.has_more_streams = extractor.hasMoreStreams();
info.next_streams_url = extractor.getNextStreamsUrl();
return info; return info;
} }
@ -94,4 +87,52 @@ public class PlaylistInfo extends ListInfo {
public String uploader_name; public String uploader_name;
public String uploader_avatar_url; public String uploader_avatar_url;
public long stream_count = 0; public long stream_count = 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;
}
public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnail_url = thumbnailUrl;
}
public void setBannerUrl(String bannerUrl) {
this.banner_url = bannerUrl;
}
public void setUploaderUrl(String uploaderUrl) {
this.uploader_url = uploaderUrl;
}
public void setUploaderName(String uploaderName) {
this.uploader_name = uploaderName;
}
public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
this.uploader_avatar_url = uploaderAvatarUrl;
}
public void setStreamCount(long streamCount) {
this.stream_count = streamCount;
}
} }

View File

@ -10,7 +10,23 @@ public class PlaylistInfoItem extends InfoItem {
*/ */
public long stream_count = 0; public long stream_count = 0;
public PlaylistInfoItem() { public PlaylistInfoItem(int serviceId, String url, String name) {
super(InfoType.PLAYLIST); super(InfoType.PLAYLIST, serviceId, url, name);
}
public String getUploaderName() {
return uploader_name;
}
public void setUploaderName(String uploader_name) {
this.uploader_name = uploader_name;
}
public long getStreamCount() {
return stream_count;
}
public void setStreamCount(long stream_count) {
this.stream_count = stream_count;
} }
} }

View File

@ -9,24 +9,25 @@ public class PlaylistInfoItemCollector extends InfoItemCollector {
} }
public PlaylistInfoItem extract(PlaylistInfoItemExtractor extractor) throws ParsingException { public PlaylistInfoItem extract(PlaylistInfoItemExtractor extractor) throws ParsingException {
final PlaylistInfoItem resultItem = new PlaylistInfoItem();
resultItem.name = extractor.getName(); String name = extractor.getName();
resultItem.service_id = getServiceId(); int serviceId = getServiceId();
resultItem.url = extractor.getUrl(); String url = extractor.getUrl();
PlaylistInfoItem resultItem = new PlaylistInfoItem(serviceId, url, name);
try { try {
resultItem.uploader_name = extractor.getUploaderName(); resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.thumbnail_url = extractor.getThumbnailUrl(); resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.stream_count = extractor.getStreamCount(); resultItem.setStreamCount(extractor.getStreamCount());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }

View File

@ -4,6 +4,18 @@ import org.schabi.newpipe.extractor.InfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
public interface PlaylistInfoItemExtractor extends InfoItemExtractor { public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
/**
* Get the uploader name
* @return the uploader name
* @throws ParsingException
*/
String getUploaderName() throws ParsingException; String getUploaderName() throws ParsingException;
/**
* Get the number of streams
* @return the number of streams
* @throws ParsingException
*/
long getStreamCount() throws ParsingException; long getStreamCount() throws ParsingException;
} }

View File

@ -7,8 +7,8 @@ import java.util.List;
public abstract class Stream implements Serializable { public abstract class Stream implements Serializable {
private final MediaFormat mediaFormat; private final MediaFormat mediaFormat;
public String url; public final String url;
public int format = -1; public final int format;
public Stream(String url, MediaFormat format) { public Stream(String url, MediaFormat format) {
this.url = url; this.url = url;

View File

@ -4,9 +4,11 @@ import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.utils.DashMpdParser; import org.schabi.newpipe.extractor.utils.DashMpdParser;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/* /*
@ -35,6 +37,12 @@ import java.util.List;
@SuppressWarnings("WeakerAccess") @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 * Get the stream type
* @return the stream type * @return the stream type
@ -131,15 +139,88 @@ public class StreamInfo extends Info {
return start_position; return start_position;
} }
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 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 static class StreamExtractException extends ExtractionException { public static class StreamExtractException extends ExtractionException {
StreamExtractException(String message) { StreamExtractException(String message) {
super(message); super(message);
} }
} }
public StreamInfo() {
}
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);
} }
@ -157,10 +238,9 @@ public class StreamInfo extends Info {
* Probably needs to be overridden by subclasses * Probably needs to be overridden by subclasses
*/ */
public static StreamInfo getInfo(StreamExtractor extractor) throws ExtractionException { public static StreamInfo getInfo(StreamExtractor extractor) throws ExtractionException {
StreamInfo streamInfo = new StreamInfo(); StreamInfo streamInfo;
try { try {
streamInfo = extractImportantData(streamInfo, extractor); streamInfo = extractImportantData(extractor);
streamInfo = extractStreams(streamInfo, extractor); streamInfo = extractStreams(streamInfo, extractor);
streamInfo = extractOptionalData(streamInfo, extractor); streamInfo = extractOptionalData(streamInfo, extractor);
} catch (ExtractionException e) { } catch (ExtractionException e) {
@ -181,26 +261,26 @@ public class StreamInfo extends Info {
return streamInfo; return streamInfo;
} }
private static StreamInfo extractImportantData(StreamInfo streamInfo, StreamExtractor extractor) throws ExtractionException { private static StreamInfo extractImportantData(StreamExtractor extractor) throws ExtractionException {
/* ---- important data, without the video can't be displayed goes here: ---- */ /* ---- important data, without the video can't be displayed goes here: ---- */
// if one of these is not available an exception is meant to be thrown directly into the frontend. // if one of these is not available an exception is meant to be thrown directly into the frontend.
streamInfo.service_id = extractor.getServiceId(); int serviceId = extractor.getServiceId();
streamInfo.url = extractor.getCleanUrl(); String url = extractor.getCleanUrl();
streamInfo.stream_type = extractor.getStreamType(); StreamType streamType = extractor.getStreamType();
streamInfo.id = extractor.getId(); String id = extractor.getId();
streamInfo.name = extractor.getName(); String name = extractor.getName();
streamInfo.age_limit = extractor.getAgeLimit(); int ageLimit = extractor.getAgeLimit();
if ((streamInfo.stream_type == StreamType.NONE) if ((streamType == StreamType.NONE)
|| (streamInfo.url == null || streamInfo.url.isEmpty()) || (url == null || url.isEmpty())
|| (streamInfo.id == null || streamInfo.id.isEmpty()) || (id == null || id.isEmpty())
|| (streamInfo.name == null /* streamInfo.title can be empty of course */) || (name == null /* streamInfo.title can be empty of course */)
|| (streamInfo.age_limit == -1)) { || (ageLimit == -1)) {
throw new ExtractionException("Some important stream information was not given."); throw new ExtractionException("Some important stream information was not given.");
} }
return streamInfo; return new StreamInfo(serviceId, url, streamType, id, name, ageLimit);
} }
private static StreamInfo extractStreams(StreamInfo streamInfo, StreamExtractor extractor) throws ExtractionException { private static StreamInfo extractStreams(StreamInfo streamInfo, StreamExtractor extractor) throws ExtractionException {
@ -209,37 +289,37 @@ public class StreamInfo extends Info {
// otherwise an exception will be thrown directly into the frontend. // otherwise an exception will be thrown directly into the frontend.
try { try {
streamInfo.dashMpdUrl = extractor.getDashMpdUrl(); streamInfo.setDashMpdUrl(extractor.getDashMpdUrl());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(new ExtractionException("Couldn't get Dash manifest", e)); streamInfo.addError(new ExtractionException("Couldn't get Dash manifest", e));
} }
/* Load and extract audio */ /* Load and extract audio */
try { try {
streamInfo.audio_streams = extractor.getAudioStreams(); streamInfo.setAudioStreams(extractor.getAudioStreams());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(new ExtractionException("Couldn't get audio streams", e)); streamInfo.addError(new ExtractionException("Couldn't get audio streams", e));
} }
/* Extract video stream url*/ /* Extract video stream url*/
try { try {
streamInfo.video_streams = extractor.getVideoStreams(); streamInfo.setVideoStreams(extractor.getVideoStreams());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(new ExtractionException("Couldn't get video streams", e)); streamInfo.addError(new ExtractionException("Couldn't get video streams", e));
} }
/* Extract video only stream url*/ /* Extract video only stream url*/
try { try {
streamInfo.video_only_streams = extractor.getVideoOnlyStreams(); streamInfo.setVideoOnlyStreams(extractor.getVideoOnlyStreams());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(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 a exception was thrown during extraction // Lists can be null if a exception was thrown during extraction
if (streamInfo.video_streams == null) streamInfo.video_streams = new ArrayList<>(); if (streamInfo.getVideoStreams() == null) streamInfo.setVideoStreams(Collections.<VideoStream>emptyList());
if (streamInfo.video_only_streams == null) streamInfo.video_only_streams = new ArrayList<>(); if (streamInfo.getVideoOnlyStreams()== null) streamInfo.setVideoOnlyStreams(Collections.<VideoStream>emptyList());
if (streamInfo.audio_streams == null) streamInfo.audio_streams = new ArrayList<>(); if (streamInfo.getAudioStreams() == null) streamInfo.setAudioStreams(Collections.<AudioStream>emptyList());
Exception dashMpdError = null; Exception dashMpdError = null;
if (streamInfo.dashMpdUrl != null && !streamInfo.dashMpdUrl.isEmpty()) { if (streamInfo.getDashMpdUrl() != null && !streamInfo.getDashMpdUrl().isEmpty()) {
try { try {
DashMpdParser.getStreams(streamInfo); DashMpdParser.getStreams(streamInfo);
} catch (Exception e) { } catch (Exception e) {
@ -250,13 +330,13 @@ 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 == null || streamInfo.video_streams.isEmpty()) if ((streamInfo.video_streams.isEmpty())
&& (streamInfo.audio_streams == null || streamInfo.audio_streams.isEmpty())) { && (streamInfo.audio_streams.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
// (it's optional and it don't get added automatically, but it's good to have some additional error context) // (it's optional and it don't get added automatically, but it's good to have some additional error context)
streamInfo.addException(dashMpdError); streamInfo.addError(dashMpdError);
} }
throw new StreamExtractException("Could not get any stream. See error variable to get further details."); throw new StreamExtractException("Could not get any stream. See error variable to get further details.");
@ -272,82 +352,70 @@ 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.thumbnail_url = extractor.getThumbnailUrl(); streamInfo.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.duration = extractor.getLength(); streamInfo.setDuration(extractor.getLength());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.uploader_name = extractor.getUploaderName(); streamInfo.setUploaderName(extractor.getUploaderName());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.uploader_url = extractor.getUploaderUrl(); streamInfo.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.description = extractor.getDescription(); streamInfo.setDescription(extractor.getDescription());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.view_count = extractor.getViewCount(); streamInfo.setViewCount(extractor.getViewCount());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.upload_date = extractor.getUploadDate(); streamInfo.setUploadDate(extractor.getUploadDate());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.uploader_avatar_url = extractor.getUploaderAvatarUrl(); streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.start_position = extractor.getTimeStamp(); streamInfo.setStartPosition(extractor.getTimeStamp());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.like_count = extractor.getLikeCount(); streamInfo.setLikeCount(extractor.getLikeCount());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.dislike_count = extractor.getDislikeCount(); streamInfo.setDislikeCount(extractor.getDislikeCount());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
} }
try { try {
streamInfo.next_video = extractor.getNextVideo(); streamInfo.setNextVideo(extractor.getNextVideo());
} catch (Exception e) { } catch (Exception e) {
streamInfo.addException(e); streamInfo.addError(e);
}
try {
StreamInfoItemCollector c = extractor.getRelatedVideos();
streamInfo.related_streams = c.getItemList();
streamInfo.errors.addAll(c.getErrors());
} catch (Exception e) {
streamInfo.addException(e);
} }
if (streamInfo.related_streams == null) streamInfo.related_streams = new ArrayList<>(); streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
return streamInfo; return streamInfo;
} }
public void addException(Exception e) {
errors.add(e);
}
public StreamType stream_type; public StreamType stream_type;
public String thumbnail_url; public String thumbnail_url;
public String upload_date; public String upload_date;

View File

@ -26,7 +26,7 @@ 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 StreamType stream_type; public final StreamType stream_type;
public String uploader_name; public String uploader_name;
public String upload_date; public String upload_date;
@ -35,8 +35,9 @@ public class StreamInfoItem extends InfoItem {
private String uploaderUrl = null; private String uploaderUrl = null;
public StreamInfoItem() { public StreamInfoItem(int serviceId, String url, String name, StreamType streamType) {
super(InfoType.STREAM); super(InfoType.STREAM, serviceId, url, name);
this.stream_type = streamType;
} }
public void setUploaderUrl(String uploaderUrl) { public void setUploaderUrl(String uploaderUrl) {
@ -66,4 +67,20 @@ public class StreamInfoItem extends InfoItem {
public long getDuration() { public long getDuration() {
return duration; return duration;
} }
public void setDuration(long duration) {
this.duration = duration;
}
public void setUploaderName(String uploader_name) {
this.uploader_name = uploader_name;
}
public void setUploadDate(String upload_date) {
this.upload_date = upload_date;
}
public void setViewCount(long view_count) {
this.view_count = view_count;
}
} }

View File

@ -39,36 +39,38 @@ public class StreamInfoItemCollector extends InfoItemCollector {
throw new FoundAdException("Found ad"); throw new FoundAdException("Found ad");
} }
StreamInfoItem resultItem = new StreamInfoItem();
// important information // important information
resultItem.service_id = getServiceId(); int serviceId = getServiceId();
resultItem.url = extractor.getUrl(); String url = extractor.getUrl();
resultItem.name = extractor.getName(); String name = extractor.getName();
resultItem.stream_type = extractor.getStreamType(); StreamType streamType = extractor.getStreamType();
StreamInfoItem resultItem = new StreamInfoItem(serviceId, url, name, streamType);
// optional information // optional information
try { try {
resultItem.duration = extractor.getDuration(); resultItem.setDuration(extractor.getDuration());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.uploader_name = extractor.getUploaderName(); resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.upload_date = extractor.getUploadDate(); resultItem.setUploadDate(extractor.getUploadDate());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.view_count = extractor.getViewCount(); resultItem.setViewCount(extractor.getViewCount());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }
try { try {
resultItem.thumbnail_url = extractor.getThumbnailUrl(); resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) { } catch (Exception e) {
addError(e); addError(e);
} }

View File

@ -0,0 +1,53 @@
package org.schabi.newpipe.extractor.utils;
import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.InfoItemCollector;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import java.util.Collections;
import java.util.List;
public class ExtractorHelper {
private ExtractorHelper() {}
public static List<InfoItem> getStreamsOrLogError(Info info, ListExtractor extractor) {
StreamInfoItemCollector collector;
try {
collector = extractor.getStreams();
} catch (Exception e) {
info.addError(e);
return Collections.emptyList();
}
// Get from collector
return getInfoItems(info, collector);
}
public static List<InfoItem> getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) {
StreamInfoItemCollector collector;
try {
collector = extractor.getRelatedVideos();
} catch (Exception e) {
info.addError(e);
return Collections.emptyList();
}
// Get from collector
return getInfoItems(info, collector);
}
private static List<InfoItem> getInfoItems(Info info, InfoItemCollector collector) {
List<InfoItem> result;
try {
result = collector.getItemList();
info.addAllErrors(collector.getErrors());
} catch (Exception e) {
info.addError(e);
return Collections.emptyList();
}
return result;
}
}