From 11eb4932f4eb52bd2e88c5e8d63c76f54ecd912a Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 11 Feb 2021 14:40:38 +0530 Subject: [PATCH] Add data to respective classes. --- .../extractors/YoutubeStreamExtractor.java | 16 +++--- .../newpipe/extractor/stream/AudioStream.java | 49 +++++++++++++++++ .../newpipe/extractor/stream/VideoStream.java | 55 +++++++++++++++++++ 3 files changed, 112 insertions(+), 8 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index d47105ac..964fd7cf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -502,7 +502,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { for (Map.Entry entry : getItags(ADAPTIVE_FORMATS, ItagItem.ItagType.AUDIO).entrySet()) { ItagItem itag = entry.getValue(); - AudioStream audioStream = new AudioStream(entry.getKey(), itag.getMediaFormat(), itag.avgBitrate); + AudioStream audioStream = new AudioStream(entry.getKey(), itag.getMediaFormat(), itag.avgBitrate, itag.bitrate, itag.initStart, itag.initEnd, itag.indexStart, itag.indexEnd, itag.codec); if (!Stream.containSimilarStream(audioStream, audioStreams)) { audioStreams.add(audioStream); } @@ -542,7 +542,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { for (Map.Entry entry : getItags(ADAPTIVE_FORMATS, ItagItem.ItagType.VIDEO_ONLY).entrySet()) { ItagItem itag = entry.getValue(); - VideoStream videoStream = new VideoStream(entry.getKey(), itag.getMediaFormat(), itag.resolutionString, true); + VideoStream videoStream = new VideoStream(entry.getKey(), itag.getMediaFormat(), itag.resolutionString, true, itag.bitrate, itag.initStart, itag.initEnd, itag.indexStart, itag.indexEnd, itag.codec, itag.width, itag.height); if (!Stream.containSimilarStream(videoStream, videoOnlyStreams)) { videoOnlyStreams.add(videoStream); } @@ -950,19 +950,19 @@ public class YoutubeStreamExtractor extends StreamExtractor { } int bitrate = formatData.getInt("bitrate"); - int averageBitrate = formatData.getInt("averageBitrate"); int width = formatData.getInt("width"); int height = formatData.getInt("height"); - int initStart = formatData.getInt("initRange.start"); - int initEnd = formatData.getInt("initRange.end"); - int indexStart = formatData.getInt("indexRange.start"); - int indexEnd = formatData.getInt("indexRange.end"); + JsonObject initRange = formatData.getObject("initRange"); + JsonObject indexRange = formatData.getObject("indexRange"); + int initStart = Integer.parseInt(initRange.getString("start")); + int initEnd = Integer.parseInt(initRange.getString("end")); + int indexStart = Integer.parseInt(indexRange.getString("start")); + int indexEnd = Integer.parseInt(indexRange.getString("end")); int fps = formatData.getInt("fps"); String mimeType = formatData.getString("mimeType", EMPTY_STRING); String codec = mimeType.contains("codecs") ? mimeType.split("\"")[1] : EMPTY_STRING; itagItem.bitrate = bitrate; - itagItem.avgBitrate =averageBitrate; itagItem.width = width; itagItem.height = height; itagItem.initStart = initStart; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/AudioStream.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/AudioStream.java index 98fc9942..3229cf21 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/AudioStream.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/AudioStream.java @@ -25,6 +25,14 @@ import org.schabi.newpipe.extractor.MediaFormat; public class AudioStream extends Stream { public int average_bitrate = -1; + // Fields for Dash + public int bitrate; + public int initStart; + public int initEnd; + public int indexStart; + public int indexEnd; + public String codec; + /** * Create a new audio stream * @param url the url @@ -36,6 +44,23 @@ public class AudioStream extends Stream { this.average_bitrate = averageBitrate; } + /** + * Create a new audio stream + * @param url the url + * @param format the format + * @param averageBitrate the average bitrate + */ + public AudioStream(String url, MediaFormat format, int averageBitrate, int bitrate, int initStart, int initEnd, int indexStart, int indexEnd, String codec) { + super(url, format); + this.average_bitrate = averageBitrate; + this.bitrate = bitrate; + this.initStart = initStart; + this.initEnd = initEnd; + this.indexStart = indexStart; + this.indexEnd = indexEnd; + this.codec = codec; + } + @Override public boolean equalStats(Stream cmp) { return super.equalStats(cmp) && cmp instanceof AudioStream && @@ -49,4 +74,28 @@ public class AudioStream extends Stream { public int getAverageBitrate() { return average_bitrate; } + + public int getBitrate() { + return bitrate; + } + + public int getInitStart() { + return initStart; + } + + public int getInitEnd() { + return initEnd; + } + + public int getIndexStart() { + return indexStart; + } + + public int getIndexEnd() { + return indexEnd; + } + + public String getCodec() { + return codec; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/VideoStream.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/VideoStream.java index 67219240..66a22912 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/VideoStream.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/VideoStream.java @@ -26,6 +26,15 @@ public class VideoStream extends Stream { public final String resolution; public final boolean isVideoOnly; + // Fields for Dash + public int bitrate; + public int initStart; + public int initEnd; + public int indexStart; + public int indexEnd; + public int width; + public int height; + public String codec; public VideoStream(String url, MediaFormat format, String resolution) { this(url, format, resolution, false); @@ -37,6 +46,20 @@ public class VideoStream extends Stream { this.isVideoOnly = isVideoOnly; } + public VideoStream(String url, MediaFormat format, String resolution, boolean isVideoOnly, int bitrate, int initStart, int initEnd, int indexStart, int indexEnd, String codec, int width, int height) { + super(url, format); + this.resolution = resolution; + this.isVideoOnly = isVideoOnly; + this.bitrate = bitrate; + this.initStart = initStart; + this.initEnd = initEnd; + this.indexStart = indexStart; + this.indexEnd = indexEnd; + this.codec = codec; + this.height = height; + this.width = width; + } + public VideoStream(String url, String torrentUrl, MediaFormat format, String resolution) { this(url, torrentUrl, format, resolution, false); } @@ -73,4 +96,36 @@ public class VideoStream extends Stream { public boolean isVideoOnly() { return isVideoOnly; } + + public int getBitrate() { + return bitrate; + } + + public int getInitStart() { + return initStart; + } + + public int getInitEnd() { + return initEnd; + } + + public int getIndexStart() { + return indexStart; + } + + public int getIndexEnd() { + return indexEnd; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public String getCodec() { + return codec; + } }