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