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