mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-25 06:15:46 +00:00
[swrmediathek] improve extraction
This commit is contained in:
parent
2365f94412
commit
a9cd1691b2
@ -1,10 +1,12 @@
|
|||||||
# 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 parse_duration
|
from ..utils import (
|
||||||
|
parse_duration,
|
||||||
|
int_or_none,
|
||||||
|
determine_protocol,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SWRMediathekIE(InfoExtractor):
|
class SWRMediathekIE(InfoExtractor):
|
||||||
@ -38,6 +40,7 @@ class SWRMediathekIE(InfoExtractor):
|
|||||||
'uploader': 'SWR Fernsehen',
|
'uploader': 'SWR Fernsehen',
|
||||||
'uploader_id': '990030',
|
'uploader_id': '990030',
|
||||||
},
|
},
|
||||||
|
'_skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink',
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6',
|
'url': 'http://swrmediathek.de/player.htm?show=bba23e10-cb93-11e3-bf7f-0026b975f2e6',
|
||||||
'md5': '4382e4ef2c9d7ce6852535fa867a0dd3',
|
'md5': '4382e4ef2c9d7ce6852535fa867a0dd3',
|
||||||
@ -51,54 +54,62 @@ class SWRMediathekIE(InfoExtractor):
|
|||||||
'upload_date': '20140520',
|
'upload_date': '20140520',
|
||||||
'uploader': 'SWR 2',
|
'uploader': 'SWR 2',
|
||||||
'uploader_id': '284670',
|
'uploader_id': '284670',
|
||||||
}
|
},
|
||||||
|
'_skip': 'redirect to http://swrmediathek.de/index.htm?hinweis=swrlink',
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
video_id = self._match_id(url)
|
||||||
video_id = mobj.group('id')
|
|
||||||
|
|
||||||
video = self._download_json(
|
video = self._download_json(
|
||||||
'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id, video_id, 'Downloading video JSON')
|
'http://swrmediathek.de/AjaxEntry?ekey=%s' % video_id,
|
||||||
|
video_id, 'Downloading video JSON')
|
||||||
|
|
||||||
attr = video['attr']
|
attr = video['attr']
|
||||||
media_type = attr['entry_etype']
|
title = attr['entry_title']
|
||||||
|
media_type = attr.get('entry_etype')
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for entry in video['sub']:
|
for entry in video.get('sub', []):
|
||||||
if entry['name'] != 'entry_media':
|
if entry.get('name') != 'entry_media':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry_attr = entry['attr']
|
entry_attr = entry.get('attr', {})
|
||||||
codec = entry_attr['val0']
|
f_url = entry_attr.get('val2')
|
||||||
quality = int(entry_attr['val1'])
|
if not f_url:
|
||||||
|
continue
|
||||||
fmt = {
|
codec = entry_attr.get('val0')
|
||||||
'url': entry_attr['val2'],
|
if codec == 'm3u8':
|
||||||
'quality': quality,
|
formats.extend(self._extract_m3u8_formats(
|
||||||
}
|
f_url, video_id, 'mp4', 'm3u8_native',
|
||||||
|
m3u8_id='hls', fatal=False))
|
||||||
if media_type == 'Video':
|
elif codec == 'f4m':
|
||||||
fmt.update({
|
formats.extend(self._extract_f4m_formats(
|
||||||
'format_note': ['144p', '288p', '544p', '720p'][quality - 1],
|
f_url + '?hdcore=3.7.0', video_id,
|
||||||
'vcodec': codec,
|
f4m_id='hds', fatal=False))
|
||||||
|
else:
|
||||||
|
formats.append({
|
||||||
|
'format_id': determine_protocol({'url': f_url}),
|
||||||
|
'url': f_url,
|
||||||
|
'quality': int_or_none(entry_attr.get('val1')),
|
||||||
|
'vcodec': codec if media_type == 'Video' else 'none',
|
||||||
|
'acodec': codec if media_type == 'Audio' else None,
|
||||||
})
|
})
|
||||||
elif media_type == 'Audio':
|
|
||||||
fmt.update({
|
|
||||||
'acodec': codec,
|
|
||||||
})
|
|
||||||
formats.append(fmt)
|
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
upload_date = None
|
||||||
|
entry_pdatet = attr.get('entry_pdatet')
|
||||||
|
if entry_pdatet:
|
||||||
|
upload_date = entry_pdatet[:-4]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': attr['entry_title'],
|
'title': title,
|
||||||
'description': attr['entry_descl'],
|
'description': attr.get('entry_descl'),
|
||||||
'thumbnail': attr['entry_image_16_9'],
|
'thumbnail': attr.get('entry_image_16_9'),
|
||||||
'duration': parse_duration(attr['entry_durat']),
|
'duration': parse_duration(attr.get('entry_durat')),
|
||||||
'upload_date': attr['entry_pdatet'][:-4],
|
'upload_date': upload_date,
|
||||||
'uploader': attr['channel_title'],
|
'uploader': attr.get('channel_title'),
|
||||||
'uploader_id': attr['channel_idkey'],
|
'uploader_id': attr.get('channel_idkey'),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user