test and better handle invalid domains
This commit is contained in:
parent
cfa0cabd41
commit
30c20b41d9
|
@ -688,14 +688,14 @@ class DownloadApiListView(ApiBaseView):
|
||||||
|
|
||||||
pending = [i["youtube_id"] for i in to_add if i["status"] == "pending"]
|
pending = [i["youtube_id"] for i in to_add if i["status"] == "pending"]
|
||||||
url_str = " ".join(pending)
|
url_str = " ".join(pending)
|
||||||
try:
|
# try:
|
||||||
youtube_ids = Parser(url_str).parse()
|
# youtube_ids = Parser(url_str).parse()
|
||||||
except ValueError:
|
# except ValueError:
|
||||||
message = f"failed to parse: {url_str}"
|
# message = f"failed to parse: {url_str}"
|
||||||
print(message)
|
# print(message)
|
||||||
return Response({"message": message}, status=400)
|
# return Response({"message": message}, status=400)
|
||||||
|
|
||||||
extrac_dl.delay(youtube_ids, auto_start=auto_start)
|
extrac_dl.delay(url_str, auto_start=auto_start)
|
||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ class Parser:
|
||||||
youtube_id = parsed.path.strip("/")
|
youtube_id = parsed.path.strip("/")
|
||||||
return self._validate_expected(youtube_id, "video")
|
return self._validate_expected(youtube_id, "video")
|
||||||
|
|
||||||
|
if "youtube.com" not in parsed.netloc:
|
||||||
|
message = f"invalid domain: {parsed.netloc}"
|
||||||
|
raise ValueError(message)
|
||||||
|
|
||||||
query_parsed = parse_qs(parsed.query)
|
query_parsed = parse_qs(parsed.query)
|
||||||
if "v" in query_parsed:
|
if "v" in query_parsed:
|
||||||
# video from v query str
|
# video from v query str
|
||||||
|
|
|
@ -117,6 +117,7 @@ def test_passing_parse(url_str, expected_result):
|
||||||
INVALID_IDS_ERRORS = [
|
INVALID_IDS_ERRORS = [
|
||||||
"aaaaa",
|
"aaaaa",
|
||||||
"https://www.youtube.com/playlist?list=AAAA",
|
"https://www.youtube.com/playlist?list=AAAA",
|
||||||
|
"https://www.youtube.com/channel/UC9-y-6csu5WGm29I7Jiwpn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,3 +127,17 @@ def test_invalid_ids(invalid_value):
|
||||||
with pytest.raises(ValueError, match="not a valid id_str"):
|
with pytest.raises(ValueError, match="not a valid id_str"):
|
||||||
parser = Parser(invalid_value)
|
parser = Parser(invalid_value)
|
||||||
parser.parse()
|
parser.parse()
|
||||||
|
|
||||||
|
|
||||||
|
INVALID_DOMAINS = [
|
||||||
|
"https://vimeo.com/32001208",
|
||||||
|
"https://peertube.tv/w/8RiJE2j2nw569FVgPNjDt7",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("invalid_value", INVALID_DOMAINS)
|
||||||
|
def test_invalid_domains(invalid_value):
|
||||||
|
"""raise error on none YT domains"""
|
||||||
|
parser = Parser(invalid_value)
|
||||||
|
with pytest.raises(ValueError, match="invalid domain"):
|
||||||
|
parser.parse()
|
||||||
|
|
Loading…
Reference in New Issue