ffafd23800f49de2bc7987f3d63c9b5ab2104b58
[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 class PodomaticIE(InfoExtractor):
10     IE_NAME = 'podomatic'
11     _VALID_URL = r'^(?P<proto>https?)://(?P<channel>[^.]+)\.podomatic\.com/entry/(?P<id>[^?]+)'
12
13     _TESTS = [
14         {
15             'url': 'http://scienceteachingtips.podomatic.com/entry/2009-01-02T16_03_35-08_00',
16             'md5': '84bb855fcf3429e6bf72460e1eed782d',
17             'info_dict': {
18                 'id': '2009-01-02T16_03_35-08_00',
19                 'ext': 'mp3',
20                 'uploader': 'Science Teaching Tips',
21                 'uploader_id': 'scienceteachingtips',
22                 'title': '64.  When the Moon Hits Your Eye',
23                 'duration': 446,
24             }
25         },
26         {
27             'url': 'http://ostbahnhof.podomatic.com/entry/2013-11-15T16_31_21-08_00',
28             'md5': 'd2cf443931b6148e27638650e2638297',
29             'info_dict': {
30                 'id': '2013-11-15T16_31_21-08_00',
31                 'ext': 'mp3',
32                 'uploader': 'Ostbahnhof / Techno Mix',
33                 'uploader_id': 'ostbahnhof',
34                 'title': 'Einunddreizig',
35                 'duration': 3799,
36             }
37         },
38     ]
39
40     def _real_extract(self, url):
41         mobj = re.match(self._VALID_URL, url)
42         video_id = mobj.group('id')
43         channel = mobj.group('channel')
44
45         json_url = (('%s://%s.podomatic.com/entry/embed_params/%s' +
46                      '?permalink=true&rtmp=0') %
47                     (mobj.group('proto'), channel, video_id))
48         data_json = self._download_webpage(
49             json_url, video_id, 'Downloading video info')
50         data = json.loads(data_json)
51
52         video_url = data['downloadLink']
53         if not video_url:
54             video_url = '%s/%s' % (data['streamer'].replace('rtmp', 'http'), data['mediaLocation'])
55         uploader = data['podcast']
56         title = data['title']
57         thumbnail = data['imageLocation']
58         duration = int_or_none(data.get('length'), 1000)
59
60         return {
61             'id': video_id,
62             'url': video_url,
63             'title': title,
64             'uploader': uploader,
65             'uploader_id': channel,
66             'thumbnail': thumbnail,
67             'duration': duration,
68         }