@@ -509,22 +509,25 @@ public String getHlsUrl() throws ParsingException {
509509 public List <AudioStream > getAudioStreams () throws ExtractionException {
510510 assertPageFetched ();
511511 final List <AudioStream > audioStreams = new ArrayList <>();
512+ final StreamType streamType = this .getStreamType ();
512513
513- try {
514- for (final Map .Entry <String , ItagItem > entry : getItags (ADAPTIVE_FORMATS , ItagItem .ItagType .AUDIO ).entrySet ()) {
515- final ItagItem itag = entry .getValue ();
516- final AudioStream audioStream = new AudioStream (String .valueOf (itag .id ),
517- entry .getKey (), true , itag .getMediaFormat (),
518- DeliveryMethod .PROGRESSIVE_HTTP , itag .avgBitrate , itag , null );
519- audioStreams .add (audioStream );
514+ if (streamType == StreamType .VIDEO_STREAM ) {
515+ try {
516+ for (final Map .Entry <String , ItagItem > entry : getItags (ADAPTIVE_FORMATS , ItagItem .ItagType .AUDIO ).entrySet ()) {
517+ final ItagItem itag = entry .getValue ();
518+ final AudioStream audioStream = new AudioStream (String .valueOf (itag .id ),
519+ entry .getKey (), true , itag .getMediaFormat (),
520+ DeliveryMethod .PROGRESSIVE_HTTP , itag .avgBitrate , itag , null );
521+ audioStreams .add (audioStream );
522+ }
523+ } catch (final Exception e ) {
524+ throw new ParsingException ("Could not get audio streams" , e );
520525 }
526+ }
521527
522- final DashMpdParser .Result dashMpdResult = getDashResult ();
523- if (dashMpdResult != null ) {
524- audioStreams .addAll (dashMpdResult .getAudioStreams ());
525- }
526- } catch (final Exception e ) {
527- throw new ParsingException ("Could not get audio streams" , e );
528+ final DashMpdParser .Result dashMpdResult = getDashResult ();
529+ if (dashMpdResult != null ) {
530+ audioStreams .addAll (dashMpdResult .getAudioStreams ());
528531 }
529532
530533 return audioStreams ;
@@ -534,22 +537,25 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
534537 public List <VideoStream > getVideoStreams () throws ExtractionException {
535538 assertPageFetched ();
536539 final List <VideoStream > videoStreams = new ArrayList <>();
540+ final StreamType streamType = this .getStreamType ();
537541
538- try {
539- for (final Map .Entry <String , ItagItem > entry : getItags (FORMATS , ItagItem .ItagType .VIDEO ).entrySet ()) {
540- final ItagItem itag = entry .getValue ();
541- final VideoStream videoStream = new VideoStream (String .valueOf (itag .id ),
542- entry .getKey (), true , itag .getMediaFormat (),
543- DeliveryMethod .PROGRESSIVE_HTTP , itag .resolutionString , false , itag , null );
544- videoStreams .add (videoStream );
542+ if (streamType == StreamType .VIDEO_STREAM ) {
543+ try {
544+ for (final Map .Entry <String , ItagItem > entry : getItags (FORMATS , ItagItem .ItagType .VIDEO ).entrySet ()) {
545+ final ItagItem itag = entry .getValue ();
546+ final VideoStream videoStream = new VideoStream (String .valueOf (itag .id ),
547+ entry .getKey (), true , itag .getMediaFormat (),
548+ DeliveryMethod .PROGRESSIVE_HTTP , itag .resolutionString , false , itag , null );
549+ videoStreams .add (videoStream );
550+ }
551+ } catch (final Exception e ) {
552+ throw new ParsingException ("Could not get video streams" , e );
545553 }
554+ }
546555
547- final DashMpdParser .Result dashMpdResult = getDashResult ();
548- if (dashMpdResult != null ) {
549- videoStreams .addAll (dashMpdResult .getVideoStreams ());
550- }
551- } catch (final Exception e ) {
552- throw new ParsingException ("Could not get video streams" , e );
556+ final DashMpdParser .Result dashMpdResult = getDashResult ();
557+ if (dashMpdResult != null ) {
558+ videoStreams .addAll (dashMpdResult .getVideoStreams ());
553559 }
554560
555561 return videoStreams ;
@@ -559,22 +565,26 @@ public List<VideoStream> getVideoStreams() throws ExtractionException {
559565 public List <VideoStream > getVideoOnlyStreams () throws ExtractionException {
560566 assertPageFetched ();
561567 final List <VideoStream > videoOnlyStreams = new ArrayList <>();
562- try {
563- for (final Map .Entry <String , ItagItem > entry : getItags (ADAPTIVE_FORMATS , ItagItem .ItagType .VIDEO_ONLY ).entrySet ()) {
564- final ItagItem itag = entry .getValue ();
568+ final StreamType streamType = this .getStreamType ();
565569
566- final VideoStream videoStream = new VideoStream (String .valueOf (itag .id ),
567- entry .getKey (), true , itag .getMediaFormat (),
568- DeliveryMethod .PROGRESSIVE_HTTP , itag .resolutionString , true , itag , null );
569- videoOnlyStreams .add (videoStream );
570- }
570+ if (streamType == StreamType .VIDEO_STREAM ) {
571+ try {
572+ for (final Map .Entry <String , ItagItem > entry : getItags (ADAPTIVE_FORMATS , ItagItem .ItagType .VIDEO_ONLY ).entrySet ()) {
573+ final ItagItem itag = entry .getValue ();
571574
572- final DashMpdParser .Result dashMpdResult = getDashResult ();
573- if (dashMpdResult != null ) {
574- videoOnlyStreams .addAll (dashMpdResult .getVideoOnlyStreams ());
575+ final VideoStream videoStream = new VideoStream (String .valueOf (itag .id ),
576+ entry .getKey (), true , itag .getMediaFormat (),
577+ DeliveryMethod .PROGRESSIVE_HTTP , itag .resolutionString , true , itag , null );
578+ videoOnlyStreams .add (videoStream );
579+ }
580+ } catch (final Exception e ) {
581+ throw new ParsingException ("Could not get video only streams" , e );
575582 }
576- } catch (final Exception e ) {
577- throw new ParsingException ("Could not get video only streams" , e );
583+ }
584+
585+ final DashMpdParser .Result dashMpdResult = getDashResult ();
586+ if (dashMpdResult != null ) {
587+ videoOnlyStreams .addAll (dashMpdResult .getVideoOnlyStreams ());
578588 }
579589
580590 return videoOnlyStreams ;
@@ -630,8 +640,13 @@ public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws Parsi
630640 @ Override
631641 public StreamType getStreamType () {
632642 assertPageFetched ();
633- return playerResponse .getObject ("streamingData" ).has (FORMATS )
634- ? StreamType .VIDEO_STREAM : StreamType .LIVE_STREAM ;
643+ if (playerResponse .getObject ("playabilityStatus" ).has ("liveStreamability" )) {
644+ return StreamType .LIVE_STREAM ;
645+ } else if (playerResponse .getObject ("videoDetails" ).getBoolean ("isPostLiveDvr" , false )) {
646+ return StreamType .POST_LIVE_STREAM ;
647+ } else {
648+ return StreamType .VIDEO_STREAM ;
649+ }
635650 }
636651
637652 @ Nullable
0 commit comments