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
|
|
|
|
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",
|
2024-05-03 17:42:53 +03:00
|
|
|
"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",
|
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({
|
2024-05-05 18:04:18 +03:00
|
|
|
"type": "error",
|
|
|
|
"data": {
|
2024-05-03 17:42:53 +03:00
|
|
|
"type": ex.__class__.__qualname__,
|
|
|
|
"message": str(ex),
|
|
|
|
}
|
2024-05-02 16:18:27 +03:00
|
|
|
})
|