[voicerepublic] Add new extractor
[youtube-dl] / youtube_dl / extractor / voicerepublic.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6 from ..compat import (
7     compat_urllib_request,
8 )
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             'creator': 'M. C. McGrath',
23         }
24     }
25
26     def _real_extract(self, url):
27         display_id = self._match_id(url)
28         req = compat_urllib_request.Request(url)
29         # Older versions of Firefox get redirected to an "upgrade browser" page
30         req.add_header('User-Agent', 'youtube-dl')
31         webpage = self._download_webpage(req, display_id)
32         thumbnail = self._og_search_thumbnail(webpage)
33         video_id = self._search_regex(r'/(\d+)\.png', thumbnail, 'id')
34
35         if '<div class=\'vr-player jp-jplayer\'' in webpage:
36             formats = [{
37                 'url': 'https://voicerepublic.com/vrmedia/{}-clean.{}'.format(video_id, ext),
38                 'ext': ext,
39                 'format_id': ext,
40                 'vcodec': 'none',
41             } for ext in ['m4a', 'mp3', 'ogg']]
42             self._sort_formats(formats)
43         else:
44             # Audio is still queued for processing
45             formats = []
46
47         return {
48             'id': video_id,
49             'title': self._og_search_title(webpage),
50             'formats': formats,
51             'url': self._og_search_url(webpage),
52             'thumbnail': thumbnail,
53             'description': self._og_search_description(webpage),
54             'creator': self._search_regex(r'<meta content=\'([^\']*?)\' name=\'author\'>', webpage, 'author', fatal=False),
55         }