Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Fix extraction for unembeddable videos
Browse files Browse the repository at this point in the history
  • Loading branch information
HaarigerHarald committed Sep 15, 2018
1 parent 7c32e0f commit a942648
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public void testUsualVideo() throws Throwable {
extractorTestDashManifest("http:https://youtube.com/watch?v=YE7VzlLtp-4");
}

public void testUnembeddable() throws Throwable {
VideoMeta expMeta = new VideoMeta("QH4VHl2uQ9o", "Match Chain Reaction Amazing Fire Art", "BLACKHAND",
"UCl9nsRuGenStMDZfD95w85A", 331, 0, false);
extractorTest("https://www.youtube.com/watch?v=QH4VHl2uQ9o", expMeta);
extractorTestDashManifest("https://www.youtube.com/watch?v=QH4VHl2uQ9o");
}

public void testEncipheredVideo() throws Throwable {
VideoMeta expMeta = new VideoMeta("e8X3ACToii0", "Rise Against - Savior", "RiseAgainstVEVO",
"UChMKB2AHNpeuWhalpRYhUaw", 243, 0, false);
Expand Down Expand Up @@ -86,6 +93,7 @@ public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMet

HttpURLConnection con = (HttpURLConnection) url.openConnection();
int code = con.getResponseCode();
con.getInputStream().close();
con.disconnect();
assertEquals(200, code);
}
Expand Down Expand Up @@ -131,6 +139,7 @@ public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMe

HttpURLConnection con = (HttpURLConnection) url.openConnection();
int code = con.getResponseCode();
con.getInputStream().close();
con.disconnect();
assertEquals(200, code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public abstract class YouTubeExtractor extends AsyncTask<String, Void, SparseArr
private static final Pattern patChannelId = Pattern.compile("ucid=(.+?)(&|\\z)");
private static final Pattern patLength = Pattern.compile("length_seconds=(\\d+?)(&|\\z)");
private static final Pattern patViewCount = Pattern.compile("view_count=(\\d+?)(&|\\z)");
private static final Pattern patStatusOk = Pattern.compile("status=ok(&|,|\\z)");

private static final Pattern patHlsvp = Pattern.compile("hlsvp=(.+?)(&|\\z)");
private static final Pattern patHlsItag = Pattern.compile("/itag/(\\d+?)/");
Expand Down Expand Up @@ -276,22 +277,29 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep

// "use_cipher_signature" disappeared, we check whether at least one ciphered signature
// exists int the stream_map.
boolean sigEnc = true;
boolean sigEnc = true, statusFail = false;
if(streamMap != null && streamMap.contains(STREAM_MAP_STRING)){
String streamMapSub = streamMap.substring(streamMap.indexOf(STREAM_MAP_STRING));
mat = patIsSigEnc.matcher(streamMapSub);
if(!mat.find())
if(!mat.find()) {
sigEnc = false;

if (!patStatusOk.matcher(streamMap).find())
statusFail = true;
}
}

// Some videos are using a ciphered signature we need to get the
// deciphering js-file from the youtubepage.
if (sigEnc) {
if (sigEnc || statusFail) {
// Get the video directly from the youtubepage
if (CACHING
&& (decipherJsFileName == null || decipherFunctions == null || decipherFunctionName == null)) {
readDecipherFunctFromCache();
}
if (LOGGING)
Log.d(LOG_TAG, "Get from youtube page");

getUrl = new URL("https://youtube.com/watch?v=" + videoID);
urlConnection = (HttpURLConnection) getUrl.openConnection();
urlConnection.setRequestProperty("User-Agent", USER_AGENT);
Expand Down

0 comments on commit a942648

Please sign in to comment.