Skip to content

Commit edcfd16

Browse files
committed
added the option to specify an array of download links
1 parent b3fba78 commit edcfd16

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

downloader.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,40 @@ class FileType(StrEnum):
1515
AUTO = "auto"
1616

1717

18+
def parse_array_urls_line(urls_line: str) -> list[str]:
19+
urls: list[str] = []
20+
21+
urls_line = urls_line.removeprefix("[").removesuffix("]")
22+
for raw_url in urls_line.split(","):
23+
url = raw_url.strip().strip("'").strip('"')
24+
if url == "":
25+
continue
26+
27+
urls.append(url)
28+
29+
return urls
30+
31+
1832
def get_urls_from_file(input_file: str) -> list[str]:
1933
file_path = Path(input_file)
2034
if not file_path.exists():
2135
exit(f"Файл '{file_path.name}' не существует")
2236

23-
return file_path.read_text(encoding="utf-8").splitlines()
37+
urls: list[str] = []
38+
39+
raw_urls_list = file_path.read_text(encoding="utf-8").splitlines()
40+
for raw_url in raw_urls_list:
41+
url = raw_url.strip()
42+
if url == "":
43+
continue
44+
45+
if url.startswith("[") and url.endswith("]"):
46+
urls.extend(parse_array_urls_line(url))
47+
continue
48+
49+
urls.append(url)
50+
51+
return urls
2452

2553

2654
def regexp_compile(regexp: str) -> Pattern[str] | None:
@@ -37,10 +65,6 @@ def urls_filter(urls: list[str], filter_regexp: str) -> list[str]:
3765

3866
filtered_urls: list[str] = []
3967
for url in urls:
40-
url = url.strip()
41-
if url == "":
42-
continue
43-
4468
if _re.search(url) is None:
4569
continue
4670

0 commit comments

Comments
 (0)