]> jfr.im git - yt-dlp.git/commitdiff
Cleanup some code and fix typos
authorpukkandan <redacted>
Fri, 12 Feb 2021 04:34:04 +0000 (10:04 +0530)
committerpukkandan <redacted>
Fri, 12 Feb 2021 15:02:49 +0000 (20:32 +0530)
:ci skip dl

15 files changed:
.gitignore
Changelog.md
Makefile
youtube_dlc/__init__.py
youtube_dlc/extractor/brightcove.py
youtube_dlc/extractor/ceskatelevize.py
youtube_dlc/extractor/common.py
youtube_dlc/extractor/ivi.py
youtube_dlc/extractor/limelight.py
youtube_dlc/extractor/ninecninemedia.py
youtube_dlc/extractor/ruutu.py
youtube_dlc/extractor/toggle.py
youtube_dlc/extractor/wakanim.py
youtube_dlc/postprocessor/ffmpeg.py
youtube_dlc/update.py

index a550c83af99e9d16066cabcecaf020f21360c8b3..7562032942213aa4e7c5bb2ca401d0de94c2494a 100644 (file)
@@ -55,6 +55,9 @@ youtube-dlc
 *.swf
 *.part
 *.ytdl
+*.frag
+*.frag.urls
+*.aria2
 *.swp
 *.ogg
 *.opus
index 87aff1107e990d2b15276ae64687514a8d2a6577..cc3c0a1f1e8bd6ff508e7b5261af841a795c5a16 100644 (file)
@@ -205,7 +205,7 @@ ### 2021.01.05
     * Changed video format sorting to show video only files and video+audio files together.
     * Added `--video-multistreams`, `--no-video-multistreams`, `--audio-multistreams`, `--no-audio-multistreams`
     * Added `b`,`w`,`v`,`a` as alias for `best`, `worst`, `video` and `audio` respectively
