1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-30 11:43:00 +08:00
youtube-dl/youtube_dl/extractor/podomatic.py

70 lines
2.3 KiB
Python
Raw Normal View History

2014-02-25 00:31:09 +08:00
from __future__ import unicode_literals
2013-11-29 10:33:25 +08:00
import json
import re
from .common import InfoExtractor
2014-02-25 00:31:09 +08:00
from ..utils import int_or_none
2013-11-29 10:33:25 +08:00
2014-11-24 03:41:03 +08:00
2013-11-29 10:33:25 +08:00
class PodomaticIE(InfoExtractor):
IE_NAME = 'podomatic'
_VALID_URL = r'^(?P<proto>https?)://(?P<channel>[^.]+)\.podomatic\.com/entry/(?P<id>[^?]+)'
_TESTS = [
{
'url': 'http://scienceteachingtips.podomatic.com/entry/2009-01-02T16_03_35-08_00',
'md5': '84bb855fcf3429e6bf72460e1eed782d',
'info_dict': {
'id': '2009-01-02T16_03_35-08_00',
'ext': 'mp3',
'uploader': 'Science Teaching Tips',
'uploader_id': 'scienceteachingtips',
'title': '64. When the Moon Hits Your Eye',
'duration': 446,
}
},
{
'url': 'http://ostbahnhof.podomatic.com/entry/2013-11-15T16_31_21-08_00',
'md5': 'd2cf443931b6148e27638650e2638297',
'info_dict': {
'id': '2013-11-15T16_31_21-08_00',
'ext': 'mp3',
'uploader': 'Ostbahnhof / Techno Mix',
'uploader_id': 'ostbahnhof',
'title': 'Einunddreizig',
'duration': 3799,
}
},
]
2013-11-29 10:33:25 +08:00
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
channel = mobj.group('channel')
json_url = (('%s://%s.podomatic.com/entry/embed_params/%s' +
'?permalink=true&rtmp=0') %
(mobj.group('proto'), channel, video_id))
data_json = self._download_webpage(
json_url, video_id, 'Downloading video info')
2013-11-29 10:33:25 +08:00
data = json.loads(data_json)
video_url = data['downloadLink']
if not video_url:
video_url = '%s/%s' % (data['streamer'].replace('rtmp', 'http'), data['mediaLocation'])
2013-11-29 10:33:25 +08:00
uploader = data['podcast']
title = data['title']
thumbnail = data['imageLocation']
2014-02-25 00:31:09 +08:00
duration = int_or_none(data.get('length'), 1000)
2013-11-29 10:33:25 +08:00
return {
'id': video_id,
'url': video_url,
'title': title,
'uploader': uploader,
'uploader_id': channel,
'thumbnail': thumbnail,
'duration': duration,
}