[streamango] Improve extraction (closes #12643)

This commit is contained in:
Sergey M․ 2017-04-15 21:50:15 +07:00
parent 4db79fa1bc
commit 8068296276
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -1,11 +1,18 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
determine_ext,
int_or_none,
js_to_json,
)
class StreamangoIE(InfoExtractor): class StreamangoIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?streamango\.com/(?:f|embed)/(?P<id>.+?)/(?:.+)' _VALID_URL = r'https?://(?:www\.)?streamango\.com/(?:f|embed)/(?P<id>[^/?#&]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4', 'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4',
'md5': 'e992787515a182f55e38fc97588d802a', 'md5': 'e992787515a182f55e38fc97588d802a',
@ -13,7 +20,6 @@ class StreamangoIE(InfoExtractor):
'id': 'clapasobsptpkdfe', 'id': 'clapasobsptpkdfe',
'ext': 'mp4', 'ext': 'mp4',
'title': '20170315_150006.mp4', 'title': '20170315_150006.mp4',
'url': r're:https://streamango\.com/v/d/clapasobsptpkdfe~[0-9]{10}~(?:[0-9]+\.){3}[0-9]+~.{8}/720',
} }
}, { }, {
'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4', 'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
@ -21,29 +27,33 @@ class StreamangoIE(InfoExtractor):
}] }]
def _real_extract(self, url): def _real_extract(self, url):
def extract_url(urltype):
return self._search_regex(
r'type\s*:\s*["\']{}["\']\s*,\s*src\s*:\s*["\'](?P<url>.+?)["\'].*'.format(urltype),
webpage, 'video URL', group='url')
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
title = self._og_search_title(webpage) title = self._og_search_title(webpage)
url = 'https:' + extract_url('video/mp4')
dashurl = extract_url(r'application/dash\+xml')
formats = [{
'url': url,
'ext': 'mp4',
'width': 1280,
'height': 720,
'format_id': 'mp4',
}]
formats = []
for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage):
video = self._parse_json(
format_, video_id, transform_source=js_to_json, fatal=False)
if not video:
continue
src = video.get('src')
if not src:
continue
ext = determine_ext(src, default_ext=None)
if video.get('type') == 'application/dash+xml' or ext == 'mpd':
formats.extend(self._extract_mpd_formats( formats.extend(self._extract_mpd_formats(
dashurl, video_id, mpd_id='dash', fatal=False)) src, video_id, mpd_id='dash', fatal=False))
else:
formats.append({
'url': src,
'ext': ext or 'mp4',
'width': int_or_none(video.get('width')),
'height': int_or_none(video.get('height')),
'tbr': int_or_none(video.get('bitrate')),
})
self._sort_formats(formats) self._sort_formats(formats)
return { return {