From 4292fd33715e7d5a6a1aa9e0be619030ce32ddd1 Mon Sep 17 00:00:00 2001 From: fnord Date: Wed, 24 Jun 2015 01:23:14 -0500 Subject: [PATCH] --custom-meta option to write specific information to tags, for --add-metadata Syntax: --custom-meta "TAGNAME=string with optional %(format)s" Example: --custom-meta "comment=%(webpage_url)s\n%(description)s" This can be invoked multiple times for different tags. Example 2: youtube-dl --add-metadata -f 18 --meta 'artist=%(uploader_id)s' --meta 'comment=url: %(webpage_url)s\nviews: %(view_count)s / Rating: %(average_rating)s\n\n%(description)s' https://www.youtube.com/watch?v=WzhW20hLp6M (snip) [ffmpeg] Adding metadata to 'Breaking Bad Remix (Seasons 3-5)-WzhW20hLp6M.mp4' mp4info Breaking\ Bad\ Remix\ \(Seasons\ 3-5\)-WzhW20hLp6M.mp4 (snip) Artist: uploader: placeboing Comments: url: https://www.youtube.com/watch?v=WzhW20hLp6M views: 5601679 / Rating: 4.97684526443 Music and remixing by me. Seasons 1 and 2 remix: http://www.youtube.com/watch?v=WsqdmqRgrIc MP3 download: https://www.dropbox.com/s/39luqbbi5cu36du/Chris%20Lohr%20-%20Breaking%20Bad%20Remix%20seasons%203-5.mp3 --- youtube_dl/__init__.py | 1 + youtube_dl/options.py | 10 ++++++++++ youtube_dl/postprocessor/ffmpeg.py | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index ace17857c..89192b3d3 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -367,6 +367,7 @@ def _real_main(argv=None): 'hls_prefer_native': opts.hls_prefer_native, 'external_downloader_args': external_downloader_args, 'cn_verification_proxy': opts.cn_verification_proxy, + 'custommeta': opts.custommeta, } with YoutubeDL(ydl_opts) as ydl: diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 740458e51..8427a58e5 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -707,6 +707,16 @@ def parseOpts(overrideArguments=None): '--add-metadata', action='store_true', dest='addmetadata', default=False, help='Write metadata to the video file') + postproc.add_option( + '--custom-meta', + action='append', dest='custommeta', default=[], + help='Write specific information to a metadata tag.' + 'Syntax: "tagname=string to add with %(format)s" ' + 'The formatting syntax is the same as output. ' + 'Example: --custom-meta "comment=%(webpage_url)s\\n%(description)s" will ' + 'add a line with the url, then the description in the "comment" tag. ' + 'Tags are format-specific, common ones include: artist, comment, title, copyright, uploader. ' + 'This can be invoked multiple times for different tags.') postproc.add_option( '--metadata-from-title', metavar='FORMAT', dest='metafromtitle', diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py index fe7e0a8ee..c27c0db3b 100644 --- a/youtube_dl/postprocessor/ffmpeg.py +++ b/youtube_dl/postprocessor/ffmpeg.py @@ -367,6 +367,10 @@ class FFmpegMetadataPP(FFmpegPostProcessor): if info.get('album') is not None: metadata['album'] = info['album'] + for m in self._downloader.params.get('custommeta'): + key,val = m.split('=',1) + metadata[key] = val.replace('\\n', '\n') % info + if not metadata: self._downloader.to_screen('[ffmpeg] There isn\'t any metadata to add') return [], info