3333import java .util .Objects ;
3434
3535import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .addClientInfoHeaders ;
36- import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .getYoutubeAndroidAppUserAgent ;
36+ import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .getAndroidUserAgent ;
37+ import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .getIosUserAgent ;
3738import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .isAndroidStreamingUrl ;
39+ import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .isIosStreamingUrl ;
40+ import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .isTvHtml5SimplyEmbeddedPlayerStreamingUrl ;
3841import static org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper .isWebStreamingUrl ;
3942import static org .schabi .newpipe .extractor .utils .Utils .EMPTY_STRING ;
4043import static org .schabi .newpipe .extractor .utils .Utils .isBlank ;
@@ -562,54 +565,44 @@ private static Response getInitializationResponse(@Nonnull String baseStreamingU
562565 @ Nonnull final ItagItem itagItem ,
563566 final DeliveryType deliveryType )
564567 throws YoutubeDashManifestCreationException {
565- final boolean isAWebStreamingUrl = isWebStreamingUrl (baseStreamingUrl );
568+ final boolean isAHtml5StreamingUrl = isWebStreamingUrl (baseStreamingUrl )
569+ || isTvHtml5SimplyEmbeddedPlayerStreamingUrl (baseStreamingUrl );
566570 final boolean isAnAndroidStreamingUrl = isAndroidStreamingUrl (baseStreamingUrl );
567- final boolean isAnAndroidStreamingUrlAndAPostLiveDvrStream = isAnAndroidStreamingUrl
568- && deliveryType == DeliveryType .LIVE ;
569- if (isAWebStreamingUrl ) {
571+ final boolean isAnIosStreamingUrl = isIosStreamingUrl (baseStreamingUrl );
572+ if (isAHtml5StreamingUrl ) {
570573 baseStreamingUrl += ALR_YES ;
571574 }
572575 baseStreamingUrl = appendRnParamAndSqParamIfNeeded (baseStreamingUrl , deliveryType );
573576
574577 final Downloader downloader = NewPipe .getDownloader ();
575- if (isAWebStreamingUrl ) {
578+ if (isAHtml5StreamingUrl ) {
576579 final String mimeTypeExpected = itagItem .getMediaFormat ().getMimeType ();
577580 if (!isNullOrEmpty (mimeTypeExpected )) {
578581 return getStreamingWebUrlWithoutRedirects (downloader , baseStreamingUrl ,
579582 mimeTypeExpected , deliveryType );
580583 }
581- } else if (isAnAndroidStreamingUrlAndAPostLiveDvrStream ) {
584+ } else if (isAnAndroidStreamingUrl || isAnIosStreamingUrl ) {
582585 try {
583586 final Map <String , List <String >> headers = new HashMap <>();
584587 headers .put ("User-Agent" , Collections .singletonList (
585- getYoutubeAndroidAppUserAgent (null )));
588+ isAnAndroidStreamingUrl ? getAndroidUserAgent (null )
589+ : getIosUserAgent (null )));
586590 final byte [] emptyBody = "" .getBytes (StandardCharsets .UTF_8 );
587591 return downloader .post (baseStreamingUrl , headers , emptyBody );
588592 } catch (final IOException | ExtractionException e ) {
589593 throw new YoutubeDashManifestCreationException (
590594 "Could not generate the DASH manifest: error when trying to get the "
591- + "ANDROID streaming post-live-DVR URL response" , e );
595+ + (isAnIosStreamingUrl ? "ANDROID" : "IOS" )
596+ + " streaming URL response" , e );
592597 }
593598 }
594599
595600 try {
596- final Map <String , List <String >> headers = new HashMap <>();
597- if (isAnAndroidStreamingUrl ) {
598- headers .put ("User-Agent" , Collections .singletonList (
599- getYoutubeAndroidAppUserAgent (null )));
600- }
601-
602- return downloader .get (baseStreamingUrl , headers );
601+ return downloader .get (baseStreamingUrl );
603602 } catch (final IOException | ExtractionException e ) {
604- if (isAnAndroidStreamingUrl ) {
605603 throw new YoutubeDashManifestCreationException (
606- "Could not generate the DASH manifest: error when trying to get the "
607- + "ANDROID streaming URL response" , e );
608- } else {
609- throw new YoutubeDashManifestCreationException (
610- "Could not generate the DASH manifest: error when trying to get the "
611- + "streaming URL response" , e );
612- }
604+ "Could not generate the DASH manifest: error when trying to get the streaming "
605+ + "URL response" , e );
613606 }
614607 }
615608
@@ -834,8 +827,10 @@ private static int getStreamDuration(@Nonnull final String[] segmentDuration)
834827 * sequence of the stream
835828 * @param deliveryType the {@link DeliveryType} of the stream, see the enum for
836829 * possible values
830+ * @param itagItem the {@link ItagItem} which will be used to get the duration
831+ * of progressive streams
837832 * @param durationSecondsFallback the duration in seconds, extracted from player response, used
838- * as a fallback
833+ * as a fallback if the duration could not be determined
839834 * @return a {@link Document} object which contains a {@code <MPD>} element
840835 * @throws YoutubeDashManifestCreationException if something goes wrong when generating/
841836 * appending the {@link Document object} or the
@@ -1698,7 +1693,7 @@ public static double getProgressiveStreamsClearFactor() {
16981693 }
16991694
17001695 /**
1701- * Set the clear factor of cached OTF streams
1696+ * Set the clear factor of cached OTF streams.
17021697 *
17031698 * @param otfStreamsClearFactor the clear factor of OTF streams manifests cache.
17041699 */
@@ -1707,7 +1702,7 @@ public static void setOtfStreamsClearFactor(final double otfStreamsClearFactor)
17071702 }
17081703
17091704 /**
1710- * Set the clear factor of cached post-live-DVR streams
1705+ * Set the clear factor of cached post-live-DVR streams.
17111706 *
17121707 * @param postLiveDvrStreamsClearFactor the clear factor of post-live-DVR streams manifests
17131708 * cache.
@@ -1718,7 +1713,7 @@ public static void setPostLiveDvrStreamsClearFactor(
17181713 }
17191714
17201715 /**
1721- * Set the clear factor of cached progressive streams
1716+ * Set the clear factor of cached progressive streams.
17221717 *
17231718 * @param progressiveStreamsClearFactor the clear factor of progressive streams manifests
17241719 * cache.
0 commit comments