[voicerepublic] Remove hardcoded paths to media files
[youtube-dl] / youtube_dl / extractor / voicerepublic.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_request
8 from ..utils import ExtractorError
9
10
11 class VoiceRepublicIE(InfoExtractor):
12     _VALID_URL = r'https?://voicerepublic\.com/talks/(?P<id>[0-9a-z-]+)'
13     _TEST = {
14         'url': 'https://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
15         'md5': '0554a24d1657915aa8e8f84e15dc9353',
16         'info_dict': {
17             'id': '2296',
18             'ext': 'm4a',
19             'title': 'Watching the Watchers: Building a Sousveillance State',
20             'thumbnail': 'https://voicerepublic.com/system/flyer/2296.png',
21             'description': 'md5:715ba964958afa2398df615809cfecb1',
22         }
23     }
24
25     def _real_extract(self, url):
26         display_id = self._match_id(url)
27         req = compat_urllib_request.Request(url)
28         # Older versions of Firefox get redirected to an "upgrade browser" page
29         req.add_header('User-Agent', 'youtube-dl')
30         webpage = self._download_webpage(req, display_id)
31         thumbnail = self._og_search_thumbnail(webpage)
32         video_id = self._search_regex(r'/(\d+)\.png', thumbnail, 'id')
33
34         if '<a>Queued for processing, please stand by...</a>' in webpage:
35             raise ExtractorError('Audio is still queued for processing')
36
37         formats = [{
38             'url': 'https://voicerepublic.com' + path,
39             'ext': ext,
40             'format_id': ext,
41             'vcodec': 'none',
42         } for ext, path in re.findall(r"data-([^=]+)='(/[^']+\.\1)'", webpage)]
43         self._sort_formats(formats)
44
45         return {
46             'id': video_id,
47             'title': self._og_search_title(webpage),
48             'formats': formats,
49             'url': self._og_search_url(webpage),
50             'thumbnail': thumbnail,
51             'description': self._og_search_description(webpage),
52         }