musicdlp/backend/response.py

31 lines
612 B
Python
Raw Normal View History

2024-05-02 16:18:27 +03:00
import json
import traceback
2024-05-02 16:18:27 +03:00
2024-05-05 18:04:18 +03:00
def playlist(items: list[str]) -> str:
2024-05-02 16:18:27 +03:00
return json.dumps({
2024-05-05 18:04:18 +03:00
"type": "items",
"data": items,
2024-05-02 16:18:27 +03:00
})
2024-05-05 18:04:18 +03:00
def dl_progress(msg: str) -> str:
return json.dumps({
"type": "dl_progress",
"data": msg,
})
def dl_end(ret: int) -> str:
2024-05-02 16:18:27 +03:00
return json.dumps({
2024-05-05 18:04:18 +03:00
"type": "dl_end",
"data": ret,
2024-05-02 16:18:27 +03:00
})
def error(ex: Exception) -> str:
traceback.print_tb(ex.__traceback__)
2024-05-02 16:18:27 +03:00
return json.dumps({
2024-05-05 18:04:18 +03:00
"type": "error",
"data": {
"type": ex.__class__.__qualname__,
"message": str(ex),
}
2024-05-02 16:18:27 +03:00
})