[extractor/generic] Detect m3u playlists served without proper Content-Type
authorSergey M․ <dstftw@gmail.com>
Fri, 18 Mar 2016 16:45:28 +0000 (22:45 +0600)
committerSergey M․ <dstftw@gmail.com>
Fri, 18 Mar 2016 16:45:28 +0000 (22:45 +0600)
youtube_dl/extractor/generic.py

index 5649e26daed694a0e5cb5733f92ed768012ac80d..24d43a247b6d67ad10c5ba81db46630ff25ecdfb 100644 (file)
@@ -1299,9 +1299,15 @@ class GenericIE(InfoExtractor):
             request.add_header('Accept-Encoding', '*')
             full_response = self._request_webpage(request, video_id)
 
+        first_bytes = full_response.read(512)
+
+        # Is it an M3U playlist?
+        if first_bytes.startswith('#EXTM3U'):
+            info_dict['formats'] = self._extract_m3u8_formats(url, video_id, 'mp4')
+            return info_dict
+
         # Maybe it's a direct link to a video?
         # Be careful not to download the whole thing!
-        first_bytes = full_response.read(512)
         if not is_html(first_bytes):
             self._downloader.report_warning(
                 'URL could be a direct video link, returning it as such.')