-* **Shortcut Options:** Added `--write-link`, `--write-url-link`, `--write-webloc-link`, `--write-desktop-link` by [h-h-h-h](https://github.com/h-h-h-h) - See [Internet Shortcut Options]README.md(#internet-shortcut-options) for details
+* **Shortcut Options:** Added `--write-link`, `--write-url-link`, `--write-webloc-link`, `--write-desktop-link` by [h-h-h-h](https://github.com/h-h-h-h) - See [Internet Shortcut Options](README.md#internet-shortcut-options) for details
 * **Sponskrub integration:** Added `--sponskrub`, `--sponskrub-cut`, `--sponskrub-force`, `--sponskrub-location`, `--sponskrub-args` - See [SponSkrub Options](README.md#sponskrub-options-sponsorblock) for details
 * Added `--force-download-archive` (`--force-write-archive`) by [h-h-h-h](https://github.com/h-h-h-h)
 * Added `--list-formats-as-table`,  `--list-formats-old`
index 4dc5e517cf404eb77f401e5bea4d44f416d9e31e..f5390c46db98e45d38a6ffc1da942c2a28328030 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ man: README.txt youtube-dlc.1 youtube-dlc.bash-completion youtube-dlc.zsh youtub
 
 
 clean:
-       rm -rf youtube-dlc.1.temp.md youtube-dlc.1 youtube-dlc.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dlc.tar.gz youtube-dlc.zsh youtube-dlc.fish youtube_dlc/extractor/lazy_extractors.py *.dump *.part* *.ytdl *.info.json *.mp4 *.m4a *.flv *.mp3 *.avi *.mkv *.webm *.3gp *.wav *.ape *.swf *.jpg *.png *.spec CONTRIBUTING.md.tmp youtube-dlc youtube-dlc.exe
+       rm -rf youtube-dlc.1.temp.md youtube-dlc.1 youtube-dlc.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dlc.tar.gz youtube-dlc.zsh youtube-dlc.fish youtube_dlc/extractor/lazy_extractors.py *.dump *.part* *.ytdl *.info.json *.mp4 *.m4a *.flv *.mp3 *.avi *.mkv *.webm *.3gp *.wav *.ape *.swf *.jpg *.png *.spec *.frag *.frag.urls *.frag.aria2 CONTRIBUTING.md.tmp youtube-dlc youtube-dlc.exe
        find . -name "*.pyc" -delete
        find . -name "*.class" -delete
 
index c681c8edbc4fc6511fdcee41c75ccc3e2b6fee02..4e55cf33713d9d08cade021b8e813e6c94921685 100644 (file)
@@ -379,12 +379,15 @@ def report_conflict(arg1, arg2):
             'when': 'aftermove'
         })
 
-    _args_compat_warning = 'WARNING: %s given without specifying name. The arguments will be given to all %s\n'
+    def report_args_compat(arg, name):
+        write_string(
+            'WARNING: %s given without specifying name. The arguments will be given to all %s\n' % (arg, name),
+            out=sys.stderr)
     if 'default' in opts.external_downloader_args:
-        write_string(_args_compat_warning % ('--external-downloader-args', 'external downloaders'), out=sys.stderr),
+        report_args_compat('--external-downloader-args', 'external downloaders')
 
     if 'default-compat' in opts.postprocessor_args and 'default' not in opts.postprocessor_args:
-        write_string(_args_compat_warning % ('--post-processor-args', 'post-processors'), out=sys.stderr),
+        report_args_compat('--post-processor-args', 'post-processors')
         opts.postprocessor_args.setdefault('sponskrub', [])
         opts.postprocessor_args['default'] = opts.postprocessor_args['default-compat']
 
index 091992ebd3c60fad5fe394bc40624f6c35dafd8d..8b29ca99375daaeaa7de0dd4dc8e065d4abde357 100644 (file)
@@ -478,11 +478,12 @@ def _parse_brightcove_metadata(self, json_data, video_id, headers={}):
             container = source.get('container')
             ext = mimetype2ext(source.get('type'))
             src = source.get('src')
+            skip_unplayable = not self._downloader.params.get('allow_unplayable_formats')
             # https://support.brightcove.com/playback-api-video-fields-reference#key_systems_object
-            if not self._downloader.params.get('allow_unplayable_formats') and (container == 'WVM' or source.get('key_systems')):
+            if skip_unplayable and (container == 'WVM' or source.get('key_systems')):
                 num_drm_sources += 1
                 continue
-            elif ext == 'ism' and not self._downloader.params.get('allow_unplayable_formats'):
+            elif ext == 'ism' and skip_unplayable:
                 continue
             elif ext == 'm3u8' or container == 'M2TS':
                 if not src:
@@ -546,7 +547,8 @@ def build_format_id(kind):
                 error = errors[0]
                 raise ExtractorError(
                     error.get('message') or error.get('error_subcode') or error['error_code'], expected=True)
-            if not self._downloader.params.get('allow_unplayable_formats') and sources and num_drm_sources == len(sources):
+            if (not self._downloader.params.get('allow_unplayable_formats')
+                    and sources and num_drm_sources == len(sources)):
                 raise ExtractorError('This video is DRM protected.', expected=True)
 
         self._sort_formats(formats)
index dc8b04ec6a6704fc97762bc8df8d08e9da03cd3d..6bfb760fadd9f0b2ab04ada53dc170ff34f45c90 100644 (file)
@@ -147,7 +147,8 @@ def _real_extract(self, url):
                 is_live = item.get('type') == 'LIVE'
                 formats = []
                 for format_id, stream_url in item.get('streamUrls', {}).items():
-                    if not self._downloader.params.get('allow_unplayable_formats') and 'drmOnly=true' in stream_url:
+                    if (not self._downloader.params.get('allow_unplayable_formats')
+                            and 'drmOnly=true' in stream_url):
                         continue
                     if 'playerType=flash' in stream_url:
                         stream_formats = self._extract_m3u8_formats(
index 1fe2d0a93e122e50d143f594a82824e4be902612..371c3492995bbddc013f5ab67905e7456eebe506 100644 (file)
@@ -2358,7 +2358,7 @@ def extract_Initialization(source):
                         extract_Initialization(segment_template)
             return ms_info
 
-        allow_unplayable_formats = self._downloader.params.get('allow_unplayable_formats')
+        skip_unplayable = not self._downloader.params.get('allow_unplayable_formats')
 
         mpd_duration = parse_duration(mpd_doc.get('mediaPresentationDuration'))
         formats = []
@@ -2369,11 +2369,11 @@ def extract_Initialization(source):
                 'timescale': 1,
             })
             for adaptation_set in period.findall(_add_ns('AdaptationSet')):
-                if is_drm_protected(adaptation_set) and allow_unplayable_formats is False:
+                if skip_unplayable and is_drm_protected(adaptation_set):
                     continue
                 adaption_set_ms_info = extract_multisegment_info(adaptation_set, period_ms_info)
                 for representation in adaptation_set.findall(_add_ns('Representation')):
-                    if is_drm_protected(representation) and allow_unplayable_formats is False:
+                    if skip_unplayable and is_drm_protected(representation):
                         continue
                     representation_attrib = adaptation_set.attrib.copy()
                     representation_attrib.update(representation.attrib)
@@ -2587,7 +2587,10 @@ def _parse_ism_formats(self, ism_doc, ism_url, ism_id=None):
          1. [MS-SSTR]: Smooth Streaming Protocol,
             https://msdn.microsoft.com/en-us/library/ff469518.aspx
         """
-        if ism_doc.get('IsLive') == 'TRUE' or (ism_doc.find('Protection') is not None and not self._downloader.params.get('allow_unplayable_formats')):
+        if ism_doc.get('IsLive') == 'TRUE':
+            return []
+        if (not self._downloader.params.get('allow_unplayable_formats')
+                and ism_doc.find('Protection') is not None):
             return []
 
         duration = int(ism_doc.attrib['Duration'])
index 7952ab9e6568c345a4a5662d576a727b613bdc8a..580cf41cd0e7c71cb0f5354911f8d042ac839fb2 100644 (file)
@@ -163,7 +163,10 @@ def _real_extract(self, url):
         for f in result.get('files', []):
             f_url = f.get('url')
             content_format = f.get('content_format')
-            if not f_url or (not self._downloader.params.get('allow_unplayable_formats') and ('-MDRM-' in content_format or '-FPS-' in content_format)):
+            if not f_url:
+                continue
+            if (not self._downloader.params.get('allow_unplayable_formats')
+                    and ('-MDRM-' in content_format or '-FPS-' in content_format)):
                 continue
             formats.append({
                 'url': f_url,
index 6592f60da38a96cb3227518e0af62c8a1505fe6d..b95b001ad3dbfe2c1245fa00f0fa0ca3db3ad4ba 100644 (file)
@@ -96,7 +96,9 @@ def _extract_info(self, pc, mobile, i, referer):
         urls = []
         for stream in pc_item.get('streams', []):
             stream_url = stream.get('url')
-            if not stream_url or (not self._downloader.params.get('allow_unplayable_formats') and stream.get('drmProtected')) or stream_url in urls:
+            if not stream_url or stream_url in urls:
+                continue
+            if not self._downloader.params.get('allow_unplayable_formats') and stream.get('drmProtected'):
                 continue
             urls.append(stream_url)
             ext = determine_ext(stream_url)
index 39ae4c66e6beb60cb634b4805514aa9afbb3920a..f98e8396bea46681fba016f9a1cb0f1a97dda9c9 100644 (file)
@@ -36,7 +36,8 @@ def _real_extract(self, url):
                 '$include': '[HasClosedCaptions]',
             })
 
-        if not self._downloader.params.get('allow_unplayable_formats') and try_get(content_package, lambda x: x['Constraints']['Security']['Type']):
+        if (not self._downloader.params.get('allow_unplayable_formats')
+                and try_get(content_package, lambda x: x['Constraints']['Security']['Type'])):
             raise ExtractorError('This video is DRM protected.', expected=True)
 
         manifest_base_url = content_package_url + 'manifest.'
index 5db83a4e11752c47d335d607279a827fc6775b89..f9f30e3dd2cf6b8dcff90fddd8398a378f3d1b67 100644 (file)
@@ -200,8 +200,8 @@ def pv(name):
                 return node.get('value')
 
         if not formats:
-            drm = xpath_text(video_xml, './Clip/DRM', default=None)
-            if not self._downloader.params.get('allow_unplayable_formats') and drm:
+            if (not self._downloader.params.get('allow_unplayable_formats')
+                    and xpath_text(video_xml, './Clip/DRM', default=None)):
                 raise ExtractorError('This video is DRM protected.', expected=True)
             ns_st_cds = pv('ns_st_cds')
             if ns_st_cds != 'free':
index 1ba55b55522691b25ed7e97c6d306a7fb222c9e8..1e2a2d819c3990db8fcf3252a143f710014acb61 100644 (file)
@@ -154,7 +154,8 @@ def _real_extract(self, url):
                 })
         if not formats:
             for meta in (info.get('Metas') or []):
-                if not self._downloader.params.get('allow_unplayable_formats') and meta.get('Key') == 'Encryption' and meta.get('Value') == '1':
+                if (not self._downloader.params.get('allow_unplayable_formats')
+                        and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'):
                     raise ExtractorError(
                         'This video is DRM protected.', expected=True)
             # Most likely because geo-blocked
index a8963d7698724e509122fcc1560a568610607090..507a28febb1b85bc7887df5782e24cbad7b7a35e 100644 (file)
@@ -41,12 +41,13 @@ def _real_extract(self, url):
         m3u8_url = urljoin(url, self._search_regex(
             r'file\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'm3u8 url',
             group='url'))
-        # https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-content-protection-overview#streaming-urls
-        encryption = self._search_regex(
-            r'encryption%3D(c(?:enc|bc(?:s-aapl)?))',
-            m3u8_url, 'encryption', default=None)
-        if not self._downloader.params.get('allow_unplayable_formats') and encryption and encryption in ('cenc', 'cbcs-aapl'):
-            raise ExtractorError('This video is DRM protected.', expected=True)
+        if not self._downloader.params.get('allow_unplayable_formats'):
+            # https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-content-protection-overview#streaming-urls
+            encryption = self._search_regex(
+                r'encryption%3D(c(?:enc|bc(?:s-aapl)?))',
+                m3u8_url, 'encryption', default=None)
+            if encryption in ('cenc', 'cbcs-aapl'):
+                raise ExtractorError('This video is DRM protected.', expected=True)
 
         formats = self._extract_m3u8_formats(
             m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
index cabe7266e2ba508af7489a62b8b2967cd3381bf4..0982bea81370317703910f404ff06f54c6362a53 100644 (file)
@@ -221,8 +221,7 @@ def get_metadata_object(self, path, opts=[]):
 
         cmd += opts
         cmd.append(encodeFilename(self._ffmpeg_filename_argument(path), True))
-        if self._downloader.params.get('verbose', False):
-            self._downloader.to_screen('[debug] ffprobe command line: %s' % shell_quote(cmd))
+        self.write_debug('ffprobe command line: %s' % shell_quote(cmd))
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
         stdout, stderr = p.communicate()
         return json.loads(stdout.decode('utf-8', 'replace'))
@@ -261,7 +260,7 @@ def run_ffmpeg_multiple_files(self, input_paths, out_path, opts):
         stdout, stderr = process_communicate_or_kill(p)
         if p.returncode != 0:
             stderr = stderr.decode('utf-8', 'replace').strip()
-            if self._downloader.params.get('verbose', False):
+            if self.get_param('verbose', False):
                 self.report_error(stderr)
             raise FFmpegPostProcessorError(stderr.split('\n')[-1])
         self.try_utime(out_path, oldest_mtime, oldest_mtime)
index 69bc5d2537a9e29a0bb76f85629b6a686c30a05d..b9d3c76248dd8e5a00e35b4767d91dce82174655 100644 (file)
@@ -59,7 +59,7 @@ def sha256sum():
         if verbose:
             to_screen(encode_compat_str(traceback.format_exc()))
         to_screen('ERROR: can\'t obtain versions info. Please try again later.')
-        to_screen('Visit https://github.com/pukkandan/yt-dlp/releases/lastest')
+        to_screen('Visit https://github.com/pukkandan/yt-dlp/releases/latest')
         return
 
     version_id = version_info['tag_name']
@@ -107,7 +107,7 @@ def version_tuple(version_str):
             if verbose:
                 to_screen(encode_compat_str(traceback.format_exc()))
             to_screen('ERROR: unable to download latest version')
-            to_screen('Visit https://github.com/pukkandan/yt-dlp/releases/lastest')
+            to_screen('Visit https://github.com/pukkandan/yt-dlp/releases/latest')
             return
 
         try:
@@ -150,7 +150,7 @@ def version_tuple(version_str):
             if verbose:
                 to_screen(encode_compat_str(traceback.format_exc()))
             to_screen('ERROR: unable to download latest version')
-            to_screen('Visit https://github.com/pukkandan/yt-dlp/releases/lastest')
+            to_screen('Visit https://github.com/pukkandan/yt-dlp/releases/latest')
             return
 
         try: