From 93240fc1848de4a94f25844c96e0dcd282ef1d3b Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 10 Mar 2024 19:52:49 +0530 Subject: [PATCH] [cleanup] Fix misc bugs (#8968) Closes #8816 Authored by: bashonly, seproDev, pukkandan, Grub4k --- yt_dlp/extractor/abematv.py | 2 +- yt_dlp/extractor/adultswim.py | 1 - yt_dlp/extractor/antenna.py | 2 +- yt_dlp/extractor/bilibili.py | 1 + yt_dlp/extractor/common.py | 7 +++++-- yt_dlp/extractor/gamejolt.py | 2 +- yt_dlp/extractor/minoto.py | 2 +- yt_dlp/extractor/myvideoge.py | 2 +- yt_dlp/extractor/myvidster.py | 2 +- yt_dlp/extractor/rockstargames.py | 8 ++++---- yt_dlp/extractor/slideslive.py | 2 +- yt_dlp/networking/_requests.py | 2 +- yt_dlp/utils/_utils.py | 3 ++- 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/yt_dlp/extractor/abematv.py b/yt_dlp/extractor/abematv.py index 6742f75d5..fee7375ea 100644 --- a/yt_dlp/extractor/abematv.py +++ b/yt_dlp/extractor/abematv.py @@ -53,7 +53,7 @@ class AbemaLicenseHandler(urllib.request.BaseHandler): # the protocol that this should really handle is 'abematv-license://' # abematv_license_open is just a placeholder for development purposes # ref. https://github.com/python/cpython/blob/f4c03484da59049eb62a9bf7777b963e2267d187/Lib/urllib/request.py#L510 - setattr(self, 'abematv-license_open', getattr(self, 'abematv_license_open')) + setattr(self, 'abematv-license_open', getattr(self, 'abematv_license_open', None)) self.ie = ie def _get_videokey_from_ticket(self, ticket): diff --git a/yt_dlp/extractor/adultswim.py b/yt_dlp/extractor/adultswim.py index daaeddeb6..d807c4181 100644 --- a/yt_dlp/extractor/adultswim.py +++ b/yt_dlp/extractor/adultswim.py @@ -107,7 +107,6 @@ class AdultSwimIE(TurnerBaseIE): title tvRating }''' % episode_path - ['getVideoBySlug'] else: query = query % '''metaDescription title diff --git a/yt_dlp/extractor/antenna.py b/yt_dlp/extractor/antenna.py index 17a4b6900..2929d6550 100644 --- a/yt_dlp/extractor/antenna.py +++ b/yt_dlp/extractor/antenna.py @@ -67,7 +67,7 @@ class AntennaGrWatchIE(AntennaBaseIE): webpage = self._download_webpage(url, video_id) info = self._download_and_extract_api_data(video_id, netloc) info['description'] = self._og_search_description(webpage, default=None) - info['_old_archive_ids'] = [make_archive_id('Ant1NewsGrWatch', video_id)], + info['_old_archive_ids'] = [make_archive_id('Ant1NewsGrWatch', video_id)] return info diff --git a/yt_dlp/extractor/bilibili.py b/yt_dlp/extractor/bilibili.py index f4e1c91a8..fee4b2994 100644 --- a/yt_dlp/extractor/bilibili.py +++ b/yt_dlp/extractor/bilibili.py @@ -1965,6 +1965,7 @@ class BiliIntlIE(BiliIntlBaseIE): 'only_matching': True, }] + @staticmethod def _make_url(video_id, series_id=None): if series_id: return f'https://www.bilibili.tv/en/play/{series_id}/{video_id}' diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py index f57963da2..e776ccae9 100644 --- a/yt_dlp/extractor/common.py +++ b/yt_dlp/extractor/common.py @@ -747,7 +747,7 @@ class InfoExtractor: raise except ExtractorError as e: e.video_id = e.video_id or self.get_temp_id(url) - e.ie = e.ie or self.IE_NAME, + e.ie = e.ie or self.IE_NAME e.traceback = e.traceback or sys.exc_info()[2] raise except IncompleteRead as e: @@ -1339,7 +1339,10 @@ class InfoExtractor: else: return None, None if not info: - raise netrc.NetrcParseError(f'No authenticators for {netrc_machine}') + self.to_screen(f'No authenticators for {netrc_machine}') + return None, None + + self.write_debug(f'Using netrc for {netrc_machine} authentication') return info[0], info[2] def _get_login_info(self, username_option='username', password_option='password', netrc_machine=None): diff --git a/yt_dlp/extractor/gamejolt.py b/yt_dlp/extractor/gamejolt.py index 4d57391ac..1d3c0b110 100644 --- a/yt_dlp/extractor/gamejolt.py +++ b/yt_dlp/extractor/gamejolt.py @@ -88,7 +88,7 @@ class GameJoltBaseIE(InfoExtractor): 'uploader_id': user_data.get('username'), 'uploader_url': format_field(user_data, 'url', 'https://gamejolt.com%s'), 'categories': [try_get(category, lambda x: '%s - %s' % (x['community']['name'], x['channel'].get('display_title') or x['channel']['title'])) - for category in post_data.get('communities' or [])], + for category in post_data.get('communities') or []], 'tags': traverse_obj( lead_content, ('content', ..., 'content', ..., 'marks', ..., 'attrs', 'tag'), expected_type=str_or_none), 'like_count': int_or_none(post_data.get('like_count')), diff --git a/yt_dlp/extractor/minoto.py b/yt_dlp/extractor/minoto.py index 8d18179c7..032bf3b71 100644 --- a/yt_dlp/extractor/minoto.py +++ b/yt_dlp/extractor/minoto.py @@ -21,7 +21,7 @@ class MinotoIE(InfoExtractor): continue container = fmt.get('container') if container == 'hls': - formats.extend(fmt_url, video_id, 'mp4', m3u8_id='hls', fatal=False) + formats.extend(self._extract_m3u8_formats(fmt_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) else: fmt_profile = fmt.get('profile') or {} formats.append({ diff --git a/yt_dlp/extractor/myvideoge.py b/yt_dlp/extractor/myvideoge.py index 64cee48e7..3e0bb2499 100644 --- a/yt_dlp/extractor/myvideoge.py +++ b/yt_dlp/extractor/myvideoge.py @@ -64,7 +64,7 @@ class MyVideoGeIE(InfoExtractor): # translate any ka month to an en one re.sub('|'.join(self._MONTH_NAMES_KA), lambda m: MONTH_NAMES['en'][self._MONTH_NAMES_KA.index(m.group(0))], - upload_date, re.I)) + upload_date, flags=re.I)) if upload_date else None) return { diff --git a/yt_dlp/extractor/myvidster.py b/yt_dlp/extractor/myvidster.py index c91f294bf..e3b700dbb 100644 --- a/yt_dlp/extractor/myvidster.py +++ b/yt_dlp/extractor/myvidster.py @@ -2,7 +2,7 @@ from .common import InfoExtractor class MyVidsterIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?myvidster\.com/video/(?P\d+)/' + _VALID_URL = r'https?://(?:www\.)?myvidster\.com/video/(?P\d+)' _TEST = { 'url': 'http://www.myvidster.com/video/32059805/Hot_chemistry_with_raw_love_making', diff --git a/yt_dlp/extractor/rockstargames.py b/yt_dlp/extractor/rockstargames.py index b0b92e642..16622430c 100644 --- a/yt_dlp/extractor/rockstargames.py +++ b/yt_dlp/extractor/rockstargames.py @@ -38,14 +38,14 @@ class RockstarGamesIE(InfoExtractor): title = video['title'] formats = [] - for video in video['files_processed']['video/mp4']: - if not video.get('src'): + for v in video['files_processed']['video/mp4']: + if not v.get('src'): continue - resolution = video.get('resolution') + resolution = v.get('resolution') height = int_or_none(self._search_regex( r'^(\d+)[pP]$', resolution or '', 'height', default=None)) formats.append({ - 'url': self._proto_relative_url(video['src']), + 'url': self._proto_relative_url(v['src']), 'format_id': resolution, 'height': height, }) diff --git a/yt_dlp/extractor/slideslive.py b/yt_dlp/extractor/slideslive.py index df2af3b35..c012dee59 100644 --- a/yt_dlp/extractor/slideslive.py +++ b/yt_dlp/extractor/slideslive.py @@ -386,7 +386,7 @@ class SlidesLiveIE(InfoExtractor): if not line.startswith('#EXT-SL-'): continue tag, _, value = line.partition(':') - key = lookup.get(tag.lstrip('#EXT-SL-')) + key = lookup.get(tag[8:]) if not key: continue m3u8_dict[key] = value diff --git a/yt_dlp/networking/_requests.py b/yt_dlp/networking/_requests.py index 7b19029bf..6545028c8 100644 --- a/yt_dlp/networking/_requests.py +++ b/yt_dlp/networking/_requests.py @@ -116,7 +116,7 @@ See: https://github.com/urllib3/urllib3/issues/517 """ if urllib3_version < (2, 0, 0): - with contextlib.suppress(): + with contextlib.suppress(Exception): urllib3.util.IS_SECURETRANSPORT = urllib3.util.ssl_.IS_SECURETRANSPORT = True diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index d8b74423a..49944e9d2 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -1424,7 +1424,8 @@ def write_string(s, out=None, encoding=None): s = re.sub(r'([\r\n]+)', r' \1', s) enc, buffer = None, out - if 'b' in getattr(out, 'mode', ''): + # `mode` might be `None` (Ref: https://github.com/yt-dlp/yt-dlp/issues/8816) + if 'b' in (getattr(out, 'mode', None) or ''): enc = encoding or preferredencoding() elif hasattr(out, 'buffer'): buffer = out.buffer