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