2024-05-02 16:18:27 +03:00
|
|
|
import json
|
2024-05-03 17:42:53 +03:00
|
|
|
import traceback
|
2024-05-02 16:18:27 +03:00
|
|
|
|
|
|
|
OK = '{"ok":true}'
|
|
|
|
|
2024-05-03 17:42:53 +03:00
|
|
|
def ok_playlist(items: list[str]) -> str:
|
2024-05-02 16:18:27 +03:00
|
|
|
return json.dumps({
|
|
|
|
"ok": True,
|
2024-05-03 17:42:53 +03:00
|
|
|
"data": items,
|
2024-05-02 16:18:27 +03:00
|
|
|
})
|
|
|
|
|
2024-05-03 19:10:42 +03:00
|
|
|
def ok_downloaded(ret: int) -> str:
|
2024-05-02 16:18:27 +03:00
|
|
|
return json.dumps({
|
2024-05-03 19:10:42 +03:00
|
|
|
"type": "downloaded",
|
2024-05-03 17:42:53 +03:00
|
|
|
"data": ret,
|
2024-05-02 16:18:27 +03:00
|
|
|
})
|
|
|
|
|
2024-05-03 17:42:53 +03:00
|
|
|
def error(ex: Exception) -> str:
|
|
|
|
traceback.print_tb(ex.__traceback__)
|
2024-05-02 16:18:27 +03:00
|
|
|
return json.dumps({
|
|
|
|
"ok": False,
|
2024-05-03 17:42:53 +03:00
|
|
|
"error": {
|
|
|
|
"type": ex.__class__.__qualname__,
|
|
|
|
"message": str(ex),
|
|
|
|
}
|
2024-05-02 16:18:27 +03:00
|
|
|
})
|