mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 10:31:29 +00:00
[CDA] Add more formats (#805)
Fixes: #791, https://github.com/ytdl-org/youtube-dl/issues/29844 Authored by: u-spec-png
This commit is contained in:
parent
2ee6389bef
commit
05664a2f7b
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
parse_duration,
|
parse_duration,
|
||||||
random_birthday,
|
random_birthday,
|
||||||
urljoin,
|
urljoin,
|
||||||
|
try_get,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +40,8 @@ class CDAIE(InfoExtractor):
|
||||||
'average_rating': float,
|
'average_rating': float,
|
||||||
'duration': 39,
|
'duration': 39,
|
||||||
'age_limit': 0,
|
'age_limit': 0,
|
||||||
|
'upload_date': '20160221',
|
||||||
|
'timestamp': 1456078244,
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.cda.pl/video/57413289',
|
'url': 'http://www.cda.pl/video/57413289',
|
||||||
|
@ -143,7 +147,7 @@ def decrypt_file(a):
|
||||||
b = []
|
b = []
|
||||||
for c in a:
|
for c in a:
|
||||||
f = compat_ord(c)
|
f = compat_ord(c)
|
||||||
b.append(compat_chr(33 + (f + 14) % 94) if 33 <= f and 126 >= f else compat_chr(f))
|
b.append(compat_chr(33 + (f + 14) % 94) if 33 <= f <= 126 else compat_chr(f))
|
||||||
a = ''.join(b)
|
a = ''.join(b)
|
||||||
a = a.replace('.cda.mp4', '')
|
a = a.replace('.cda.mp4', '')
|
||||||
for p in ('.2cda.pl', '.3cda.pl'):
|
for p in ('.2cda.pl', '.3cda.pl'):
|
||||||
|
@ -173,18 +177,34 @@ def extract_format(page, version):
|
||||||
video['file'] = video['file'].replace('adc.mp4', '.mp4')
|
video['file'] = video['file'].replace('adc.mp4', '.mp4')
|
||||||
elif not video['file'].startswith('http'):
|
elif not video['file'].startswith('http'):
|
||||||
video['file'] = decrypt_file(video['file'])
|
video['file'] = decrypt_file(video['file'])
|
||||||
f = {
|
video_quality = video.get('quality')
|
||||||
|
qualities = video.get('qualities', {})
|
||||||
|
video_quality = next((k for k, v in qualities.items() if v == video_quality), video_quality)
|
||||||
|
info_dict['formats'].append({
|
||||||
'url': video['file'],
|
'url': video['file'],
|
||||||
}
|
'format_id': video_quality,
|
||||||
m = re.search(
|
'height': int_or_none(video_quality[:-1]),
|
||||||
r'<a[^>]+data-quality="(?P<format_id>[^"]+)"[^>]+href="[^"]+"[^>]+class="[^"]*quality-btn-active[^"]*">(?P<height>[0-9]+)p',
|
})
|
||||||
page)
|
for quality, cda_quality in qualities.items():
|
||||||
if m:
|
if quality == video_quality:
|
||||||
f.update({
|
continue
|
||||||
'format_id': m.group('format_id'),
|
data = {'jsonrpc': '2.0', 'method': 'videoGetLink', 'id': 2,
|
||||||
'height': int(m.group('height')),
|
'params': [video_id, cda_quality, video.get('ts'), video.get('hash2'), {}]}
|
||||||
})
|
data = json.dumps(data).encode('utf-8')
|
||||||
info_dict['formats'].append(f)
|
video_url = self._download_json(
|
||||||
|
f'https://www.cda.pl/video/{video_id}', video_id, headers={
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest'
|
||||||
|
}, data=data, note=f'Fetching {quality} url',
|
||||||
|
errnote=f'Failed to fetch {quality} url', fatal=False)
|
||||||
|
if try_get(video_url, lambda x: x['result']['status']) == 'ok':
|
||||||
|
video_url = try_get(video_url, lambda x: x['result']['resp'])
|
||||||
|
info_dict['formats'].append({
|
||||||
|
'url': video_url,
|
||||||
|
'format_id': quality,
|
||||||
|
'height': int_or_none(quality[:-1])
|
||||||
|
})
|
||||||
|
|
||||||
if not info_dict['duration']:
|
if not info_dict['duration']:
|
||||||
info_dict['duration'] = parse_duration(video.get('duration'))
|
info_dict['duration'] = parse_duration(video.get('duration'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue