From 690f241357242da2465ed2904f14d91a01d76c7d Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sun, 25 Feb 2018 13:03:32 -0800 Subject: [PATCH] -Added hls manifest url extraction. -Changed manifest url fields to nonnull. --- .../soundcloud/SoundcloudStreamExtractor.java | 9 ++++++- .../youtube/YoutubeStreamExtractor.java | 25 ++++++++++++++----- .../extractor/stream/StreamExtractor.java | 3 ++- .../newpipe/extractor/stream/StreamInfo.java | 15 +++++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java index 28353c97..6a14f3b1 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java @@ -116,9 +116,16 @@ public class SoundcloudStreamExtractor extends StreamExtractor { return SoundcloudParsingHelper.getAvatarUrl(track); } + @Nonnull @Override public String getDashMpdUrl() { - return null; + return ""; + } + + @Nonnull + @Override + public String getHlsUrl() throws ParsingException { + return ""; } @Override diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index cb8e1ca9..38b94bdc 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -66,12 +66,6 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } - public class LiveStreamException extends ContentNotAvailableException { - LiveStreamException(String message) { - super(message); - } - } - public class SubtitlesException extends ContentNotAvailableException { SubtitlesException(String message, Throwable cause) { super(message, cause); @@ -338,6 +332,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nonnull @Override public String getDashMpdUrl() throws ParsingException { assertPageFetched(); @@ -365,6 +360,24 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } + @Nonnull + @Override + public String getHlsUrl() throws ParsingException { + assertPageFetched(); + try { + String hlsvp; + if (playerArgs != null && playerArgs.isString("hlsvp")) { + hlsvp = playerArgs.getString("hlsvp", ""); + } else { + return ""; + } + + return hlsvp; + } catch (Exception e) { + throw new ParsingException("Could not get hls manifest url", e); + } + } + @Override public List getAudioStreams() throws IOException, ExtractionException { assertPageFetched(); diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index 05317fb6..b54874af 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -126,7 +126,8 @@ public abstract class StreamExtractor extends Extractor { * @return the url as a string or an empty string * @throws ParsingException if an error occurs while reading */ - public abstract String getDashMpdUrl() throws ParsingException; + @Nonnull public abstract String getDashMpdUrl() throws ParsingException; + @Nonnull public abstract String getHlsUrl() throws ParsingException; public abstract List getAudioStreams() throws IOException, ExtractionException; public abstract List getVideoStreams() throws IOException, ExtractionException; public abstract List getVideoOnlyStreams() throws IOException, ExtractionException; 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 9119cc21..ffa3028b 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -126,6 +126,10 @@ public class StreamInfo extends Info { return dashMpdUrl; } + public String getHlsUrl() { + return hlsUrl; + } + public StreamInfoItem getNextVideo() { return next_video; } @@ -206,6 +210,10 @@ public class StreamInfo extends Info { this.dashMpdUrl = dashMpdUrl; } + public void setHlsUrl(String hlsUrl) { + this.hlsUrl = hlsUrl; + } + public void setNextVideo(StreamInfoItem next_video) { this.next_video = next_video; } @@ -298,6 +306,12 @@ public class StreamInfo extends Info { streamInfo.addError(new ExtractionException("Couldn't get Dash manifest", e)); } + try { + streamInfo.setHlsUrl(extractor.getHlsUrl()); + } catch (Exception e) { + streamInfo.addError(new ExtractionException("Couldn't get HLS manifest", e)); + } + /* Load and extract audio */ try { streamInfo.setAudioStreams(extractor.getAudioStreams()); @@ -447,6 +461,7 @@ public class StreamInfo extends Info { // 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; public List related_streams;