Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "lyrics_sync",
"name": "Lyrics Sync",
"version": "1.0.1",
"version": "1.0.2",
"private": false,
"nav": {
"label": "Lyrics Sync",
Expand Down
22 changes: 20 additions & 2 deletions routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
from pathlib import Path, PurePosixPath, PureWindowsPath
from urllib.parse import quote

from fastapi import FastAPI
from fastapi.responses import JSONResponse, Response
Expand Down Expand Up @@ -219,7 +220,13 @@ def ls_align(data: dict):
502,
)

result = resp.json()
try:
result = resp.json()
except ValueError:
return JSONResponse(
{"error": "Alignment server returned a malformed response"},
502,
)
if "error" in result:
return JSONResponse(
{"error": f"Alignment failed: {result['error']}"},
Expand Down Expand Up @@ -260,11 +267,22 @@ def ls_export(data: dict):
safe_name = f"{artist} - {title}".strip(" -") or "lyrics"
safe_name = safe_name.replace("/", "_").replace("\\", "_")

# Quote-escape for the legacy `filename=` fallback, and provide an
# RFC 5987 `filename*=` form so non-ASCII / quote characters in
# title-artist can't corrupt or break out of the header value.
# The `\` escape is a no-op today (safe_name already stripped `\`
# above) but guards this line if that stripping ever changes.
ascii_name = safe_name.replace("\\", "\\\\").replace('"', '\\"')
Comment thread
cchacs marked this conversation as resolved.
Resolved
encoded_name = quote(f"{safe_name}.lrc", safe="")

return Response(
content=lrc,
media_type="text/plain",
headers={
"Content-Disposition": f'attachment; filename="{safe_name}.lrc"',
"Content-Disposition": (
f'attachment; filename="{ascii_name}.lrc"; '
f"filename*=UTF-8''{encoded_name}"
),
},
)

Expand Down
Loading