]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/voicerepublic.py
Rename compat_urllib_request_Request to sanitized_Request and move to utils
[yt-dlp.git] / youtube_dl / extractor / voicerepublic.py
CommitLineData
c6ddbdb6
D
1from __future__ import unicode_literals
2
28ebef0b
D
3import re
4
c6ddbdb6 5from .common import InfoExtractor
a6762c4a
S
6from ..compat import (
7 compat_urllib_request,
8 compat_urlparse,
9)
10from ..utils import (
11 ExtractorError,
12 determine_ext,
13 int_or_none,
14)
c6ddbdb6
D
15
16
17class VoiceRepublicIE(InfoExtractor):
a6762c4a
S
18 _VALID_URL = r'https?://voicerepublic\.com/(?:talks|embed)/(?P<id>[0-9a-z-]+)'
19 _TESTS = [{
20 'url': 'http://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
c6ddbdb6
D
21 'md5': '0554a24d1657915aa8e8f84e15dc9353',
22 'info_dict': {
23 'id': '2296',
a6762c4a 24 'display_id': 'watching-the-watchers-building-a-sousveillance-state',
c6ddbdb6
D
25 'ext': 'm4a',
26 'title': 'Watching the Watchers: Building a Sousveillance State',
c6ddbdb6 27 'description': 'md5:715ba964958afa2398df615809cfecb1',
a6762c4a
S
28 'thumbnail': 're:^https?://.*\.(?:png|jpg)$',
29 'duration': 1800,
30 'view_count': int,
c6ddbdb6 31 }
a6762c4a
S
32 }, {
33 'url': 'http://voicerepublic.com/embed/watching-the-watchers-building-a-sousveillance-state',
34 'only_matching': True,
35 }]
c6ddbdb6
D
36
37 def _real_extract(self, url):
38 display_id = self._match_id(url)
a6762c4a
S
39
40 req = compat_urllib_request.Request(
41 compat_urlparse.urljoin(url, '/talks/%s' % display_id))
c6ddbdb6
D
42 # Older versions of Firefox get redirected to an "upgrade browser" page
43 req.add_header('User-Agent', 'youtube-dl')
44 webpage = self._download_webpage(req, display_id)
c6ddbdb6 45
a6762c4a
S
46 if '>Queued for processing, please stand by...<' in webpage:
47 raise ExtractorError(
48 'Audio is still queued for processing', expected=True)
f03a8a3c 49
370b39e8
S
50 config = self._search_regex(
51 r'(?s)return ({.+?});\s*\n', webpage,
52 'data', default=None)
53 data = self._parse_json(config, display_id, fatal=False) if config else None
a6762c4a
S
54 if data:
55 title = data['title']
56 description = data.get('teaser')
57 talk_id = data.get('talk_id') or display_id
58 talk = data['talk']
59 duration = int_or_none(talk.get('duration'))
60 formats = [{
61 'url': compat_urlparse.urljoin(url, talk_url),
62 'format_id': format_id,
63 'ext': determine_ext(talk_url) or format_id,
64 'vcodec': 'none',
65 } for format_id, talk_url in talk['links'].items()]
66 else:
67 title = self._og_search_title(webpage)
68 description = self._html_search_regex(
69 r"(?s)<div class='talk-teaser'[^>]*>(.+?)</div>",
70 webpage, 'description', fatal=False)
71 talk_id = self._search_regex(
72 [r"id='jc-(\d+)'", r"data-shareable-id='(\d+)'"],
73 webpage, 'talk id', default=None) or display_id
74 duration = None
370b39e8
S
75 player = self._search_regex(
76 r"class='vr-player jp-jplayer'([^>]+)>", webpage, 'player')
a6762c4a
S
77 formats = [{
78 'url': compat_urlparse.urljoin(url, talk_url),
79 'format_id': format_id,
80 'ext': determine_ext(talk_url) or format_id,
81 'vcodec': 'none',
370b39e8 82 } for format_id, talk_url in re.findall(r"data-([^=]+)='([^']+)'", player)]
f03a8a3c 83 self._sort_formats(formats)
c6ddbdb6 84
a6762c4a
S
85 thumbnail = self._og_search_thumbnail(webpage)
86 view_count = int_or_none(self._search_regex(
87 r"class='play-count[^']*'>\s*(\d+) plays",
88 webpage, 'play count', fatal=False))
89
c6ddbdb6 90 return {
a6762c4a
S
91 'id': talk_id,
92 'display_id': display_id,
93 'title': title,
94 'description': description,
c6ddbdb6 95 'thumbnail': thumbnail,
a6762c4a
S
96 'duration': duration,
97 'view_count': view_count,
98 'formats': formats,
c6ddbdb6 99 }