]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/voicerepublic.py
debian/copyright: use spaces rather than tabs to start continuation lines.
[youtubedl] / youtube_dl / extractor / voicerepublic.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_str
5 from ..utils import (
6 ExtractorError,
7 determine_ext,
8 int_or_none,
9 urljoin,
10 )
11
12
13 class VoiceRepublicIE(InfoExtractor):
14 _VALID_URL = r'https?://voicerepublic\.com/(?:talks|embed)/(?P<id>[0-9a-z-]+)'
15 _TESTS = [{
16 'url': 'http://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
17 'md5': 'b9174d651323f17783000876347116e3',
18 'info_dict': {
19 'id': '2296',
20 'display_id': 'watching-the-watchers-building-a-sousveillance-state',
21 'ext': 'm4a',
22 'title': 'Watching the Watchers: Building a Sousveillance State',
23 'description': 'Secret surveillance programs have metadata too. The people and companies that operate secret surveillance programs can be surveilled.',
24 'duration': 1556,
25 'view_count': int,
26 }
27 }, {
28 'url': 'http://voicerepublic.com/embed/watching-the-watchers-building-a-sousveillance-state',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 display_id = self._match_id(url)
34
35 webpage = self._download_webpage(url, display_id)
36
37 if '>Queued for processing, please stand by...<' in webpage:
38 raise ExtractorError(
39 'Audio is still queued for processing', expected=True)
40
41 talk = self._parse_json(self._search_regex(
42 r'initialSnapshot\s*=\s*({.+?});',
43 webpage, 'talk'), display_id)['talk']
44 title = talk['title']
45 formats = [{
46 'url': urljoin(url, talk_url),
47 'format_id': format_id,
48 'ext': determine_ext(talk_url) or format_id,
49 'vcodec': 'none',
50 } for format_id, talk_url in talk['media_links'].items()]
51 self._sort_formats(formats)
52
53 return {
54 'id': compat_str(talk.get('id') or display_id),
55 'display_id': display_id,
56 'title': title,
57 'description': talk.get('teaser'),
58 'thumbnail': talk.get('image_url'),
59 'duration': int_or_none(talk.get('archived_duration')),
60 'view_count': int_or_none(talk.get('play_count')),
61 'formats': formats,
62 }