]> jfr.im git - yt-dlp.git/commitdiff
Tolerate failure to `--write-link` due to unknown URL
authorpukkandan <redacted>
Fri, 18 Feb 2022 12:23:09 +0000 (17:53 +0530)
committerpukkandan <redacted>
Fri, 18 Feb 2022 12:44:50 +0000 (18:14 +0530)
Closes #2724

yt_dlp/YoutubeDL.py

index 3a489ba96a65ab2b6ad0049433dff53cb2d0017a..36b2b37c0f447d475f7eb85f38c417adf438db4b 100644 (file)
@@ -2908,9 +2908,11 @@ def process_info(self, info_dict):
 
         # Write internet shortcut files
         def _write_link_file(link_type):
-            if 'webpage_url' not in info_dict:
-                self.report_error('Cannot write internet shortcut file because the "webpage_url" field is missing in the media information')
-                return False
+            url = try_get(info_dict['webpage_url'], iri_to_uri)
+            if not url:
+                self.report_warning(
+                    f'Cannot write internet shortcut file because the actual URL of "{info_dict["webpage_url"]}" is unknown')
+                return True
             linkfn = replace_extension(self.prepare_filename(info_dict, 'link'), link_type, info_dict.get('ext'))
             if not self._ensure_dir_exists(encodeFilename(linkfn)):
                 return False
@@ -2921,7 +2923,7 @@ def _write_link_file(link_type):
                 self.to_screen(f'[info] Writing internet shortcut (.{link_type}) to: {linkfn}')
                 with io.open(encodeFilename(to_high_limit_path(linkfn)), 'w', encoding='utf-8',
                              newline='\r\n' if link_type == 'url' else '\n') as linkfile:
-                    template_vars = {'url': iri_to_uri(info_dict['webpage_url'])}
+                    template_vars = {'url': url}
                     if link_type == 'desktop':
                         template_vars['filename'] = linkfn[:-(len(link_type) + 1)]
                     linkfile.write(LINK_TEMPLATES[link_type] % template_vars)