diff --git a/pyproject.toml b/pyproject.toml index d45b8f7..2089b77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,13 +10,13 @@ readme = "README.md" requires-python = ">=3.9" license = {file = "LICENSE"} dependencies = [ - "internetarchive==4.1.0", + "internetarchive", "docopt==0.6.2", "yt-dlp", ] [project.scripts] -tubeup = "tubeup:__main__" +tubeup = "tubeup.__main__:main" [tool.setuptools.dynamic] version = {attr = "tubeup.__version__"} diff --git a/tubeup/__main__.py b/tubeup/__main__.py index 0841765..07db11e 100644 --- a/tubeup/__main__.py +++ b/tubeup/__main__.py @@ -56,9 +56,7 @@ import logging import traceback -import internetarchive -import internetarchive.cli - +from tubeup.utils import key_value_to_dict from tubeup.TubeUp import TubeUp from tubeup import __version__ @@ -90,7 +88,7 @@ def main(): ch.setFormatter(formatter) root.addHandler(ch) - metadata = internetarchive.cli.argparser.get_args_dict(args['--metadata']) + metadata = key_value_to_dict(args['--metadata']) tu = TubeUp(verbose=not quiet_mode, output_template=args['--output']) diff --git a/tubeup/utils.py b/tubeup/utils.py index bc12845..52d31a4 100644 --- a/tubeup/utils.py +++ b/tubeup/utils.py @@ -1,10 +1,29 @@ import os import re +from collections import defaultdict EMPTY_ANNOTATION_FILE = ('' '') +def key_value_to_dict(lst): + """ + Convert many key:value pair strings into a python dictionary + """ + if not isinstance(lst, list): + lst = [lst] + + result = defaultdict(list) + for item in lst: + key, value = item.split(":", 1) + assert value, f"Expected a value! for {key}" + if result[key] and value not in result[key]: + result[key].append(value) + else: + result[key] = [value] + + # Convert single-item lists back to strings for non-list values + return {k: v if len(v) > 1 else v[0] for k, v in result.items()} def sanitize_identifier(identifier, replacement='-'): return re.sub(r'[^\w-]', replacement, identifier)