Skip to content

Commit d3f7945

Browse files
committed
[duplicated subtitle][YouTube] Restrict SubtitleDeduplicator to YouTube-related URLs.
- `SubtitleDeduplicator` relies on YouTube-specific subtitle URL semantics (videoId, languageCode, translationCode) for cache file naming and deduplication. - Add `isYoutubeRelatedUrl()` to ensure deduplication logic is only applied to YouTube URLs. For non-YouTube subtitle URLs, the original subtitle URL is returned unchanged.
1 parent 41e158c commit d3f7945

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/util/subtitle/SubtitleDeduplicator.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import java.util.regex.Matcher;
1818
import java.util.regex.Pattern;
1919

20+
import java.net.MalformedURLException;
21+
import java.net.URL;
22+
2023
import androidx.annotation.NonNull;
2124

2225
import android.util.Log;
@@ -75,6 +78,13 @@ public static void setCacheDirPath(final String path) {
7578
public static String checkAndDeduplicate(final String remoteSubtitleUrl,
7679
final MediaFormat format,
7780
final SubtitleOrigin currentSubtitleOrigin) {
81+
// Subtitle deduplication relies on YouTube-specific subtitle URL semantics
82+
// (videoId, languageCode, translationCode) which are used for cache file naming.
83+
// For non-YouTube URLs, the original subtitle is returned unchanged.
84+
if (!isYoutubeRelatedUrl(remoteSubtitleUrl)) {
85+
return remoteSubtitleUrl;
86+
}
87+
7888
if (!isCacheDirAvailable()) {
7989
printCacheDirNotInitialized();
8090
return remoteSubtitleUrl;
@@ -488,6 +498,16 @@ private static String getVideoId(final String remoteSubtitleUrl) {
488498
return YoutubeParsingHelper.extractVideoId(remoteSubtitleUrl);
489499
}
490500

501+
private static boolean isYoutubeRelatedUrl(@NonNull final String url) {
502+
try {
503+
final URL parsedUrl = new URL(url);
504+
return (YoutubeParsingHelper.isYoutubeURL(parsedUrl)
505+
|| YoutubeParsingHelper.isYoutubeServiceURL(parsedUrl));
506+
} catch (final MalformedURLException e) {
507+
return false;
508+
}
509+
}
510+
491511
private static File getCacheFile(final String subtitleUrl,
492512
final MediaFormat format,
493513
final SubtitleOrigin currentSubtitleOrigin,

0 commit comments

Comments
 (0)