A feature-rich command-line audio/video downloader
Tolerate failure to `--write-link` due to unknown URL
pukkandan60f3e9959270
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.pyindex 3a489ba96a..36b2b37c0f 100644--- a/yt_dlp/YoutubeDL.py+++ b/yt_dlp/YoutubeDL.py@@ -2908,9 +2908,11 @@ class YoutubeDL(object):# Write internet shortcut filesdef _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 Truelinkfn = 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 @@ class YoutubeDL(object):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)