From c4dcd43a5d3d985b8659004778b30793c342ce66 Mon Sep 17 00:00:00 2001 From: Digital <34419970+DigitalDwagon@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:31:27 -0500 Subject: [PATCH] fix: don't rely on internetarchive for parsing --metadata Closes #338 --- pyproject.toml | 2 +- tubeup/__main__.py | 6 ++---- tubeup/utils.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d45b8f7..a7f7073 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ readme = "README.md" requires-python = ">=3.9" license = {file = "LICENSE"} dependencies = [ - "internetarchive==4.1.0", + "internetarchive", "docopt==0.6.2", "yt-dlp", ] 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)