yt-dlp/youtube_dl/extractor/mpora.py

63 lines
2.0 KiB
Python
Raw Normal View History

2014-01-07 02:07:46 -05:00
from __future__ import unicode_literals
from .common import InfoExtractor
2014-04-10 08:10:03 -04:00
from ..utils import int_or_none
2014-01-07 02:07:46 -05:00
class MporaIE(InfoExtractor):
2015-02-26 10:16:35 -05:00
_VALID_URL = r'https?://(?:www\.)?mpora\.(?:com|de)/videos/(?P<id>[^?#/]+)'
2014-01-07 03:45:58 -05:00
IE_NAME = 'MPORA'
2014-01-07 02:07:46 -05:00
_TEST = {
'url': 'http://mpora.de/videos/AAdo8okx4wiz/embed?locale=de',
'md5': 'a7a228473eedd3be741397cf452932eb',
'info_dict': {
2015-02-01 05:58:37 -05:00
'id': 'AAdo8okx4wiz',
'ext': 'mp4',
2014-01-07 02:07:46 -05:00
'title': 'Katy Curd - Winter in the Forest',
'duration': 416,
2014-04-10 08:10:03 -04:00
'uploader': 'Peter Newman Media',
2014-01-07 02:07:46 -05:00
},
}
def _real_extract(self, url):
2015-02-01 05:58:37 -05:00
video_id = self._match_id(url)
2014-01-07 02:07:46 -05:00
webpage = self._download_webpage(url, video_id)
2015-02-01 05:58:37 -05:00
2014-01-07 02:07:46 -05:00
data_json = self._search_regex(
2015-02-26 10:10:49 -05:00
[r"new FM\.Player\('[^']+',\s*(\{.*?)\).player;",
r"new\s+FM\.Kaltura\.Player\('[^']+'\s*,\s*({.+?})\);"],
webpage, 'json')
2015-02-01 05:58:37 -05:00
data = self._parse_json(data_json, video_id)
2014-01-07 02:07:46 -05:00
2014-01-16 21:59:42 -05:00
uploader = data['info_overlay'].get('username')
2014-01-07 02:07:46 -05:00
duration = data['video']['duration'] // 1000
thumbnail = data['video']['encodings']['sd']['poster']
title = data['info_overlay']['title']
formats = []
for encoding_id, edata in data['video']['encodings'].items():
for src in edata['sources']:
width_str = self._search_regex(
r'_([0-9]+)\.[a-zA-Z0-9]+$', src['src'],
False, default=None)
vcodec = src['type'].partition('/')[2]
2014-11-23 14:41:03 -05:00
2014-01-07 02:07:46 -05:00
formats.append({
'format_id': encoding_id + '-' + vcodec,
'url': src['src'],
'vcodec': vcodec,
'width': int_or_none(width_str),
})
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'formats': formats,
'uploader': uploader,
'duration': duration,
'thumbnail': thumbnail,
}