1
0
Fork 0
mirror of https://gitlab.com/dstftw/youtube-dl.git synced 2020-11-16 09:42:26 +00:00

[dvtv] PEP8 and correct format sorting (#4502)

This commit is contained in:
Philipp Hagemeister 2014-12-17 23:18:06 +01:00
parent edf41477f0
commit b9465395cb

View file

@ -2,62 +2,62 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re
import json
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError, js_to_json,
js_to_json, unescapeHTML
unescapeHTML
) )
class DVTVIE(InfoExtractor): class DVTVIE(InfoExtractor):
IE_NAME = 'dvtv' IE_NAME = 'dvtv'
IE_DESC = 'http://video.aktualne.cz/dvtv/' IE_DESC = 'http://video.aktualne.cz/dvtv/'
_VALID_URL = r'http://video\.aktualne\.cz/dvtv/(?P<id>[a-z0-9-]+/r~[0-9a-f]{32})/?' _VALID_URL = r'http://video\.aktualne\.cz/dvtv/(?P<id>[a-z0-9-]+/r~[0-9a-f]{32})/?'
_TESTS = [{ _TESTS = [{
'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/', 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
'md5': '75800f964fa0f82939a2914563301f72', 'md5': '75800f964fa0f82939a2914563301f72',
'info_dict': { 'info_dict': {
'id': 'e5efe9ca855511e4833a0025900fea04', 'id': 'e5efe9ca855511e4833a0025900fea04',
'ext': 'webm', 'ext': 'webm',
'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně' 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně'
} }
}, { }, {
'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/', 'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/',
'md5': 'd50455195a67a94c57f931360cc68a1b', 'md5': '6388f1941b48537dbd28791f712af8bf',
'info_dict': { 'info_dict': {
'id': '82ed4322849211e4a10c0025900fea04', 'id': '82ed4322849211e4a10c0025900fea04',
'ext': 'webm', 'ext': 'mp4',
'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala' 'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala'
} }
}] }]
def _real_extract(self, url): def _real_extract(self, 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)
code = self._search_regex(r'embedData[0-9a-f]{32}\[\'asset\'\] = (\{.+?\});', webpage, 'video JSON', flags=re.DOTALL) code = self._search_regex(
payload = self._parse_json(code, video_id, transform_source=js_to_json) r'(?s)embedData[0-9a-f]{32}\[\'asset\'\] = (\{.+?\});',
formats = [] webpage, 'video JSON')
for source in payload['sources']: payload = self._parse_json(code, video_id, transform_source=js_to_json)
formats.append({ formats = []
'url': source['file'], for source in payload['sources']:
'ext': source['type'][6:], ext = source['type'][6:]
'format': '%s %s' % (source['type'][6:], source['label']), formats.append({
'format_id': '%s-%s' % (source['type'][6:], source['label']), 'url': source['file'],
'resolution': source['label'], 'ext': ext,
'fps': 25, 'format': '%s %s' % (ext, source['label']),
'preference': -1 if source['type'][6:] == 'mp4' and source['label'] == '720p' else -2 'format_id': '%s-%s' % (ext, source['label']),
}) 'height': int(source['label'].rstrip('p')),
'fps': 25,
})
self._sort_formats(formats)
return { return {
'id': video_id[-32:], 'id': video_id[-32:],
'display_id': video_id[:-35], 'display_id': video_id[:-35],
'title': unescapeHTML(payload['title']), 'title': unescapeHTML(payload['title']),
'thumbnail': 'http:%s' % payload['image'], 'thumbnail': 'http:%s' % payload['image'],
'formats': formats 'formats': formats
} }