From 09716d0d0e50dde2e1fc68c6fdd093740d654bed Mon Sep 17 00:00:00 2001 From: Simon Jacquin Date: Wed, 6 Oct 2021 21:14:25 +0200 Subject: [PATCH] Filter out videos using FORMAT_STREAM_TYPE_OTF (#205) * Filter out videos using FORMAT_STREAM_TYPE_OTF * Fix a wrong usage of JSON getString --- .../at/huber/youtubeExtractor/YouTubeExtractor.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/youtubeExtractor/src/main/java/at/huber/youtubeExtractor/YouTubeExtractor.java b/youtubeExtractor/src/main/java/at/huber/youtubeExtractor/YouTubeExtractor.java index 8ae9815..3131948 100644 --- a/youtubeExtractor/src/main/java/at/huber/youtubeExtractor/YouTubeExtractor.java +++ b/youtubeExtractor/src/main/java/at/huber/youtubeExtractor/YouTubeExtractor.java @@ -231,6 +231,14 @@ private SparseArray getStreamUrls() throws IOException, InterruptedExcep for (int i = 0; i < formats.length(); i++) { JSONObject format = formats.getJSONObject(i); + + // FORMAT_STREAM_TYPE_OTF(otf=1) requires downloading the init fragment (adding + // `&sq=0` to the URL) and parsing emsg box to determine the number of fragment that + // would subsequently requested with (`&sq=N`) (cf. youtube-dl) + String type = format.optString("type"); + if (type != null && type.equals("FORMAT_STREAM_TYPE_OTF")) + continue; + int itag = format.getInt("itag"); if (FORMAT_MAP.get(itag) != null) { @@ -255,6 +263,11 @@ private SparseArray getStreamUrls() throws IOException, InterruptedExcep for (int i = 0; i < adaptiveFormats.length(); i++) { JSONObject adaptiveFormat = adaptiveFormats.getJSONObject(i); + + String type = adaptiveFormat.optString("type"); + if (type != null && type.equals("FORMAT_STREAM_TYPE_OTF")) + continue; + int itag = adaptiveFormat.getInt("itag"); if (FORMAT_MAP.get(itag) != null) {