1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2025-02-17 01:17:54 +01:00

fixes after first review

This commit is contained in:
bato3 2018-07-14 00:32:41 +02:00
parent 0f70ac8403
commit ccf6a90ba8

View File

@ -9,6 +9,8 @@ from ..utils import (
decode_packed_codes,
get_element_by_class,
get_element_by_id,
int_or_none,
float_or_none,
parse_filesize,
strip_or_none,
)
@ -20,25 +22,19 @@ class Mp4UploadIE(InfoExtractor):
_TESTS = [{
'url': 'http://www.mp4upload.com/e52ycvdl4x29',
'md5': '09780a74b0de79ada5f9a8955f0704fc',
'info_dict': {
'id': 'e52ycvdl4x29',
'ext': 'mp4',
'title': '橋本潮 - ロマンティックあげるよ.mp4',
'timestamp': 1467471956,
'thumbnail': r're:^https?://.*\.jpg$',
'vcodec': 'ffh264',
'width': 454,
'height': 360,
'fps': 29.970,
'acodec': 'ffaac',
'asr': 44100,
'abr': 96,
# Something adds this to the _real_extract return value, and the test runner expects it present.
# Should probably be autocalculated from the timestamp instead, just like _real_extract.
'upload_date': '20160702',
},
}, {
@ -64,13 +60,6 @@ class Mp4UploadIE(InfoExtractor):
'id': video_id,
}
file_info = re.findall(
r'>(?P<label>[^<:]+):</span><span>(?P<value>[^<]+)</span></li>',
get_element_by_class('fileinfo', webpage)
)
if not file_info:
raise ExtractorError('I can\'t find file info', video_id=video_id)
embedpage = self._download_webpage(embed_url, video_id, note='Downloading embed webpage')
# It contains only `source url` and `thumbnail`
@ -85,34 +74,41 @@ class Mp4UploadIE(InfoExtractor):
info_dict['thumbnail'] = poor_info_dict.get('thumbnail')
_f = {
'url': poor_info_dict.get('formats')[0].get('url'),
'ext': poor_info_dict.get('formats')[0].get('ext'),
'url': poor_info_dict.get('formats', [{}])[0].get('url'),
'ext': poor_info_dict.get('formats', [{}])[0].get('ext'),
'format_id': '1',
}
for info in file_info:
if info[0] == 'Codec':
_f['vcodec'] = info[1]
file_info = re.findall(
r'>(?P<label>[^<:]+):</span><span>(?P<value>[^<]+)</span></li>',
get_element_by_class('fileinfo', webpage)
)
if file_info:
for info in file_info:
if info[0] == 'Codec':
_f['vcodec'] = info[1]
elif info[0] == 'Resolution':
_f['resolution'] = info[1].replace(' ', '')
resmatch = re.search(r'(?P<width>[\d]+) x (?P<height>[\d]+)', info[1])
if resmatch:
_f['width'] = int(resmatch.group('width'))
_f['height'] = int(resmatch.group('height'))
elif info[0] == 'Resolution':
_f['resolution'] = info[1].replace(' ', '')
resmatch = re.search(r'(?P<width>\d+)\s*x\s*(?P<height>\d+)', info[1])
if resmatch:
_f['width'] = int(resmatch.group('width'))
_f['height'] = int(resmatch.group('height'))
elif info[0] == 'Framerate' and info[1] != '1000.000 fps':
_f['fps'] = float(info[1].replace(' fps', ''))
elif info[0] == 'Framerate':
fps = float_or_none(re.sub(r'[^\d\.]+', '', info[1]))
if fps < 100:
_f['fps'] = fps
elif info[0] == 'Audio info':
audmatch = re.search(r'(?P<acodec>.+?), (?P<abr>[\d]+) kbps, (?P<asr>[\d]+) Hz', info[1])
if audmatch:
_f['acodec'] = audmatch.group('acodec')
_f['abr'] = int(audmatch.group('abr'))
_f['asr'] = int(audmatch.group('asr'))
elif info[0] == 'Audio info':
audmatch = re.search(r'(?P<acodec>.+?), (?P<abr>\d+) kbps, (?P<asr>\d+) Hz', info[1])
if audmatch:
_f['acodec'] = audmatch.group('acodec')
_f['abr'] = int(audmatch.group('abr'))
_f['asr'] = int(audmatch.group('asr'))
elif info[0] == 'Bitrate':
_f['vbr'] = int(info[1].replace(' Kbps', ''))
elif info[0] == 'Bitrate':
_f['vbr'] = int_or_none(re.sub(r'\D+', '', info[1]))
_f['filesize_approx'] = parse_filesize(
self._html_search_regex(
@ -122,11 +118,14 @@ class Mp4UploadIE(InfoExtractor):
)
info_dict['formats'] = [_f]
# can't use _html_search_regex, there's data both inside and outside a bold tag and I need it all
date_raw = self._search_regex(r'Uploaded on(.+?)</div>', webpage, 'timestamp', fatal=False, flags=re.DOTALL)
if date_raw:
date_raw = re.sub(r'<[^>]+>', '', date_raw)
date_raw = re.sub(r'[\s]+', ' ', date_raw)
info_dict['timestamp'] = time.mktime(time.strptime(date_raw, ' %Y-%m-%d %H:%M:%S '))
try:
info_dict['timestamp'] = time.mktime(time.strptime(
re.sub(r'[^\d\-\:]+', '', date_raw),
'%Y-%m-%d%H:%M:%S'
))
except ValueError:
pass
return info_dict