diff --git a/app/library/HttpAPI.py b/app/library/HttpAPI.py index f629d777..45a53f3a 100644 --- a/app/library/HttpAPI.py +++ b/app/library/HttpAPI.py @@ -262,8 +262,8 @@ class HttpAPI: response: Response = await handler(request) - contentType: str | None = response.headers.get("content-type", None) - if contentType and contentType.startswith("text/html"): + contentType: str = response.headers.get("content-type", "") + if contentType.startswith("text/html") and getattr(response, "_path", None): rewrite_path: str = base_path.rstrip("/") async with await anyio.open_file(response._path, "rb") as f: content = await f.read() diff --git a/app/library/YTDLPOpts.py b/app/library/YTDLPOpts.py index f5ccab41..7d5d323c 100644 --- a/app/library/YTDLPOpts.py +++ b/app/library/YTDLPOpts.py @@ -29,7 +29,11 @@ class ARGSMerger: if not args or not isinstance(args, str) or len(args) < 2: return self - _args: list[str] = shlex.split(args) + _args: list[str] = shlex.split( + # Filter out comment lines. + "\n".join([line for line in args.split("\n") if not line.lstrip().startswith("#")]) + ) + if len(_args) > 0: self.args.extend(_args) diff --git a/app/tests/test_ytdlpopts.py b/app/tests/test_ytdlpopts.py index 6abdcdbe..8cc7a35f 100644 --- a/app/tests/test_ytdlpopts.py +++ b/app/tests/test_ytdlpopts.py @@ -527,6 +527,80 @@ class TestARGSMerger: assert result is merger # Returns self for chaining assert merger.args == ["--format", "best"] + def test_add_filters_comment_lines(self): + """Test that comment lines (starting with #) are filtered out.""" + from app.library.YTDLPOpts import ARGSMerger + + merger = ARGSMerger() + cli_with_comments = """--format best +# This is a comment +--output test.mp4 +#Another comment without space +--no-playlist""" + + merger.add(cli_with_comments) + + # Comments should be filtered out + assert "#" not in merger.as_string() + assert "This is a comment" not in merger.as_string() + assert "Another comment" not in merger.as_string() + + # Valid options should remain + assert "--format" in merger.args + assert "best" in merger.args + assert "--output" in merger.args + assert "test.mp4" in merger.args + assert "--no-playlist" in merger.args + + def test_add_filters_indented_comment_lines(self): + """Test that indented comment lines are filtered out.""" + from app.library.YTDLPOpts import ARGSMerger + + merger = ARGSMerger() + cli_with_indented_comments = """--format best + # Indented comment with spaces + # Indented comment with tabs + --output test.mp4 + # Another indented comment +--socket-timeout 30""" + + merger.add(cli_with_indented_comments) + + # Comments should be filtered out + result = merger.as_string() + assert "# Indented comment with spaces" not in result + assert "# Indented comment with tabs" not in result + assert "# Another indented comment" not in result + + # Valid options should remain + assert "--format" in merger.args + assert "--output" in merger.args + assert "--socket-timeout" in merger.args + + def test_add_filters_complex_commented_extractor_args(self): + """Test filtering of complex real-world commented extractor-args.""" + from app.library.YTDLPOpts import ARGSMerger + + merger = ARGSMerger() + cli_with_complex_comments = """--extractor-args "youtube:player-client=default,tv,mweb,-web_safari;formats=incomplete" +#--extractor-args "youtube:player-client=default,tv,mweb;-formats=incomplete;player_js_version=actual" +#--extractor-args "youtube:player-client=default,tv,mweb,web_safari;formats=incomplete" +--socket-timeout 60""" + + merger.add(cli_with_complex_comments) + + result = merger.as_string() + + # Commented lines should be filtered out completely + assert "player_js_version=actual" not in result + # Check the specific commented variant (with comma before web_safari, not dash) + assert "mweb,web_safari;formats=incomplete" not in result + + # Valid extractor-args should remain (with -web_safari, note the dash) + assert "youtube:player-client=default,tv,mweb,-web_safari;formats=incomplete" in result + assert "--socket-timeout" in merger.args + assert "60" in merger.args + def test_add_multiple_args_with_chaining(self): """Test adding multiple arguments using method chaining.""" from app.library.YTDLPOpts import ARGSMerger diff --git a/ui/app/components/GetInfo.vue b/ui/app/components/GetInfo.vue index 67b9006f..9269f982 100644 --- a/ui/app/components/GetInfo.vue +++ b/ui/app/components/GetInfo.vue @@ -16,7 +16,7 @@ const props = defineProps<{ code_classes?: string }>() -const isLoading = ref(false) +const isLoading = ref(true) const data = ref({}) onMounted(async (): Promise => { @@ -35,7 +35,6 @@ onMounted(async (): Promise => { } try { - isLoading.value = true const response = await request(url) const body = await response.text() diff --git a/ui/app/components/ModalText.vue b/ui/app/components/ModalText.vue index 008981da..530095ec 100644 --- a/ui/app/components/ModalText.vue +++ b/ui/app/components/ModalText.vue @@ -31,14 +31,19 @@ code {