diff --git a/contrib/src/main/java/org/archive/modules/extractor/ExtractorYoutubeFormatStream.java b/contrib/src/main/java/org/archive/modules/extractor/ExtractorYoutubeFormatStream.java index 819b6ecc..82be44d3 100644 --- a/contrib/src/main/java/org/archive/modules/extractor/ExtractorYoutubeFormatStream.java +++ b/contrib/src/main/java/org/archive/modules/extractor/ExtractorYoutubeFormatStream.java @@ -1,6 +1,7 @@ package org.archive.modules.extractor; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Arrays; @@ -147,12 +148,12 @@ public class ExtractorYoutubeFormatStream extends Extractor { * never have them anymore?) * */ - + /* * Highest quality traditional stream. */ "37", // (discontinued) MP4 1080p H.264 High 3–5.9 AAC 192 - + /* * Traditional streams that are currently in use */ @@ -162,13 +163,13 @@ public class ExtractorYoutubeFormatStream extends Extractor { "5", // FLV 240p Sorenson H.263 N/A 0.25 MP3 64 "36", // 3GP 240p MPEG-4 Visual Simple 0.175 AAC 36 "17", // 3GP 144p MPEG-4 Visual Simple 0.05 AAC 24 - + /* * Discontinued FLV Standard Def */ "35", // (discontinued) FLV 480p H.264 Main 0.8-1 AAC 128 "34", // (discontinued) FLV 360p H.264 Main 0.5 AAC 128 - + /* * 3D streams that include video+audio */ @@ -177,7 +178,7 @@ public class ExtractorYoutubeFormatStream extends Extractor { "100", // WebM 360p VP8 3D N/A Vorbis 128 "82", // MP4 360p H.264 3D 0.5 AAC 96 "83", // MP4 240p H.264 3D 0.5 AAC 96 - + /* * Discontinued (but maybe not completely phased out?) */ @@ -189,7 +190,7 @@ public class ExtractorYoutubeFormatStream extends Extractor { "46", // (discontinued) WebM 1080p VP8 N/A N/A Vorbis 192 "101", // (discontinued) WebM 360p VP8 3D N/A Vorbis 192 "102", // (discontinued) WebM 720p VP8 3D N/A Vorbis 192 - + /* * live streaming - not sure what happens if we try to download one * of these @@ -201,7 +202,7 @@ public class ExtractorYoutubeFormatStream extends Extractor { "92", // (live streaming) MP4 240p H.264 Main 0.15-0.3 AAC 48 "132", // (live streaming) MP4 240p H.264 Baseline 0.15-0.2 AAC 48 "151", // (live streaming) MP4 72p H.264 Baseline 0.05 AAC 24 - + /* * http://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP * separate video and audio streams, not preferred because we @@ -221,7 +222,7 @@ public class ExtractorYoutubeFormatStream extends Extractor { "141", // (discontinued; MPEG-DASH audio only) MP4 AAC 256 "139" // (discontinued; MPEG-DASH audio only) MP4 AAC 48 ); - + private static final Set KNOWN_ITAGS = new HashSet(DEFAULT_ITAG_PRIORITY); // Add videos as outlinks by priority list @@ -271,8 +272,7 @@ public class ExtractorYoutubeFormatStream extends Extractor { // Parse Video Map into itag,url pair for (int i = 0; i < rawVideoList.length; i++) { String[] videoParams = rawVideoList[i].split("\\u0026"); - String videoURLParam, itagParam, sigParam; - videoURLParam = itagParam = sigParam = ""; + String videoURLParam=null, itagParam=null, sigParam=null; for (String param : videoParams) { @@ -288,20 +288,24 @@ public class ExtractorYoutubeFormatStream extends Extractor { if (keyValuePair[0].equals("itag")) { itagParam = keyValuePair[1]; } - if (keyValuePair[0].equals("sig")) { + if (keyValuePair[0].equals("sig") || keyValuePair[0].equals("s")) { sigParam = keyValuePair[1]; } } - if (videoURLParam.length() > 0 && itagParam.length() > 0 - && sigParam.length() > 0) { + if (videoURLParam != null && itagParam != null) { try { - String fixupURL = URLDecoder.decode(videoURLParam - + "%26signature=" + sigParam, "UTF-8"); + String fixupURL = URLDecoder.decode(videoURLParam, "UTF-8"); + if (sigParam != null) { + fixupURL = fixupURL + "&signature=" + sigParam; + } + if (!fixupURL.contains("signature=")) { + logger.warning("no 'signature' parameter in raw url or in stream map: " + fixupURL); + } parsedVideoMap.put(itagParam, fixupURL); - } catch (java.io.UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { logger.warning("Error decoding youtube video URL: " - + videoURLParam + "%26signature=" + sigParam); + + videoURLParam); } } }