]> jfr.im git - yt-dlp.git/commitdiff
[cleanup Misc
authorpukkandan <redacted>
Tue, 18 Oct 2022 17:58:57 +0000 (23:28 +0530)
committerpukkandan <redacted>
Tue, 18 Oct 2022 18:22:44 +0000 (23:52 +0530)
Closes #5162

12 files changed:
README.md
yt_dlp/YoutubeDL.py
yt_dlp/__init__.py
yt_dlp/__main__.py
yt_dlp/downloader/common.py
yt_dlp/extractor/common.py
yt_dlp/extractor/generic.py
yt_dlp/extractor/prankcast.py
yt_dlp/extractor/tv24ua.py
yt_dlp/extractor/youtube.py
yt_dlp/postprocessor/sponsorblock.py
yt_dlp/utils.py

index a306b199e94ba2705f7b2651f84ee7304ddd2d19..4f731785d3cf891470274c0f98fb165c02df389e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1193,7 +1193,7 @@ # OUTPUT TEMPLATE
 
 1. **More Conversions**: In addition to the normal format types `diouxXeEfFgGcrs`, yt-dlp additionally supports converting to `B` = **B**ytes, `j` = **j**son (flag `#` for pretty-printing, `+` for Unicode), `h` = HTML escaping, `l` = a comma separated **l**ist (flag `#` for `\n` newline-separated), `q` = a string **q**uoted for the terminal (flag `#` to split a list into different arguments), `D` = add **D**ecimal suffixes (e.g. 10M) (flag `#` to use 1024 as factor), and `S` = **S**anitize as filename (flag `#` for restricted)
 
-1. **Unicode normalization**: The format type `U` can be used for NFC [unicode normalization](https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize). The alternate form flag (`#`) changes the normalization to NFD and the conversion flag `+` can be used for NFKC/NFKD compatibility equivalence normalization. E.g. `%(title)+.100U` is NFKC
+1. **Unicode normalization**: The format type `U` can be used for NFC [Unicode normalization](https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize). The alternate form flag (`#`) changes the normalization to NFD and the conversion flag `+` can be used for NFKC/NFKD compatibility equivalence normalization. E.g. `%(title)+.100U` is NFKC
 
 To summarize, the general syntax for a field is:
 ```
index 13725cddc3de8c798ec39b3f6476489f95aa912e..42780e7941148de899a70460a7d6ec1b9630daaa 100644 (file)
@@ -548,7 +548,7 @@ class YoutubeDL:
         # NB: Keep in sync with the docstring of extractor/common.py
         'url', 'manifest_url', 'manifest_stream_number', 'ext', 'format', 'format_id', 'format_note',
         'width', 'height', 'resolution', 'dynamic_range', 'tbr', 'abr', 'acodec', 'asr', 'audio_channels',
-        'vbr', 'fps', 'vcodec', 'container', 'filesize', 'filesize_approx',
+        'vbr', 'fps', 'vcodec', 'container', 'filesize', 'filesize_approx', 'rows', 'columns',
         'player_url', 'protocol', 'fragment_base_url', 'fragments', 'is_from_start',
         'preference', 'language', 'language_preference', 'quality', 'source_preference',
         'http_headers', 'stretched_ratio', 'no_resume', 'has_drm', 'downloader_options',
@@ -3586,7 +3586,7 @@ def render_formats_table(self, info_dict):
                     format_field(f, 'ext'),
                     self.format_resolution(f),
                     self._format_note(f)
-                ] for f in formats if f.get('preference') is None or f['preference'] >= -1000]
+                ] for f in formats if (f.get('preference') or 0) >= -1000]
             return render_table(['format code', 'extension', 'resolution', 'note'], table, extra_gap=1)
 
         def simplified_codec(f, field):
index 9382ff43baee0cb1f1ba34ffba1aa4e289d27000..726fb0685caf38eb25d7c30756ba980f7a87b344 100644 (file)
@@ -962,6 +962,8 @@ def _real_main(argv=None):
 
 
 def main(argv=None):
+    global _IN_CLI
+    _IN_CLI = True
     try:
         _exit(*variadic(_real_main(argv)))
     except DownloadError:
index 895918c272405e6cb59b7dd0ce75ce46233f9bfc..ff5d71d3c97d6fdeb0fc86d5a5d177b3c8cda652 100644 (file)
@@ -14,5 +14,4 @@
 import yt_dlp
 
 if __name__ == '__main__':
-    yt_dlp._IN_CLI = True
     yt_dlp.main()
index 221b3827c70cf1003402f9dd257cc3395e37866e..8d110c37473f0f00b4441827bd1b54e2debd3800 100644 (file)
@@ -333,7 +333,7 @@ def with_fields(*tups, default=''):
                     return tmpl
             return default
 
-        _formats_bytes = lambda k: f'{format_bytes(s.get(k)):>10s}'
+        _format_bytes = lambda k: f'{format_bytes(s.get(k)):>10s}'
 
         if s['status'] == 'finished':
             if self.params.get('noprogress'):
@@ -342,7 +342,7 @@ def with_fields(*tups, default=''):
             s.update({
                 'speed': speed,
                 '_speed_str': self.format_speed(speed).strip(),
-                '_total_bytes_str': _formats_bytes('total_bytes'),
+                '_total_bytes_str': _format_bytes('total_bytes'),
                 '_elapsed_str': self.format_seconds(s.get('elapsed')),
                 '_percent_str': self.format_percent(100),
             })
@@ -363,9 +363,9 @@ def with_fields(*tups, default=''):
                 lambda: 100 * s['downloaded_bytes'] / s['total_bytes'],
                 lambda: 100 * s['downloaded_bytes'] / s['total_bytes_estimate'],
                 lambda: s['downloaded_bytes'] == 0 and 0)),
-            '_total_bytes_str': _formats_bytes('total_bytes'),
-            '_total_bytes_estimate_str': _formats_bytes('total_bytes_estimate'),
-            '_downloaded_bytes_str': _formats_bytes('downloaded_bytes'),
+            '_total_bytes_str': _format_bytes('total_bytes'),
+            '_total_bytes_estimate_str': _format_bytes('total_bytes_estimate'),
+            '_downloaded_bytes_str': _format_bytes('downloaded_bytes'),
             '_elapsed_str': self.format_seconds(s.get('elapsed')),
         })
 
index ab8def57da500783c99cff9f5c42e7a45776c3e0..ec3fb58e5612405d95d225c247e49e412ed0bfe3 100644 (file)
@@ -1108,7 +1108,9 @@ def get_param(self, name, default=None, *args, **kwargs):
             return self._downloader.params.get(name, default, *args, **kwargs)
         return default
 
-    def report_drm(self, video_id, partial=False):
+    def report_drm(self, video_id, partial=NO_DEFAULT):
+        if partial is not NO_DEFAULT:
+            self._downloader.deprecation_warning('InfoExtractor.report_drm no longer accepts the argument partial')
         self.raise_no_formats('This video is DRM protected', expected=True, video_id=video_id)
 
     def report_extraction(self, id_or_name):
index b7a5ffb5b12aaed30d8ded3b8de80239f7a1c7d4..5abde33a91dd7976ab6f93a0c7f47896862e6044 100644 (file)
@@ -32,6 +32,7 @@
     unified_timestamp,
     unsmuggle_url,
     url_or_none,
+    variadic,
     xpath_attr,
     xpath_text,
     xpath_with_ns,
@@ -2820,11 +2821,8 @@ def _extract_embeds(self, url, webpage, *, urlh=None, info_dict={}):
             webpage)
         if mobj is not None:
             varname = mobj.group(1)
-            sources = self._parse_json(
-                mobj.group(2), video_id, transform_source=js_to_json,
-                fatal=False) or []
-            if not isinstance(sources, list):
-                sources = [sources]
+            sources = variadic(self._parse_json(
+                mobj.group(2), video_id, transform_source=js_to_json, fatal=False) or [])
             formats = []
             subtitles = {}
             for source in sources:
index 7446caf3c0ea3413a72f5b8e4f50a1ccbe1294d0..0eb5f98d19af2da7e06b134b9132031b4723a09b 100644 (file)
@@ -21,6 +21,23 @@ class PrankCastIE(InfoExtractor):
             'tags': ['prank call', 'prank'],
             'upload_date': '20220825'
         }
+    }, {
+        'url': 'https://prankcast.com/phonelosers/showreel/2048-NOT-COOL',
+        'info_dict': {
+            'id': '2048',
+            'ext': 'mp3',
+            'title': 'NOT COOL',
+            'display_id': 'NOT-COOL',
+            'timestamp': 1665028364,
+            'uploader': 'phonelosers',
+            'channel_id': 6,
+            'duration': 4044,
+            'cast': ['phonelosers'],
+            'description': '',
+            'categories': ['prank'],
+            'tags': ['prank call', 'prank'],
+            'upload_date': '20221006'
+        }
     }]
 
     def _real_extract(self, url):
index 553a70b6b26145b9e0664637507bc952735d92c1..2f2571df76a145afe636741fbd29a6d2194d368f 100644 (file)
@@ -1,12 +1,7 @@
 import re
 
 from .common import InfoExtractor
-from ..utils import (
-    determine_ext,
-    js_to_json,
-    mimetype2ext,
-    traverse_obj,
-)
+from ..utils import determine_ext, js_to_json, mimetype2ext, traverse_obj
 
 
 class TV24UAVideoIE(InfoExtractor):
index 857c9670c5933da6c505e9df6f20eeaefc1ea5d3..a12e5b03e7f7c9bbded920bd94396a3c2dd8ecab 100644 (file)
@@ -1721,7 +1721,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                 'live_status': 'not_live',
                 'playable_in_embed': True,
                 'comment_count': int,
-                'channel_follower_count': int
+                'channel_follower_count': int,
+                'chapters': list,
             },
             'params': {
                 'skip_download': True,
@@ -1754,7 +1755,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                 'live_status': 'not_live',
                 'channel_url': 'https://www.youtube.com/channel/UCH1dpzjCEiGAt8CXkryhkZg',
                 'comment_count': int,
-                'channel_follower_count': int
+                'channel_follower_count': int,
+                'chapters': list,
             },
             'params': {
                 'skip_download': True,
@@ -2019,7 +2021,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                 'duration': 522,
                 'channel': 'kudvenkat',
                 'comment_count': int,
-                'channel_follower_count': int
+                'channel_follower_count': int,
+                'chapters': list,
             },
             'params': {
                 'skip_download': True,
@@ -2169,7 +2172,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                 'like_count': int,
                 'live_status': 'not_live',
                 'playable_in_embed': True,
-                'channel_follower_count': int
+                'channel_follower_count': int,
+                'chapters': list,
             },
             'params': {
                 'format': '17',  # 3gp format available on android
@@ -2213,7 +2217,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                 'duration': 248,
                 'categories': ['Education'],
                 'age_limit': 0,
-                'channel_follower_count': int
+                'channel_follower_count': int,
+                'chapters': list,
             }, 'params': {'format': 'mhtml', 'skip_download': True}
         }, {
             # Ensure video upload_date is in UTC timezone (video was uploaded 1641170939)
index 188eb059aaad8a52be9fbeb681283819c24a6031..6ba87cd6723b9f0995c21e0a53997445fe2c7f8a 100644 (file)
@@ -85,7 +85,7 @@ def to_chapter(s):
 
         sponsor_chapters = [to_chapter(s) for s in duration_match]
         if not sponsor_chapters:
-            self.to_screen('No segments were found in the SponsorBlock database')
+            self.to_screen('No matching segments were found in the SponsorBlock database')
         else:
             self.to_screen(f'Found {len(sponsor_chapters)} segments in the SponsorBlock database')
         return sponsor_chapters
index adb7c0e8c5d4686a4e0e5b3b9c669331e293ab8f..1e2342f3e990e9f8d046407c22edc5fa93ad00d0 100644 (file)
@@ -5724,7 +5724,7 @@ def parse_args(self):
         return self.parser.parse_args(self.all_args)
 
 
-class WebSocketsWrapper():
+class WebSocketsWrapper:
     """Wraps websockets module to use in non-async scopes"""
     pool = None
 
@@ -5808,11 +5808,9 @@ def cached_method(f):
     def wrapper(self, *args, **kwargs):
         bound_args = signature.bind(self, *args, **kwargs)
         bound_args.apply_defaults()
-        key = tuple(bound_args.arguments.values())
+        key = tuple(bound_args.arguments.values())[1:]
 
-        if not hasattr(self, '__cached_method__cache'):
-            self.__cached_method__cache = {}
-        cache = self.__cached_method__cache.setdefault(f.__name__, {})
+        cache = vars(self).setdefault('__cached_method__cache', {}).setdefault(f.__name__, {})
         if key not in cache:
             cache[key] = f(self, *args, **kwargs)
         return cache[key]