Skip to content

Commit 9333d7f

Browse files
AudricVStypox
authored andcommitted
[YouTube] Update DASH manifest creation clients' handling
- Use POST requests with the same body as official clients do; - Update methods checking the client streaming URLs come from: - Replace TVHTML5_SIMPLY_EMBEDDED_PLAYER by TVHTML5; - Add WEB_EMBEDDED_PLAYER.
1 parent 38e2b67 commit 9333d7f

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ private YoutubeParsingHelper() {
180180
"https://www.youtube.com/feeds/videos.xml?channel_id=";
181181
private static final String FEED_BASE_USER = "https://www.youtube.com/feeds/videos.xml?user=";
182182
private static final Pattern C_WEB_PATTERN = Pattern.compile("&c=WEB");
183-
private static final Pattern C_TVHTML5_SIMPLY_EMBEDDED_PLAYER_PATTERN =
184-
Pattern.compile("&c=TVHTML5_SIMPLY_EMBEDDED_PLAYER");
183+
private static final Pattern C_WEB_EMBEDDED_PLAYER_PATTERN =
184+
Pattern.compile("&c=WEB_EMBEDDED_PLAYER");
185+
private static final Pattern C_TVHTML5_PLAYER_PATTERN =
186+
Pattern.compile("&c=TVHTML5");
185187
private static final Pattern C_ANDROID_PATTERN = Pattern.compile("&c=ANDROID");
186188
private static final Pattern C_IOS_PATTERN = Pattern.compile("&c=IOS");
187189

@@ -1394,15 +1396,24 @@ public static boolean isWebStreamingUrl(@Nonnull final String url) {
13941396
}
13951397

13961398
/**
1397-
* Check if the streaming URL is a URL from the YouTube {@code TVHTML5_SIMPLY_EMBEDDED_PLAYER}
1398-
* client.
1399+
* Check if the streaming URL is from the YouTube {@code WEB_EMBEDDED_PLAYER} client.
1400+
*
1401+
* @param url the streaming URL to be checked.
1402+
* @return true if it's a {@code WEB_EMBEDDED_PLAYER} streaming URL, false otherwise
1403+
*/
1404+
public static boolean isWebEmbeddedPlayerStreamingUrl(@Nonnull final String url) {
1405+
return Parser.isMatch(C_WEB_EMBEDDED_PLAYER_PATTERN, url);
1406+
}
1407+
1408+
/**
1409+
* Check if the streaming URL is a URL from the YouTube {@code TVHTML5} client.
13991410
*
1400-
* @param url the streaming URL on which check if it's a {@code TVHTML5_SIMPLY_EMBEDDED_PLAYER}
1411+
* @param url the streaming URL on which check if it's a {@code TVHTML5}
14011412
* streaming URL.
1402-
* @return true if it's a {@code TVHTML5_SIMPLY_EMBEDDED_PLAYER} streaming URL, false otherwise
1413+
* @return true if it's a {@code TVHTML5} streaming URL, false otherwise
14031414
*/
1404-
public static boolean isTvHtml5SimplyEmbeddedPlayerStreamingUrl(@Nonnull final String url) {
1405-
return Parser.isMatch(C_TVHTML5_SIMPLY_EMBEDDED_PLAYER_PATTERN, url);
1415+
public static boolean isTvHtml5StreamingUrl(@Nonnull final String url) {
1416+
return Parser.isMatch(C_TVHTML5_PLAYER_PATTERN, url);
14061417
}
14071418

14081419
/**

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/dashmanifestcreators/YoutubeDashManifestCreatorsUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getIosUserAgent;
66
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isAndroidStreamingUrl;
77
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isIosStreamingUrl;
8-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isTvHtml5SimplyEmbeddedPlayerStreamingUrl;
8+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isTvHtml5StreamingUrl;
99
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl;
10+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebEmbeddedPlayerStreamingUrl;
1011
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
1112

1213
import org.schabi.newpipe.extractor.MediaFormat;
@@ -582,8 +583,8 @@ public static void generateSegmentTimelineElement(@Nonnull final Document doc)
582583
* This method fetches, for OTF streams and for post-live-DVR streams:
583584
* <ul>
584585
* <li>the base URL of the stream, to which are appended {@link #SQ_0} and
585-
* {@link #RN_0} parameters, with a {@code GET} request for streaming URLs from HTML5
586-
* clients and a {@code POST} request for the ones from the {@code ANDROID} and the
586+
* {@link #RN_0} parameters, with a {@code POS} request for streaming URLs from
587+
* {@code WEB}, {@code TVHTML5}, {@code WEB_EMBEDDED_PLAYER}, {@code ANDROID} and
587588
* {@code IOS} clients;</li>
588589
* <li>for streaming URLs from HTML5 clients, the {@link #ALR_YES} param is also added.
589590
* </li>
@@ -602,7 +603,8 @@ public static Response getInitializationResponse(@Nonnull String baseStreamingUr
602603
final DeliveryType deliveryType)
603604
throws CreationException {
604605
final boolean isHtml5StreamingUrl = isWebStreamingUrl(baseStreamingUrl)
605-
|| isTvHtml5SimplyEmbeddedPlayerStreamingUrl(baseStreamingUrl);
606+
|| isTvHtml5StreamingUrl(baseStreamingUrl)
607+
|| isWebEmbeddedPlayerStreamingUrl(baseStreamingUrl);
606608
final boolean isAndroidStreamingUrl = isAndroidStreamingUrl(baseStreamingUrl);
607609
final boolean isIosStreamingUrl = isIosStreamingUrl(baseStreamingUrl);
608610
if (isHtml5StreamingUrl) {
@@ -748,7 +750,8 @@ private static Response getStreamingWebUrlWithoutRedirects(
748750
int redirectsCount = 0;
749751
while (!responseMimeType.equals(responseMimeTypeExpected)
750752
&& redirectsCount < MAXIMUM_REDIRECT_COUNT) {
751-
final Response response = downloader.get(streamingUrl, headers);
753+
final byte[] html5Body = new byte[] {0x78, 0};
754+
final Response response = downloader.post(streamingUrl, headers, html5Body);
752755

753756
final int responseCode = response.responseCode();
754757
if (responseCode != 200) {

0 commit comments

Comments
 (0)