[youtube] Added argument --write-tags, that ads the list of tags to the end of the description file. Implies --write-description.

This commit is contained in:
Purdea Andrei 2015-07-26 00:41:00 +03:00
parent 289bbb350e
commit a90a1bd798
4 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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,

View File

@ -1072,6 +1072,9 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
else:
video_categories = None
m = re.findall(r'''<meta(?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]+|="[^"]+"|='[^']+'))*?\s+property=['"]?og:video:tag['"]?(?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]+|="[^"]+"|='[^']+'))*?\s+content=['"]?([^>'"]+?)['"]?\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,

View File

@ -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,