From a90a1bd798b1791e19eb188d2b5ffa43b56619c3 Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sun, 26 Jul 2015 00:41:00 +0300 Subject: [PATCH 1/2] [youtube] Added argument --write-tags, that ads the list of tags to the end of the description file. Implies --write-description. --- youtube_dl/YoutubeDL.py | 5 ++++- youtube_dl/__init__.py | 1 + youtube_dl/extractor/youtube.py | 4 ++++ youtube_dl/options.py | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 702a6ad50..04eec07ab 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -150,6 +150,7 @@ class YoutubeDL(object): logger: Log messages to a logging.Logger instance. logtostderr: Log messages to stderr instead of stdout. writedescription: Write the video description to a .description file + writetags: Write out the tags of the video to the bottom of the .description file. writeinfojson: Write the video description to a .info.json file writeannotations: Write the video annotations to a .annotations.xml file writethumbnail: Write the thumbnail image to a file @@ -1291,7 +1292,7 @@ class YoutubeDL(object): self.report_error('unable to create directory ' + compat_str(err)) return - if self.params.get('writedescription', False): + if self.params.get('writedescription', False) or (self.params.get('writetags', False) and 'tags' in info_dict): descfn = replace_extension(filename, 'description', info_dict.get('ext')) if self.params.get('nooverwrites', False) and os.path.exists(encodeFilename(descfn)): self.to_screen('[info] Video description is already present') @@ -1302,6 +1303,8 @@ class YoutubeDL(object): self.to_screen('[info] Writing video description to: ' + descfn) with io.open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile: descfile.write(info_dict['description']) + if self.params.get('writetags', False): + descfile.write("\nKeywords: %s\n" % (info_dict['tags'],)) except (OSError, IOError): self.report_error('Cannot write description file ' + descfn) return diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 55b22c889..e6bf1f81d 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -314,6 +314,7 @@ def _real_main(argv=None): 'nopart': opts.nopart, 'updatetime': opts.updatetime, 'writedescription': opts.writedescription, + 'writetags': opts.writetags, 'writeannotations': opts.writeannotations, 'writeinfojson': opts.writeinfojson, 'writethumbnail': opts.writethumbnail, diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 0e411bfb6..1ab546a83 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1072,6 +1072,9 @@ class YoutubeIE(YoutubeBaseInfoExtractor): else: video_categories = None + m = re.findall(r''''"]+?)['"]?\s*>''' + , video_webpage, re.DOTALL | re.IGNORECASE); + video_tags = u", ".join(m) # description video_description = get_element_by_id("eow-description", video_webpage) if video_description: @@ -1259,6 +1262,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): 'title': video_title, 'thumbnail': video_thumbnail, 'description': video_description, + 'tags' : video_tags, 'categories': video_categories, 'subtitles': video_subtitles, 'automatic_captions': automatic_captions, diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 9016e3498..b52117e78 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -635,6 +635,10 @@ def parseOpts(overrideArguments=None): '--write-description', action='store_true', dest='writedescription', default=False, help='Write video description to a .description file') + filesystem.add_option( + '--write-tags', + action='store_true', dest='writetags', default=False, + help='Write out the tags of the video to the bottom of the .description file. Implies --write-description.') filesystem.add_option( '--write-info-json', action='store_true', dest='writeinfojson', default=False, From 32f41d84216b1c915a5a4c4fee44c01bfaeb28ff Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Tue, 28 Jul 2015 18:05:46 +0300 Subject: [PATCH 2/2] fix build for python3.2 --- youtube_dl/extractor/youtube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 1ab546a83..15e327ec8 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -1074,7 +1074,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): m = re.findall(r''''"]+?)['"]?\s*>''' , video_webpage, re.DOTALL | re.IGNORECASE); - video_tags = u", ".join(m) + video_tags = ", ".join(m) # description video_description = get_element_by_id("eow-description", video_webpage) if video_description: