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"]
|
||||
url_str = " ".join(pending)
|
||||
try:
|
||||
youtube_ids = Parser(url_str).parse()
|
||||
except ValueError:
|
||||
message = f"failed to parse: {url_str}"
|
||||
print(message)
|
||||
return Response({"message": message}, status=400)
|
||||
# try:
|
||||
# youtube_ids = Parser(url_str).parse()
|
||||
# except ValueError:
|
||||
# message = f"failed to parse: {url_str}"
|
||||
# print(message)
|
||||
# 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)
|
||||
|
||||
|
|
|
@ -42,6 +42,10 @@ class Parser:
|
|||
youtube_id = parsed.path.strip("/")
|
||||
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)
|
||||
if "v" in query_parsed:
|
||||
# video from v query str
|
||||
|
|
|
@ -117,6 +117,7 @@ def test_passing_parse(url_str, expected_result):
|
|||
INVALID_IDS_ERRORS = [
|
||||
"aaaaa",
|
||||
"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"):
|
||||
parser = Parser(invalid_value)
|
||||
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