Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compatibility with ia 5.0.3 #339

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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__"}
6 changes: 2 additions & 4 deletions tubeup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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'])
Expand Down
19 changes: 19 additions & 0 deletions tubeup/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import os
import re
from collections import defaultdict


EMPTY_ANNOTATION_FILE = ('<?xml version="1.0" encoding="UTF-8" ?>'
'<document><annotations></annotations></document>')

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)
Expand Down
Loading