mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 12:15:13 +03:00
✨ resolve #41
This commit is contained in:
+8
-2
@@ -17,6 +17,7 @@ from .utils import (
|
||||
setMetadata,
|
||||
convertToFlac,
|
||||
initLogging,
|
||||
parseFileInput,
|
||||
)
|
||||
|
||||
SAVE_COVER = True
|
||||
@@ -51,7 +52,7 @@ def main():
|
||||
"download_path": download_path,
|
||||
"track_quality": track_quality,
|
||||
"track_template": track_template,
|
||||
"file_extension": file_extension
|
||||
"file_extension": file_extension,
|
||||
}
|
||||
}
|
||||
).get("settings")
|
||||
@@ -118,6 +119,9 @@ def main():
|
||||
|
||||
user_inputs: list[str] = args.input
|
||||
|
||||
file_inputs = parseFileInput(args.input_file)
|
||||
user_inputs.extend(file_inputs)
|
||||
|
||||
if len(user_inputs) == 0:
|
||||
logger.warning("no ID nor URL provided")
|
||||
return
|
||||
@@ -176,7 +180,9 @@ def main():
|
||||
)
|
||||
|
||||
if file_extension:
|
||||
track_path = convertToFlac(source_path=track_path, file_extension=file_extension)
|
||||
track_path = convertToFlac(
|
||||
source_path=track_path, file_extension=file_extension
|
||||
)
|
||||
|
||||
if not cover_data:
|
||||
cover = Cover(track["album"]["cover"])
|
||||
|
||||
@@ -76,6 +76,16 @@ parser.add_argument(
|
||||
action="store_true",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
type=str,
|
||||
nargs="?",
|
||||
const=True,
|
||||
help="choose a file with urls (.txt file separated with newlines or .json list)",
|
||||
dest="input_file",
|
||||
default="",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--no-skip",
|
||||
help="dont skip already downloaded tracks",
|
||||
|
||||
+22
-1
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
@@ -17,6 +18,26 @@ RESOURCE_LIST: List[RESOURCE] = list(get_args(RESOURCE))
|
||||
logger = logging.getLogger("utils")
|
||||
|
||||
|
||||
def parseFileInput(file: str) -> list[str]:
|
||||
_, file_extension = os.path.splitext(file)
|
||||
urls_set: set[str] = set()
|
||||
|
||||
if file_extension == ".txt":
|
||||
with open(file) as f:
|
||||
data = f.read()
|
||||
urls_set.update(data.splitlines())
|
||||
elif file_extension == ".json":
|
||||
with open(file) as f:
|
||||
data = json.load(f)
|
||||
urls_set.update(data)
|
||||
else:
|
||||
logger.warning(f"a file with '{file_extension}' extension is not supported!")
|
||||
|
||||
filtered_urls = [url for url in urls_set if type(url) == str]
|
||||
|
||||
return filtered_urls
|
||||
|
||||
|
||||
def parseURL(url: str) -> tuple[RESOURCE, str]:
|
||||
# remove trailing slash
|
||||
url = url.rstrip("/")
|
||||
@@ -131,7 +152,7 @@ def setMetadata(file_path: str, track: Track, cover_data=b""):
|
||||
metadata.save()
|
||||
|
||||
|
||||
def convertToFlac(source_path: str, file_extension: str,remove_source=True):
|
||||
def convertToFlac(source_path: str, file_extension: str, remove_source=True):
|
||||
source_dir, source_extension = os.path.splitext(source_path)
|
||||
dest_path = f"{source_dir}.{file_extension}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user