From cac96421d9f736e2b463c4bb170f67874fb04055 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sat, 30 Jan 2021 16:43:20 +0530 Subject: [PATCH] New option --no-write-playlist-metafiles to NOT write playlist metadata files --- README.md | 5 +++ youtube_dlc/YoutubeDL.py | 91 +++++++++++++++++++++------------------- youtube_dlc/options.py | 12 ++++++ 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 2ffad0695d..1811ed6db2 100644 --- a/README.md +++ b/README.md @@ -378,6 +378,11 @@ ## Filesystem Options: --write-annotations Write video annotations to a .annotations.xml file --no-write-annotations Do not write video annotations (default) + --write-playlist-metafiles Write playlist metadata in addition to the + video metadata when using --write-info-json, + --write-description etc. (default) + --no-write-playlist-metafiles Do not write playlist metadata when using + --write-info-json, --write-description etc. --get-comments Retrieve video comments to be placed in the .info.json file --load-info-json FILE JSON file containing the video information diff --git a/youtube_dlc/YoutubeDL.py b/youtube_dlc/YoutubeDL.py index d396ed8ba6..62f7023569 100644 --- a/youtube_dlc/YoutubeDL.py +++ b/youtube_dlc/YoutubeDL.py @@ -206,6 +206,7 @@ class YoutubeDL(object): unless writeinfojson is also given writeannotations: Write the video annotations to a .annotations.xml file writethumbnail: Write the thumbnail image to a file + allow_playlist_files: Also write playlists' description, infojson etc in a seperate file write_all_thumbnails: Write all thumbnail formats to files writelink: Write an internet shortcut file, depending on the current platform (.url/.webloc/.desktop) @@ -1108,54 +1109,56 @@ def __process_playlist(self, ie_result, download): # We process each entry in the playlist playlist = ie_result.get('title') or ie_result.get('id') self.to_screen('[download] Downloading playlist: %s' % playlist) - ie_copy = { - 'playlist': playlist, - 'playlist_id': ie_result.get('id'), - 'playlist_title': ie_result.get('title'), - 'playlist_uploader': ie_result.get('uploader'), - 'playlist_uploader_id': ie_result.get('uploader_id'), - 'playlist_index': 0 - } - ie_copy.update(dict(ie_result)) - def ensure_dir_exists(path): - return make_dir(path, self.report_error) + if self.params.get('allow_playlist_files', True): + ie_copy = { + 'playlist': playlist, + 'playlist_id': ie_result.get('id'), + 'playlist_title': ie_result.get('title'), + 'playlist_uploader': ie_result.get('uploader'), + 'playlist_uploader_id': ie_result.get('uploader_id'), + 'playlist_index': 0 + } + ie_copy.update(dict(ie_result)) - if self.params.get('writeinfojson', False): - infofn = replace_extension( - self.prepare_filepath(self.prepare_filename(ie_copy), 'infojson'), - 'info.json', ie_result.get('ext')) - if not ensure_dir_exists(encodeFilename(infofn)): - return - if self.params.get('overwrites', True) and os.path.exists(encodeFilename(infofn)): - self.to_screen('[info] Playlist metadata is already present') - else: - self.to_screen('[info] Writing playlist metadata as JSON to: ' + infofn) - playlist_info = dict(ie_result) - playlist_info.pop('entries') - try: - write_json_file(self.filter_requested_info(playlist_info), infofn) - except (OSError, IOError): - self.report_error('Cannot write playlist metadata to JSON file ' + infofn) + def ensure_dir_exists(path): + return make_dir(path, self.report_error) - if self.params.get('writedescription', False): - descfn = replace_extension( - self.prepare_filepath(self.prepare_filename(ie_copy), 'description'), - 'description', ie_result.get('ext')) - if not ensure_dir_exists(encodeFilename(descfn)): - return - if not self.params.get('overwrites', True) and os.path.exists(encodeFilename(descfn)): - self.to_screen('[info] Playlist description is already present') - elif ie_result.get('description') is None: - self.report_warning('There\'s no playlist description to write.') - else: - try: - self.to_screen('[info] Writing playlist description to: ' + descfn) - with io.open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile: - descfile.write(ie_result['description']) - except (OSError, IOError): - self.report_error('Cannot write playlist description file ' + descfn) + if self.params.get('writeinfojson', False): + infofn = replace_extension( + self.prepare_filepath(self.prepare_filename(ie_copy), 'infojson'), + 'info.json', ie_result.get('ext')) + if not ensure_dir_exists(encodeFilename(infofn)): return + if self.params.get('overwrites', True) and os.path.exists(encodeFilename(infofn)): + self.to_screen('[info] Playlist metadata is already present') + else: + self.to_screen('[info] Writing playlist metadata as JSON to: ' + infofn) + playlist_info = dict(ie_result) + playlist_info.pop('entries') + try: + write_json_file(self.filter_requested_info(playlist_info), infofn) + except (OSError, IOError): + self.report_error('Cannot write playlist metadata to JSON file ' + infofn) + + if self.params.get('writedescription', False): + descfn = replace_extension( + self.prepare_filepath(self.prepare_filename(ie_copy), 'description'), + 'description', ie_result.get('ext')) + if not ensure_dir_exists(encodeFilename(descfn)): + return + if not self.params.get('overwrites', True) and os.path.exists(encodeFilename(descfn)): + self.to_screen('[info] Playlist description is already present') + elif ie_result.get('description') is None: + self.report_warning('There\'s no playlist description to write.') + else: + try: + self.to_screen('[info] Writing playlist description to: ' + descfn) + with io.open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile: + descfile.write(ie_result['description']) + except (OSError, IOError): + self.report_error('Cannot write playlist description file ' + descfn) + return playlist_results = [] diff --git a/youtube_dlc/options.py b/youtube_dlc/options.py index af152ab27e..2cef01a5ac 100644 --- a/youtube_dlc/options.py +++ b/youtube_dlc/options.py @@ -937,6 +937,18 @@ def _dict_from_multiple_values_options_callback( '--no-write-annotations', action='store_false', dest='writeannotations', help='Do not write video annotations (default)') + filesystem.add_option( + '--write-playlist-metafiles', + action='store_true', dest='allow_playlist_files', default=True, + help=( + 'Write playlist metadata in addition to the video metadata ' + 'when using --write-info-json, --write-description etc. (default)')) + filesystem.add_option( + '--no-write-playlist-metafiles', + action='store_false', dest='allow_playlist_files', + help=( + 'Do not write playlist metadata when using ' + '--write-info-json, --write-description etc.')) filesystem.add_option( '--get-comments', action='store_true', dest='getcomments', default=False,