From a764865324e990d05e4bbf1ec24bb1f11844ac73 Mon Sep 17 00:00:00 2001 From: cens0r <74016750+cens0r@users.noreply.github.com> Date: Sun, 8 May 2022 16:38:40 +0200 Subject: [PATCH] fixes and suggestions --- youtube_dl/extractor/camwhoresbay.py | 63 +++++++++++----------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/youtube_dl/extractor/camwhoresbay.py b/youtube_dl/extractor/camwhoresbay.py index 2c00e4b2e..5a432af41 100644 --- a/youtube_dl/extractor/camwhoresbay.py +++ b/youtube_dl/extractor/camwhoresbay.py @@ -5,7 +5,11 @@ from .common import InfoExtractor import re import itertools from ..utils import ( + int_or_none, js_to_json, + parse_resolution, + sanitize_url, + update_url_query, ) @@ -21,31 +25,7 @@ class CamWhoresBayVideoIE(InfoExtractor): 'title': 'Kirsten_Xxx 2022-01-19', 'uploader': '789sani', 'url': r're:https://www\.camwhoresbay\.com/get_file/7/55259a27805bf1313318c14b2afb0dae1fef6e1dd4/484000/484472/484472_720p\.mp4/\?rnd=.+', - # 'formats': [{ - # 'url': r're:https://www\.camwhoresbay\.com/get_file/7/55259a27805bf1313318c14b2afb0dae1fef6e1dd4/484000/484472/484472\.mp4/\?rnd=.+', - # 'height': 360 - # }, { - # 'url': r're:https://www\.camwhoresbay\.com/get_file/7/55259a27805bf1313318c14b2afb0dae1fef6e1dd4/484000/484472/484472_480p\.mp4/\?rnd=.+', - # 'height': 480 - # }, { - # 'url': r're:https://www\.camwhoresbay\.com/get_file/7/55259a27805bf1313318c14b2afb0dae1fef6e1dd4/484000/484472/484472_720p\.mp4/\?rnd=.+', - # 'height': 720 - # }] - 'thumbnails': [{ - 'url': 'https://cwbstatic.cdntrex.com/contents/videos_screenshots/484000/484472/preview.mp4.jpg', - 'height': 360 - }, { - 'url': 'https://cwbstatic.cdntrex.com/contents/videos_screenshots/484000/484472/preview_480p.mp4.jpg', - 'height': 480 - }, { - 'url': 'https://cwbstatic.cdntrex.com/contents/videos_screenshots/484000/484472/preview_720p.mp4.jpg', - 'height': 720 - }], - # TODO more properties, either as: - # * A value - # * MD5 checksum; start the string with md5: - # * A regular expression; start the string with re: - # * Any Python type (for example int or float) + 'thumbnail': r're:^https?://cwbstatic.cdntrex.com/contents/videos_screenshots/484000/484472/preview_720p.mp4.jpg', } } @@ -54,11 +34,11 @@ class CamWhoresBayVideoIE(InfoExtractor): formats = [] rnd = flashvars.get('rnd') for k, v in flashvars.items(): - if re.match(r"^video_(alt_)?url\d?$", k): + if re.match(r'^video_(alt_)?url\d?$', k): f = { - 'url': '{}?rnd={}'.format(v, rnd), - 'height': int(flashvars['{}_text'.format(k)][:-1]) + 'url': update_url_query(v, {'rnd': rnd, }) } + f.update(parse_resolution(flashvars.get(k + '_text'))) formats.append(f) return formats @@ -66,10 +46,10 @@ class CamWhoresBayVideoIE(InfoExtractor): def _parse_thumbnails(flashvars): thumbnails = [] for k, v in flashvars.items(): - if re.match(r"^preview_url\d$", k): + if re.match(r'^preview_url\d$', k): t = { - 'url': 'https:{}'.format(v), - 'height': int(flashvars[k.replace('_url', '_height')]) + 'url': sanitize_url(v), + 'height': int_or_none(flashvars.get(k.replace('_url', '_height'))), } thumbnails.append(t) return thumbnails @@ -77,12 +57,17 @@ class CamWhoresBayVideoIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) + + if re.search(r'(?s)