Skip to content

Commit d70adfd

Browse files
committed
Add methods for cache control to YoutubeThrottlingDecrypter.
1 parent d13f531 commit d70adfd

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
/**
1313
* <p>
14-
* YouTube's media is protected with a cipher, which modifies the "n" query parameter of it's video playback urls.
15-
* This class handles extracting that "n" query parameter, applying the cipher on it and returning the resulting url
16-
* which is not throttled.
14+
* YouTube's media is protected with a cipher,
15+
* which modifies the "n" query parameter of it's video playback urls.
16+
* This class handles extracting that "n" query parameter,
17+
* applying the cipher on it and returning the resulting url which is not throttled.
1718
* </p>
1819
*
1920
* <p>
@@ -23,6 +24,12 @@
2324
* <p>
2425
* https://r5---sn-4g5ednsz.googlevideo.com/videoplayback?n=iHywZkMipkszqA&other=other
2526
* </p>
27+
* <br>
28+
* <p>
29+
* Decoding the "n" parameter is time intensive. For this reason, the results are cached.
30+
* The cache can be cleared using {@link #clearCache()}
31+
* </p>
32+
*
2633
*/
2734
public class YoutubeThrottlingDecrypter {
2835

@@ -102,4 +109,18 @@ private String replaceNParam(@Nonnull final String url,
102109
final String newValue) {
103110
return url.replace(oldValue, newValue);
104111
}
112+
113+
/**
114+
* @return the number of the cached "n" query parameters.
115+
*/
116+
public static int getCacheSize() {
117+
return nParams.size();
118+
}
119+
120+
/**
121+
* Clears all stored "n" query parameters.
122+
*/
123+
public static void clearCache() {
124+
nParams.clear();
125+
}
105126
}

0 commit comments

Comments
 (0)