From 2fb1a412a6453db62b5824ff6562f237cf1193d0 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sun, 3 Apr 2022 18:42:01 +0200 Subject: [PATCH] Fix Checkstyle issues, revert resolution string changes for YouTube video streams and don't return the rn parameter in DASH manifests This parameter is still used to get the initialization sequence of OTF and POST-live streams, but is not returned anymore in the manifests. It has been removed in order to avoid fingerprinting based on the number sent (e.g. when starting to play a stream close to the end and using 123 as the request number where it should be 1) and should be added dynamically by clients in their requests. The relevant test has been also updated. Checkstyle issues in YoutubeDashManifestCreator have been fixed, and the changes in the resolution string returned for video streams in YoutubeStreamExtractor have been reverted, as they create issues on NewPipe right now. --- .../youtube/YoutubeDashManifestCreator.java | 54 ++++++++++++------- .../extractors/YoutubeStreamExtractor.java | 18 ++----- .../extractor/stream/DeliveryMethod.java | 4 +- .../YoutubeDashManifestCreatorTest.java | 15 ++++-- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreator.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreator.java index 2d7f7fe2..a61b8695 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreator.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreator.java @@ -23,10 +23,22 @@ import javax.xml.transform.stream.StreamResult; import java.io.IOException; import java.io.StringWriter; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; -import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; -import static org.schabi.newpipe.extractor.utils.Utils.*; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.addClientInfoHeaders; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getYoutubeAndroidAppUserAgent; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isAndroidStreamingUrl; +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.isWebStreamingUrl; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; +import static org.schabi.newpipe.extractor.utils.Utils.isBlank; +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; /** * Class to generate DASH manifests from YouTube OTF, progressive and ended/post-live-DVR streams. @@ -202,11 +214,11 @@ public final class YoutubeDashManifestCreator { *

In order to generate the DASH manifest, this method will: *

@@ -331,8 +343,8 @@ public final class YoutubeDashManifestCreator { *

In order to generate the DASH manifest, this method will: *

*

* @@ -1423,12 +1437,12 @@ public final class YoutubeDashManifestCreator { // Post-live-DVR/ended livestreams streams don't require an initialization sequence if (!isDeliveryTypeLive) { final Attr initializationAttribute = document.createAttribute("initialization"); - initializationAttribute.setValue(baseUrl + SQ_0 + RN_0); + initializationAttribute.setValue(baseUrl + SQ_0); segmentTemplateElement.setAttributeNode(initializationAttribute); } final Attr mediaAttribute = document.createAttribute("media"); - mediaAttribute.setValue(baseUrl + "&sq=$Number$&rn=$Number$"); + mediaAttribute.setValue(baseUrl + "&sq=$Number$"); segmentTemplateElement.setAttributeNode(mediaAttribute); representationElement.appendChild(segmentTemplateElement); 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 d10fce3b..14b9a9db 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 @@ -1292,21 +1292,9 @@ public class YoutubeStreamExtractor extends StreamExtractor { .setIsVideoOnly(areStreamsVideoOnly) .setItagItem(itagItem); - final int height = itagItem.getHeight(); - if (height > 0) { - final StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(height); - stringBuilder.append("p"); - final int fps = itagItem.getFps(); - if (fps > 30) { - stringBuilder.append(fps); - } - builder.setResolution(stringBuilder.toString()); - } else { - final String resolutionString = itagItem.getResolutionString(); - builder.setResolution(resolutionString != null ? resolutionString - : EMPTY_STRING); - } + final String resolutionString = itagItem.getResolutionString(); + builder.setResolution(resolutionString != null ? resolutionString + : EMPTY_STRING); if (streamType != StreamType.VIDEO_STREAM || !itagInfo.getIsUrl()) { // For YouTube videos on OTF streams and for all streams of post-live streams diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/DeliveryMethod.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/DeliveryMethod.java index 444023e5..5d8437b9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/DeliveryMethod.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/DeliveryMethod.java @@ -48,8 +48,8 @@ public enum DeliveryMethod { * * @see Wikipedia's BitTorrent's page, * Wikipedia's page about torrent files - * and for more information about the - * BitTorrent protocol + * and Bitorrent's website for more information + * about the BitTorrent protocol */ TORRENT } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreatorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreatorTest.java index 0cd23fca..fcfffda4 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreatorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeDashManifestCreatorTest.java @@ -21,7 +21,12 @@ import java.net.URL; import java.util.List; import java.util.Random; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.utils.Utils.isBlank; @@ -428,8 +433,8 @@ class YoutubeDashManifestCreatorTest { throw new AssertionError("The value of the initialization attribute is not an URL", e); } - assertTrue(initializationValue.endsWith("&sq=0&rn=0"), - "The value of the initialization attribute doesn't end with &sq=0&rn=0"); + assertTrue(initializationValue.endsWith("&sq=0"), + "The value of the initialization attribute doesn't end with &sq=0"); final String mediaValue = segmentTemplateElement.getAttribute("media"); assertFalse(isBlank(mediaValue), @@ -440,8 +445,8 @@ class YoutubeDashManifestCreatorTest { throw new AssertionError("The value of the media attribute is not an URL", e); } - assertTrue(mediaValue.endsWith("&sq=$Number$&rn=$Number$"), - "The value of the media attribute doesn't end with &sq=$Number$&rn=$Number$"); + assertTrue(mediaValue.endsWith("&sq=$Number$"), + "The value of the media attribute doesn't end with &sq=$Number$"); final String startNumberValue = segmentTemplateElement.getAttribute("startNumber"); assertFalse(isBlank(startNumberValue),