1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-12-05 10:05:35 +08:00
youtube-dl/youtube_dl/extractor/mpora.py

65 lines
1.9 KiB
Python
Raw Normal View History

2014-01-07 15:07:46 +08:00
from __future__ import unicode_literals
import json
import re
from .common import InfoExtractor
2014-04-10 20:10:03 +08:00
from ..utils import int_or_none
2014-01-07 15:07:46 +08:00
class MporaIE(InfoExtractor):
_VALID_URL = r'^https?://(www\.)?mpora\.(?:com|de)/videos/(?P<id>[^?#/]+)'
2014-01-07 16:45:58 +08:00
IE_NAME = 'MPORA'
2014-01-07 15:07:46 +08:00
_TEST = {
'url': 'http://mpora.de/videos/AAdo8okx4wiz/embed?locale=de',
'file': 'AAdo8okx4wiz.mp4',
'md5': 'a7a228473eedd3be741397cf452932eb',
'info_dict': {
'title': 'Katy Curd - Winter in the Forest',
'duration': 416,
2014-04-10 20:10:03 +08:00
'uploader': 'Peter Newman Media',
2014-01-07 15:07:46 +08:00
},
}
def _real_extract(self, url):
m = re.match(self._VALID_URL, url)
video_id = m.group('id')
webpage = self._download_webpage(url, video_id)
data_json = self._search_regex(
2014-07-09 20:12:42 +08:00
r"new FM\.Player\('[^']+',\s*(\{.*?)\).player;", webpage, 'json')
2014-01-07 15:07:46 +08:00
data = json.loads(data_json)
2014-01-17 10:59:42 +08:00
uploader = data['info_overlay'].get('username')
2014-01-07 15:07:46 +08: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-24 03:41:03 +08:00
2014-01-07 15:07:46 +08: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,
}