diff --git a/src/main/java/org/schabi/newpipe/extractor/Info.java b/src/main/java/org/schabi/newpipe/extractor/Info.java
index 74a906d10..c704717e6 100644
--- a/src/main/java/org/schabi/newpipe/extractor/Info.java
+++ b/src/main/java/org/schabi/newpipe/extractor/Info.java
@@ -2,23 +2,60 @@ package org.schabi.newpipe.extractor;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
public abstract class Info implements Serializable {
- public int service_id = -1;
+ public final int service_id;
/**
* Id of this Info object
* e.g. Youtube: https://www.youtube.com/watch?v=RER5qCTzZ7 > RER5qCTzZ7
*/
- public String id;
- public String url;
- public String name;
+ public final String id;
+ public final String url;
+ public final String name;
public List errors = new ArrayList<>();
+ public void addError(Throwable throwable) {
+ this.errors.add(throwable);
+ }
+
+ public void addAllErrors(Collection 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
public String toString() {
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 getErrors() {
+ return errors;
+ }
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/InfoItem.java b/src/main/java/org/schabi/newpipe/extractor/InfoItem.java
index 85048297e..f0c36f244 100644
--- a/src/main/java/org/schabi/newpipe/extractor/InfoItem.java
+++ b/src/main/java/org/schabi/newpipe/extractor/InfoItem.java
@@ -20,6 +20,8 @@ package org.schabi.newpipe.extractor;
* along with NewPipe. If not, see .
*/
+import org.schabi.newpipe.extractor.stream.StreamType;
+
import java.io.Serializable;
public abstract class InfoItem implements Serializable {
@@ -29,8 +31,11 @@ public abstract class InfoItem implements Serializable {
public String name;
public String thumbnail_url;
- public InfoItem(InfoType infoType) {
+ public InfoItem(InfoType infoType, int serviceId, String url, String name) {
this.info_type = infoType;
+ this.service_id = serviceId;
+ this.url = url;
+ this.name = name;
}
public InfoType getInfoType() {
@@ -49,6 +54,10 @@ public abstract class InfoItem implements Serializable {
return name;
}
+ public void setThumbnailUrl(String thumbnailUrl) {
+ this.thumbnail_url = thumbnailUrl;
+ }
+
public String getThumbnailUrl() {
return thumbnail_url;
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/ListInfo.java b/src/main/java/org/schabi/newpipe/extractor/ListInfo.java
index d625c14e8..c4f9a5375 100644
--- a/src/main/java/org/schabi/newpipe/extractor/ListInfo.java
+++ b/src/main/java/org/schabi/newpipe/extractor/ListInfo.java
@@ -6,4 +6,32 @@ public abstract class ListInfo extends Info {
public List related_streams;
public boolean has_more_streams;
public String next_streams_url;
+
+ public ListInfo(int serviceId, String id, String url, String name) {
+ super(serviceId, id, url, name);
+ }
+
+ public List getRelated_streams() {
+ return related_streams;
+ }
+
+ public void setRelatedStreams(List 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;
+ }
}
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 d48e6658d..9d30c9829 100644
--- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java
+++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java
@@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
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.util.ArrayList;
@@ -34,6 +35,11 @@ import java.util.ArrayList;
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 {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
}
@@ -55,52 +61,47 @@ public class ChannelInfo extends ListInfo {
}
public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException {
- ChannelInfo info = new ChannelInfo();
// important data
- info.service_id = extractor.getServiceId();
- info.url = extractor.getCleanUrl();
- info.id = extractor.getId();
- info.name = extractor.getName();
+ int serviceId = extractor.getServiceId();
+ String url = extractor.getCleanUrl();
+ String id = extractor.getId();
+ String name = extractor.getName();
+
+ ChannelInfo info = new ChannelInfo(serviceId, url, id, name);
+
try {
- info.avatar_url = extractor.getAvatarUrl();
+ info.setAvatarUrl(extractor.getAvatarUrl());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.banner_url = extractor.getBannerUrl();
+ info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.feed_url = extractor.getFeedUrl();
+ info.setFeedUrl(extractor.getFeedUrl());
} catch (Exception e) {
- info.errors.add(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);
+ info.addError(e);
}
- // Lists can be null if a exception was thrown during extraction
- if (info.related_streams == null) info.related_streams = new ArrayList<>();
+ info.setRelatedStreams(ExtractorHelper.getStreamsOrLogError(info, extractor));
- info.has_more_streams = extractor.hasMoreStreams();
- info.next_streams_url = extractor.getNextStreamsUrl();
+ try {
+ 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;
}
@@ -109,4 +110,44 @@ public class ChannelInfo extends ListInfo {
public String feed_url;
public long subscriber_count = -1;
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;
+ }
}
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 356c847f1..cd6d37071 100644
--- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItem.java
+++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItem.java
@@ -28,7 +28,32 @@ public class ChannelInfoItem extends InfoItem {
public long subscriber_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;
}
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemCollector.java b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemCollector.java
index 3bbe42f6f..547602317 100644
--- a/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemCollector.java
+++ b/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemCollector.java
@@ -29,30 +29,32 @@ public class ChannelInfoItemCollector extends InfoItemCollector {
}
public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws ParsingException {
- ChannelInfoItem resultItem = new ChannelInfoItem();
// important information
- resultItem.service_id = getServiceId();
- resultItem.name = extractor.getName();
- resultItem.url = extractor.getUrl();
+ int serviceId = getServiceId();
+ String name = extractor.getName();
+ String url = extractor.getUrl();
+
+ ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, name, url);
+
// optional information
try {
- resultItem.subscriber_count = extractor.getSubscriberCount();
+ resultItem.setSubscriberCount(extractor.getSubscriberCount());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.stream_count = extractor.getStreamCount();
+ resultItem.setStreamCount(extractor.getStreamCount());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.thumbnail_url = extractor.getThumbnailUrl();
+ resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.description = extractor.getDescription();
+ resultItem.setDescription(extractor.getDescription());
} catch (Exception e) {
addError(e);
}
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 8b82f9eca..0c5064dc1 100644
--- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java
+++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java
@@ -22,14 +22,18 @@ package org.schabi.newpipe.extractor.kiosk;
import org.schabi.newpipe.extractor.*;
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;
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,
- String url,
+ String url,
String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
}
@@ -63,20 +67,17 @@ public class KioskInfo extends ListInfo {
public static KioskInfo getInfo(KioskExtractor extractor,
String contentCountry) throws IOException, ExtractionException {
- KioskInfo info = new KioskInfo();
extractor.setContentCountry(contentCountry);
extractor.fetchPage();
- info.name = extractor.getName();
- info.id = extractor.getId();
- info.url = extractor.getCleanUrl();
- try {
- StreamInfoItemCollector c = extractor.getStreams();
- info.related_streams = c.getItemList();
- info.errors.addAll(c.getErrors());
- } catch (Exception e) {
- info.errors.add(e);
- }
+ int serviceId = extractor.getServiceId();
+ String name = extractor.getName();
+ String id = extractor.getId();
+ String url = extractor.getCleanUrl();
+
+ KioskInfo info = new KioskInfo(serviceId, name, id, url);
+
+ info.related_streams = ExtractorHelper.getStreamsOrLogError(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 ab6ddc5ae..f8f2a2114 100644
--- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java
+++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java
@@ -1,19 +1,21 @@
package org.schabi.newpipe.extractor.playlist;
+import org.schabi.newpipe.extractor.*;
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.ParsingException;
-import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
+import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException;
-import java.util.ArrayList;
+
+import static org.schabi.newpipe.extractor.utils.ExtractorHelper.getStreamsOrLogError;
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 {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
}
@@ -35,56 +37,47 @@ public class PlaylistInfo extends ListInfo {
}
public static PlaylistInfo getInfo(PlaylistExtractor extractor) throws ParsingException {
- PlaylistInfo info = new PlaylistInfo();
- info.service_id = extractor.getServiceId();
- info.url = extractor.getCleanUrl();
- info.id = extractor.getId();
- info.name = extractor.getName();
+ int serviceId = extractor.getServiceId();
+ String url = extractor.getCleanUrl();
+ String id = extractor.getId();
+ String name = extractor.getName();
+ PlaylistInfo info = new PlaylistInfo(serviceId, url, id, name);
try {
- info.stream_count = extractor.getStreamCount();
+ info.setStreamCount(extractor.getStreamCount());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.thumbnail_url = extractor.getThumbnailUrl();
+ info.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.uploader_url = extractor.getUploaderUrl();
+ info.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.uploader_name = extractor.getUploaderName();
+ info.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.uploader_avatar_url = extractor.getUploaderAvatarUrl();
+ info.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
try {
- info.banner_url = extractor.getBannerUrl();
+ info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) {
- info.errors.add(e);
- }
- try {
- StreamInfoItemCollector c = extractor.getStreams();
- info.related_streams = c.getItemList();
- info.errors.addAll(c.getErrors());
- } catch (Exception e) {
- info.errors.add(e);
+ info.addError(e);
}
- // Lists can be null if a exception was thrown during extraction
- if (info.related_streams == null) info.related_streams = new ArrayList<>();
-
- info.has_more_streams = extractor.hasMoreStreams();
- info.next_streams_url = extractor.getNextStreamsUrl();
+ info.setRelatedStreams(getStreamsOrLogError(info, extractor));
+ info.setHasMoreStreams(extractor.hasMoreStreams());
+ info.setNextStreamsUrl(extractor.getNextStreamsUrl());
return info;
}
@@ -94,4 +87,52 @@ public class PlaylistInfo extends ListInfo {
public String uploader_name;
public String uploader_avatar_url;
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;
+ }
}
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 ef8f07512..62a440bdf 100644
--- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java
+++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java
@@ -10,7 +10,23 @@ public class PlaylistInfoItem extends InfoItem {
*/
public long stream_count = 0;
- public PlaylistInfoItem() {
- super(InfoType.PLAYLIST);
+ public PlaylistInfoItem(int serviceId, String url, String name) {
+ 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;
}
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemCollector.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemCollector.java
index 61fb5ec1e..18ae40d4d 100644
--- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemCollector.java
+++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemCollector.java
@@ -9,24 +9,25 @@ public class PlaylistInfoItemCollector extends InfoItemCollector {
}
public PlaylistInfoItem extract(PlaylistInfoItemExtractor extractor) throws ParsingException {
- final PlaylistInfoItem resultItem = new PlaylistInfoItem();
- resultItem.name = extractor.getName();
- resultItem.service_id = getServiceId();
- resultItem.url = extractor.getUrl();
+ String name = extractor.getName();
+ int serviceId = getServiceId();
+ String url = extractor.getUrl();
+
+ PlaylistInfoItem resultItem = new PlaylistInfoItem(serviceId, url, name);
try {
- resultItem.uploader_name = extractor.getUploaderName();
+ resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.thumbnail_url = extractor.getThumbnailUrl();
+ resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.stream_count = extractor.getStreamCount();
+ resultItem.setStreamCount(extractor.getStreamCount());
} catch (Exception e) {
addError(e);
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java
index 9593d1547..fe75cf20c 100644
--- a/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java
+++ b/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java
@@ -4,6 +4,18 @@ import org.schabi.newpipe.extractor.InfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
+
+ /**
+ * Get the uploader name
+ * @return the uploader name
+ * @throws ParsingException
+ */
String getUploaderName() throws ParsingException;
+
+ /**
+ * Get the number of streams
+ * @return the number of streams
+ * @throws ParsingException
+ */
long getStreamCount() throws ParsingException;
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/Stream.java b/src/main/java/org/schabi/newpipe/extractor/stream/Stream.java
index 5e17f03c9..9baebb69a 100644
--- a/src/main/java/org/schabi/newpipe/extractor/stream/Stream.java
+++ b/src/main/java/org/schabi/newpipe/extractor/stream/Stream.java
@@ -7,8 +7,8 @@ import java.util.List;
public abstract class Stream implements Serializable {
private final MediaFormat mediaFormat;
- public String url;
- public int format = -1;
+ public final String url;
+ public final int format;
public Stream(String url, MediaFormat format) {
this.url = url;
diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java
index d9cba90f6..1ede39cfe 100644
--- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java
+++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java
@@ -4,9 +4,11 @@ import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.utils.DashMpdParser;
+import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/*
@@ -35,6 +37,12 @@ import java.util.List;
@SuppressWarnings("WeakerAccess")
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
@@ -131,15 +139,88 @@ public class StreamInfo extends Info {
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 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 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 static class StreamExtractException extends ExtractionException {
StreamExtractException(String message) {
super(message);
}
}
- public StreamInfo() {
- }
-
public static StreamInfo getInfo(String url) throws IOException, ExtractionException {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
@@ -157,10 +238,9 @@ public class StreamInfo extends Info {
* Probably needs to be overridden by subclasses
*/
public static StreamInfo getInfo(StreamExtractor extractor) throws ExtractionException {
- StreamInfo streamInfo = new StreamInfo();
-
+ StreamInfo streamInfo;
try {
- streamInfo = extractImportantData(streamInfo, extractor);
+ streamInfo = extractImportantData(extractor);
streamInfo = extractStreams(streamInfo, extractor);
streamInfo = extractOptionalData(streamInfo, extractor);
} catch (ExtractionException e) {
@@ -181,26 +261,26 @@ public class StreamInfo extends Info {
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: ---- */
// if one of these is not available an exception is meant to be thrown directly into the frontend.
- streamInfo.service_id = extractor.getServiceId();
- streamInfo.url = extractor.getCleanUrl();
- streamInfo.stream_type = extractor.getStreamType();
- streamInfo.id = extractor.getId();
- streamInfo.name = extractor.getName();
- streamInfo.age_limit = extractor.getAgeLimit();
+ int serviceId = extractor.getServiceId();
+ String url = extractor.getCleanUrl();
+ StreamType streamType = extractor.getStreamType();
+ String id = extractor.getId();
+ String name = extractor.getName();
+ int ageLimit = extractor.getAgeLimit();
- if ((streamInfo.stream_type == StreamType.NONE)
- || (streamInfo.url == null || streamInfo.url.isEmpty())
- || (streamInfo.id == null || streamInfo.id.isEmpty())
- || (streamInfo.name == null /* streamInfo.title can be empty of course */)
- || (streamInfo.age_limit == -1)) {
+ if ((streamType == StreamType.NONE)
+ || (url == null || url.isEmpty())
+ || (id == null || id.isEmpty())
+ || (name == null /* streamInfo.title can be empty of course */)
+ || (ageLimit == -1)) {
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 {
@@ -209,37 +289,37 @@ public class StreamInfo extends Info {
// otherwise an exception will be thrown directly into the frontend.
try {
- streamInfo.dashMpdUrl = extractor.getDashMpdUrl();
+ streamInfo.setDashMpdUrl(extractor.getDashMpdUrl());
} 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 */
try {
- streamInfo.audio_streams = extractor.getAudioStreams();
+ streamInfo.setAudioStreams(extractor.getAudioStreams());
} 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*/
try {
- streamInfo.video_streams = extractor.getVideoStreams();
+ streamInfo.setVideoStreams(extractor.getVideoStreams());
} 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*/
try {
- streamInfo.video_only_streams = extractor.getVideoOnlyStreams();
+ streamInfo.setVideoOnlyStreams(extractor.getVideoOnlyStreams());
} 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
- if (streamInfo.video_streams == null) streamInfo.video_streams = new ArrayList<>();
- if (streamInfo.video_only_streams == null) streamInfo.video_only_streams = new ArrayList<>();
- if (streamInfo.audio_streams == null) streamInfo.audio_streams = new ArrayList<>();
+ if (streamInfo.getVideoStreams() == null) streamInfo.setVideoStreams(Collections.emptyList());
+ if (streamInfo.getVideoOnlyStreams()== null) streamInfo.setVideoOnlyStreams(Collections.emptyList());
+ if (streamInfo.getAudioStreams() == null) streamInfo.setAudioStreams(Collections.emptyList());
Exception dashMpdError = null;
- if (streamInfo.dashMpdUrl != null && !streamInfo.dashMpdUrl.isEmpty()) {
+ if (streamInfo.getDashMpdUrl() != null && !streamInfo.getDashMpdUrl().isEmpty()) {
try {
DashMpdParser.getStreams(streamInfo);
} 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).
- if ((streamInfo.video_streams == null || streamInfo.video_streams.isEmpty())
- && (streamInfo.audio_streams == null || streamInfo.audio_streams.isEmpty())) {
+ if ((streamInfo.video_streams.isEmpty())
+ && (streamInfo.audio_streams.isEmpty())) {
if (dashMpdError != null) {
// 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)
- streamInfo.addException(dashMpdError);
+ streamInfo.addError(dashMpdError);
}
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.
try {
- streamInfo.thumbnail_url = extractor.getThumbnailUrl();
+ streamInfo.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.duration = extractor.getLength();
+ streamInfo.setDuration(extractor.getLength());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.uploader_name = extractor.getUploaderName();
+ streamInfo.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.uploader_url = extractor.getUploaderUrl();
+ streamInfo.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.description = extractor.getDescription();
+ streamInfo.setDescription(extractor.getDescription());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.view_count = extractor.getViewCount();
+ streamInfo.setViewCount(extractor.getViewCount());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.upload_date = extractor.getUploadDate();
+ streamInfo.setUploadDate(extractor.getUploadDate());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.uploader_avatar_url = extractor.getUploaderAvatarUrl();
+ streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.start_position = extractor.getTimeStamp();
+ streamInfo.setStartPosition(extractor.getTimeStamp());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.like_count = extractor.getLikeCount();
+ streamInfo.setLikeCount(extractor.getLikeCount());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.dislike_count = extractor.getDislikeCount();
+ streamInfo.setDislikeCount(extractor.getDislikeCount());
} catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
try {
- streamInfo.next_video = extractor.getNextVideo();
+ streamInfo.setNextVideo(extractor.getNextVideo());
} catch (Exception e) {
- streamInfo.addException(e);
- }
- try {
- StreamInfoItemCollector c = extractor.getRelatedVideos();
- streamInfo.related_streams = c.getItemList();
- streamInfo.errors.addAll(c.getErrors());
- } catch (Exception e) {
- streamInfo.addException(e);
+ streamInfo.addError(e);
}
- if (streamInfo.related_streams == null) streamInfo.related_streams = new ArrayList<>();
-
+ streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
return streamInfo;
}
- public void addException(Exception e) {
- errors.add(e);
- }
-
public StreamType stream_type;
public String thumbnail_url;
public String upload_date;
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 58008d9e9..03525c8bf 100644
--- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java
+++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java
@@ -26,7 +26,7 @@ import org.schabi.newpipe.extractor.InfoItem;
* Info object for previews of unopened videos, eg search results, related videos
*/
public class StreamInfoItem extends InfoItem {
- public StreamType stream_type;
+ public final StreamType stream_type;
public String uploader_name;
public String upload_date;
@@ -35,8 +35,9 @@ public class StreamInfoItem extends InfoItem {
private String uploaderUrl = null;
- public StreamInfoItem() {
- super(InfoType.STREAM);
+ 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) {
@@ -66,4 +67,20 @@ public class StreamInfoItem extends InfoItem {
public long getDuration() {
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;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemCollector.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemCollector.java
index 1a26df4d1..cbc585d68 100644
--- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemCollector.java
+++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemCollector.java
@@ -39,36 +39,38 @@ public class StreamInfoItemCollector extends InfoItemCollector {
throw new FoundAdException("Found ad");
}
- StreamInfoItem resultItem = new StreamInfoItem();
// important information
- resultItem.service_id = getServiceId();
- resultItem.url = extractor.getUrl();
- resultItem.name = extractor.getName();
- resultItem.stream_type = extractor.getStreamType();
+ int serviceId = getServiceId();
+ String url = extractor.getUrl();
+ String name = extractor.getName();
+ StreamType streamType = extractor.getStreamType();
+
+ StreamInfoItem resultItem = new StreamInfoItem(serviceId, url, name, streamType);
+
// optional information
try {
- resultItem.duration = extractor.getDuration();
+ resultItem.setDuration(extractor.getDuration());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.uploader_name = extractor.getUploaderName();
+ resultItem.setUploaderName(extractor.getUploaderName());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.upload_date = extractor.getUploadDate();
+ resultItem.setUploadDate(extractor.getUploadDate());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.view_count = extractor.getViewCount();
+ resultItem.setViewCount(extractor.getViewCount());
} catch (Exception e) {
addError(e);
}
try {
- resultItem.thumbnail_url = extractor.getThumbnailUrl();
+ resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
} catch (Exception e) {
addError(e);
}
diff --git a/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java b/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java
new file mode 100644
index 000000000..86046b689
--- /dev/null
+++ b/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java
@@ -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 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 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 getInfoItems(Info info, InfoItemCollector collector) {
+ List result;
+ try {
+ result = collector.getItemList();
+ info.addAllErrors(collector.getErrors());
+ } catch (Exception e) {
+ info.addError(e);
+ return Collections.emptyList();
+ }
+ return result;
+ }
+}