Skip to content

Commit

Permalink
[YouTube] Don't return the AudioStreams and the VideoOnlyStreams from…
Browse files Browse the repository at this point in the history
… the adaptiveFormats array for livestreams

Because they cannot not streamed or downloaded as they are. There are always audio and video streams because the DASH manifest is extracted.
  • Loading branch information
AudricV committed Jul 8, 2021
1 parent b33c3ee commit 5a7bf67
Showing 1 changed file with 56 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,25 @@ public String getHlsUrl() throws ParsingException {
public List<AudioStream> getAudioStreams() throws ExtractionException {
assertPageFetched();
final List<AudioStream> audioStreams = new ArrayList<>();
final StreamType streamType = this.getStreamType();

try {
for (final Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FORMATS, ItagItem.ItagType.AUDIO).entrySet()) {
final ItagItem itag = entry.getValue();
final AudioStream audioStream = new AudioStream(String.valueOf(itag.id),
entry.getKey(), true, itag.getMediaFormat(),
DeliveryMethod.PROGRESSIVE_HTTP, itag.avgBitrate, itag, null);
audioStreams.add(audioStream);
if (streamType == StreamType.VIDEO_STREAM) {
try {
for (final Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FORMATS, ItagItem.ItagType.AUDIO).entrySet()) {
final ItagItem itag = entry.getValue();
final AudioStream audioStream = new AudioStream(String.valueOf(itag.id),
entry.getKey(), true, itag.getMediaFormat(),
DeliveryMethod.PROGRESSIVE_HTTP, itag.avgBitrate, itag, null);
audioStreams.add(audioStream);
}
} catch (final Exception e) {
throw new ParsingException("Could not get audio streams", e);
}
}

final DashMpdParser.Result dashMpdResult = getDashResult();
if (dashMpdResult != null) {
audioStreams.addAll(dashMpdResult.getAudioStreams());
}
} catch (final Exception e) {
throw new ParsingException("Could not get audio streams", e);
final DashMpdParser.Result dashMpdResult = getDashResult();
if (dashMpdResult != null) {
audioStreams.addAll(dashMpdResult.getAudioStreams());
}

return audioStreams;
Expand All @@ -534,22 +537,25 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
public List<VideoStream> getVideoStreams() throws ExtractionException {
assertPageFetched();
final List<VideoStream> videoStreams = new ArrayList<>();
final StreamType streamType = this.getStreamType();

try {
for (final Map.Entry<String, ItagItem> entry : getItags(FORMATS, ItagItem.ItagType.VIDEO).entrySet()) {
final ItagItem itag = entry.getValue();
final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
entry.getKey(), true, itag.getMediaFormat(),
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, false, itag, null);
videoStreams.add(videoStream);
if (streamType == StreamType.VIDEO_STREAM) {
try {
for (final Map.Entry<String, ItagItem> entry : getItags(FORMATS, ItagItem.ItagType.VIDEO).entrySet()) {
final ItagItem itag = entry.getValue();
final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
entry.getKey(), true, itag.getMediaFormat(),
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, false, itag, null);
videoStreams.add(videoStream);
}
} catch (final Exception e) {
throw new ParsingException("Could not get video streams", e);
}
}

final DashMpdParser.Result dashMpdResult = getDashResult();
if (dashMpdResult != null) {
videoStreams.addAll(dashMpdResult.getVideoStreams());
}
} catch (final Exception e) {
throw new ParsingException("Could not get video streams", e);
final DashMpdParser.Result dashMpdResult = getDashResult();
if (dashMpdResult != null) {
videoStreams.addAll(dashMpdResult.getVideoStreams());
}

return videoStreams;
Expand All @@ -559,22 +565,26 @@ public List<VideoStream> getVideoStreams() throws ExtractionException {
public List<VideoStream> getVideoOnlyStreams() throws ExtractionException {
assertPageFetched();
final List<VideoStream> videoOnlyStreams = new ArrayList<>();
try {
for (final Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FORMATS, ItagItem.ItagType.VIDEO_ONLY).entrySet()) {
final ItagItem itag = entry.getValue();
final StreamType streamType = this.getStreamType();

final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
entry.getKey(), true, itag.getMediaFormat(),
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, true, itag, null);
videoOnlyStreams.add(videoStream);
}
if (streamType == StreamType.VIDEO_STREAM) {
try {
for (final Map.Entry<String, ItagItem> entry : getItags(ADAPTIVE_FORMATS, ItagItem.ItagType.VIDEO_ONLY).entrySet()) {
final ItagItem itag = entry.getValue();

final DashMpdParser.Result dashMpdResult = getDashResult();
if (dashMpdResult != null) {
videoOnlyStreams.addAll(dashMpdResult.getVideoOnlyStreams());
final VideoStream videoStream = new VideoStream(String.valueOf(itag.id),
entry.getKey(), true, itag.getMediaFormat(),
DeliveryMethod.PROGRESSIVE_HTTP, itag.resolutionString, true, itag, null);
videoOnlyStreams.add(videoStream);
}
} catch (final Exception e) {
throw new ParsingException("Could not get video only streams", e);
}
} catch (final Exception e) {
throw new ParsingException("Could not get video only streams", e);
}

final DashMpdParser.Result dashMpdResult = getDashResult();
if (dashMpdResult != null) {
videoOnlyStreams.addAll(dashMpdResult.getVideoOnlyStreams());
}

return videoOnlyStreams;
Expand Down Expand Up @@ -630,8 +640,13 @@ public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws Parsi
@Override
public StreamType getStreamType() {
assertPageFetched();
return playerResponse.getObject("streamingData").has(FORMATS)
? StreamType.VIDEO_STREAM : StreamType.LIVE_STREAM;
if (playerResponse.getObject("playabilityStatus").has("liveStreamability")) {
return StreamType.LIVE_STREAM;
} else if (playerResponse.getObject("videoDetails").getBoolean("isPostLiveDvr", false)) {
return StreamType.POST_LIVE_STREAM;
} else {
return StreamType.VIDEO_STREAM;
}
}

@Nullable
Expand Down

0 comments on commit 5a7bf67

Please sign in to comment.