]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/podomatic.py
[extractor] Common function `_match_valid_url`
[yt-dlp.git] / yt_dlp / extractor / podomatic.py
1 from __future__ import unicode_literals
2
3 import json
4
5 from .common import InfoExtractor
6 from ..utils import int_or_none
7
8
9 class PodomaticIE(InfoExtractor):
10 IE_NAME = 'podomatic'
11 _VALID_URL = r'''(?x)
12 (?P<proto>https?)://
13 (?:
14 (?P<channel>[^.]+)\.podomatic\.com/entry|
15 (?:www\.)?podomatic\.com/podcasts/(?P<channel_2>[^/]+)/episodes
16 )/
17 (?P<id>[^/?#&]+)
18 '''
19
20 _TESTS = [{
21 'url': 'http://scienceteachingtips.podomatic.com/entry/2009-01-02T16_03_35-08_00',
22 'md5': '84bb855fcf3429e6bf72460e1eed782d',
23 'info_dict': {
24 'id': '2009-01-02T16_03_35-08_00',
25 'ext': 'mp3',
26 'uploader': 'Science Teaching Tips',
27 'uploader_id': 'scienceteachingtips',
28 'title': '64. When the Moon Hits Your Eye',
29 'duration': 446,
30 }
31 }, {
32 'url': 'http://ostbahnhof.podomatic.com/entry/2013-11-15T16_31_21-08_00',
33 'md5': 'd2cf443931b6148e27638650e2638297',
34 'info_dict': {
35 'id': '2013-11-15T16_31_21-08_00',
36 'ext': 'mp3',
37 'uploader': 'Ostbahnhof / Techno Mix',
38 'uploader_id': 'ostbahnhof',
39 'title': 'Einunddreizig',
40 'duration': 3799,
41 }
42 }, {
43 'url': 'https://www.podomatic.com/podcasts/scienceteachingtips/episodes/2009-01-02T16_03_35-08_00',
44 'only_matching': True,
45 }]
46
47 def _real_extract(self, url):
48 mobj = self._match_valid_url(url)
49 video_id = mobj.group('id')
50 channel = mobj.group('channel') or mobj.group('channel_2')
51
52 json_url = (('%s://%s.podomatic.com/entry/embed_params/%s'
53 + '?permalink=true&rtmp=0') %
54 (mobj.group('proto'), channel, video_id))
55 data_json = self._download_webpage(
56 json_url, video_id, 'Downloading video info')
57 data = json.loads(data_json)
58
59 video_url = data['downloadLink']
60 if not video_url:
61 video_url = '%s/%s' % (data['streamer'].replace('rtmp', 'http'), data['mediaLocation'])
62 uploader = data['podcast']
63 title = data['title']
64 thumbnail = data['imageLocation']
65 duration = int_or_none(data.get('length'), 1000)
66
67 return {
68 'id': video_id,
69 'url': video_url,
70 'title': title,
71 'uploader': uploader,
72 'uploader_id': channel,
73 'thumbnail': thumbnail,
74 'duration': duration,
75 }