Merge remote-tracking branch 'origin/master'
[youtube-dl] / youtube_dl / extractor / podomatic.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import int_or_none
8
9
10 class PodomaticIE(InfoExtractor):
11     IE_NAME = 'podomatic'
12     _VALID_URL = r'^(?P<proto>https?)://(?P<channel>[^.]+)\.podomatic\.com/entry/(?P<id>[^?]+)'
13
14     _TEST = {
15         "url": "http://scienceteachingtips.podomatic.com/entry/2009-01-02T16_03_35-08_00",
16         "file": "2009-01-02T16_03_35-08_00.mp3",
17         "md5": "84bb855fcf3429e6bf72460e1eed782d",
18         "info_dict": {
19             "uploader": "Science Teaching Tips",
20             "uploader_id": "scienceteachingtips",
21             "title": "64.  When the Moon Hits Your Eye",
22             "duration": 446,
23         }
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('id')
29         channel = mobj.group('channel')
30
31         json_url = (('%s://%s.podomatic.com/entry/embed_params/%s' +
32                      '?permalink=true&rtmp=0') %
33                     (mobj.group('proto'), channel, video_id))
34         data_json = self._download_webpage(
35             json_url, video_id, note=u'Downloading video info')
36         data = json.loads(data_json)
37
38         video_url = data['downloadLink']
39         uploader = data['podcast']
40         title = data['title']
41         thumbnail = data['imageLocation']
42         duration = int_or_none(data.get('length'), 1000)
43
44         return {
45             'id': video_id,
46             'url': video_url,
47             'title': title,
48             'uploader': uploader,
49             'uploader_id': channel,
50             'thumbnail': thumbnail,
51             'duration': duration,
52         }