From a831e245651f83c1fbffeb93d550c8e976cf37bb Mon Sep 17 00:00:00 2001 From: vayalil <36435907+vayalil@users.noreply.github.com> Date: Tue, 13 Feb 2018 17:52:01 +1100 Subject: [PATCH 1/3] Add files via upload --- youtube_dl/YoutubeDL.py | 2 +- youtube_dl/options.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 523dd1f7d..925d095de 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1033,7 +1033,7 @@ class YoutubeDL(object): '!=': operator.ne, } operator_rex = re.compile(r'''(?x)\s* - (?Pwidth|height|tbr|abr|vbr|asr|filesize|filesize_approx|fps) + (?Pwidth|height|tbr|abr|vbr|asr|filesize|fps) \s*(?P%s)(?P\s*\?)?\s* (?P[0-9.]+(?:[kKmMgGtTpPeEzZyY]i?[Bb]?)?) $ diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 7d1bbc021..f1938a165 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -813,6 +813,12 @@ def parseOpts(overrideArguments=None): '--add-metadata', action='store_true', dest='addmetadata', default=False, help='Write metadata to the video file') + postproc.add_option( + '--metadata', + metavar='METADATA', dest='metafromuser', default=False, + help='Allows the user to specify key/value pairs for encoding metadata, sepatated by equal sign.' + 'Example: --metadata "album = Movie Title artist = Various artists year = "2010"' + 'Also tries to capture artist information from the file description, if otherwise not available') postproc.add_option( '--metadata-from-title', metavar='FORMAT', dest='metafromtitle', From 9f87c688c95a51fad652c0899d14ed9778e8292e Mon Sep 17 00:00:00 2001 From: vayalil <36435907+vayalil@users.noreply.github.com> Date: Tue, 13 Feb 2018 17:52:55 +1100 Subject: [PATCH 2/3] Add files via upload --- youtube_dl/postprocessor/metadatafromuser.py | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 youtube_dl/postprocessor/metadatafromuser.py diff --git a/youtube_dl/postprocessor/metadatafromuser.py b/youtube_dl/postprocessor/metadatafromuser.py new file mode 100644 index 000000000..ec4c6154b --- /dev/null +++ b/youtube_dl/postprocessor/metadatafromuser.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +""" +Created on Fri Feb 9 16:23:16 2018 + +@author: Niras C. Vayalil +""" + +from __future__ import unicode_literals +from .common import PostProcessor +import re + + +class MetadataFromUserPP(PostProcessor): + def __init__(self, downloader, metadata): + super(MetadataFromUserPP, self).__init__(downloader) + self._metadata = metadata + + + def run(self, info): + lastpos = 0 + attribute = None + # Search for key words + for match in re.finditer(r'(\w+) *=', self._metadata): + if attribute is not None: + # The data exists between previous math end and new match start + value = self._metadata[lastpos:match.start()].strip() + self._downloader.to_screen( + '[fromuser] %s: %s' + %(attribute, value if value else 'NA')) + info[attribute] = value + attribute = match.group(1) + lastpos = match.end() + + if attribute is None: + # No attributes is given user, default assume the text as album name + attribute = 'album' + # Add the last key + value = self._metadata[lastpos:].strip() + self._downloader.to_screen( + '[fromuser] %s: %s' + %(attribute, value if value else 'NA')) + info[attribute] = value + + # If nothing specified for artist, extract from comments/description + if (('artist' not in info) and ('description' in info)): + artist = re.findall('music(?![ia]).*$', info['description'], re.MULTILINE | re.IGNORECASE) + artist = artist + re.findall('sing.*$', info['description'], re.MULTILINE | re.IGNORECASE) + artist = ', '.join(artist).title().strip() + + self._downloader.to_screen( + '[artist] : %s : parsed from description' %(artist if artist else 'NA')) + info['artist'] = artist + + return [], info From d8d02c7932b29adc5bff1bba99de5492e1528daa Mon Sep 17 00:00:00 2001 From: vayalil <36435907+vayalil@users.noreply.github.com> Date: Tue, 13 Feb 2018 17:57:46 +1100 Subject: [PATCH 3/3] Add files via upload --- youtube_dl/YoutubeDL.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 925d095de..523dd1f7d 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1033,7 +1033,7 @@ class YoutubeDL(object): '!=': operator.ne, } operator_rex = re.compile(r'''(?x)\s* - (?Pwidth|height|tbr|abr|vbr|asr|filesize|fps) + (?Pwidth|height|tbr|abr|vbr|asr|filesize|filesize_approx|fps) \s*(?P%s)(?P\s*\?)?\s* (?P[0-9.]+(?:[kKmMgGtTpPeEzZyY]i?[Bb]?)?) $