From 26e11f96e025189cc639158aec9be6a555899f57 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 4 Mar 2016 15:18:04 +0100 Subject: [PATCH] add streamtype field --- .../newpipe/extractor/StreamExtractor.java | 1 + .../schabi/newpipe/extractor/StreamInfo.java | 87 ++++++++++--------- .../youtube/YoutubeStreamExtractor.java | 9 +- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java index 8c5873cfc..a3aed0363 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamExtractor.java @@ -76,6 +76,7 @@ public abstract class StreamExtractor { public abstract List getRelatedVideos() throws ParsingException; public abstract StreamUrlIdHandler getUrlIdConverter(); public abstract String getPageUrl(); + public abstract StreamInfo.StreamType getStreamType() throws ParsingException; public int getServiceId() { return serviceId; } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java b/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java index 963aa8298..baf513187 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/StreamInfo.java @@ -34,6 +34,38 @@ public class StreamInfo extends AbstractVideoInfo { } } + public StreamInfo() {} + + /**Creates a new StreamInfo object from an existing AbstractVideoInfo. + * All the shared properties are copied to the new StreamInfo.*/ + @SuppressWarnings("WeakerAccess") + public StreamInfo(AbstractVideoInfo avi) { + this.id = avi.id; + this.title = avi.title; + this.uploader = avi.uploader; + this.thumbnail_url = avi.thumbnail_url; + this.thumbnail = avi.thumbnail; + this.webpage_url = avi.webpage_url; + this.upload_date = avi.upload_date; + this.upload_date = avi.upload_date; + this.view_count = avi.view_count; + + //todo: better than this + if(avi instanceof StreamPreviewInfo) { + //shitty String to convert code + /* + String dur = ((StreamPreviewInfo)avi).duration; + int minutes = Integer.parseInt(dur.substring(0, dur.indexOf(":"))); + int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length())); + */ + this.duration = ((StreamPreviewInfo)avi).duration; + } + } + + public void addException(Exception e) { + errors.add(e); + } + /**Fills out the video info fields which are common to all services. * Probably needs to be overridden by subclasses*/ public static StreamInfo getVideoInfo(StreamExtractor extractor, Downloader downloader) @@ -57,14 +89,18 @@ public class StreamInfo extends AbstractVideoInfo { streamInfo.service_id = extractor.getServiceId(); streamInfo.webpage_url = extractor.getPageUrl(); + streamInfo.stream_type = extractor.getStreamType(); streamInfo.id = uiconv.getVideoId(extractor.getPageUrl()); streamInfo.title = extractor.getTitle(); streamInfo.age_limit = extractor.getAgeLimit(); - if((streamInfo.webpage_url == null || streamInfo.webpage_url.isEmpty()) + if((streamInfo.stream_type == StreamType.NONE) + || (streamInfo.webpage_url == null || streamInfo.webpage_url.isEmpty()) || (streamInfo.id == null || streamInfo.id.isEmpty()) || (streamInfo.title == null /* streamInfo.title can be empty of course */) - || (streamInfo.age_limit == -1)); + || (streamInfo.age_limit == -1)) { + throw new ExtractionException("Some importand stream information was not given."); + } return streamInfo; } @@ -202,15 +238,20 @@ public class StreamInfo extends AbstractVideoInfo { } catch(Exception e) { streamInfo.addException(e); } - try { - - } catch (Exception e) { - streamInfo.addException(e); - } return streamInfo; } + public static enum StreamType { + NONE, // placeholder to check if stream type was checked or not + VIDEO_STREAM, + AUDIO_STREAM, + LIVE_STREAM, + AUDIO_LIVE_STREAM, + FILE + } + + public StreamType stream_type; public String uploader_thumbnail_url = ""; public String description = ""; @@ -234,36 +275,4 @@ public class StreamInfo extends AbstractVideoInfo { public int start_position = 0; public List errors = new Vector<>(); - - public StreamInfo() {} - - public void addException(Exception e) { - errors.add(e); - } - - /**Creates a new StreamInfo object from an existing AbstractVideoInfo. - * All the shared properties are copied to the new StreamInfo.*/ - @SuppressWarnings("WeakerAccess") - public StreamInfo(AbstractVideoInfo avi) { - this.id = avi.id; - this.title = avi.title; - this.uploader = avi.uploader; - this.thumbnail_url = avi.thumbnail_url; - this.thumbnail = avi.thumbnail; - this.webpage_url = avi.webpage_url; - this.upload_date = avi.upload_date; - this.upload_date = avi.upload_date; - this.view_count = avi.view_count; - - //todo: better than this - if(avi instanceof StreamPreviewInfo) { - //shitty String to convert code - /* - String dur = ((StreamPreviewInfo)avi).duration; - int minutes = Integer.parseInt(dur.substring(0, dur.indexOf(":"))); - int seconds = Integer.parseInt(dur.substring(dur.indexOf(":")+1, dur.length())); - */ - this.duration = ((StreamPreviewInfo)avi).duration; - } - } } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 8ec716d2d..56f30a554 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.ExtractionException; import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Parser; import org.schabi.newpipe.extractor.ParsingException; +import org.schabi.newpipe.extractor.StreamInfo; import org.schabi.newpipe.extractor.StreamPreviewInfo; import org.schabi.newpipe.extractor.StreamUrlIdHandler; import org.schabi.newpipe.extractor.StreamExtractor; @@ -510,7 +511,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } catch (Exception e) { //todo: dont log throw an error - System.err.println( "Could not get Video stream."); + System.err.println("Could not get Video stream."); e.printStackTrace(); } } @@ -672,6 +673,12 @@ public class YoutubeStreamExtractor extends StreamExtractor { return pageUrl; } + @Override + public StreamInfo.StreamType getStreamType() throws ParsingException { + //todo: if implementing livestream support this value should be generated dynamically + return StreamInfo.StreamType.VIDEO_STREAM; + } + /**Provides information about links to other videos on the video page, such as related videos. * This is encapsulated in a StreamPreviewInfo object, * which is a subset of the fields in a full StreamInfo.*/