musicdlp/backend/response.py

37 lines
762 B
Python

import json
import logging
from typing import Literal
def playlist(items: list[str]) -> str:
return json.dumps({
"type": "items",
"data": items,
})
type YdlLogLevel = Literal['debug'] | Literal['warning'] | Literal['error']
def ydl_log(level: YdlLogLevel, msg: str) -> str:
return json.dumps({
"type": "ydl_log",
"level": level,
"data": msg,
})
def ydl_end(ret: int) -> str:
return json.dumps({
"type": "ydl_end",
"data": ret,
})
def error(ex: Exception) -> str:
logging.getLogger('musicdlp').exception(ex)
return json.dumps({
"type": "error",
"data": {
"type": ex.__class__.__qualname__,
"message": str(ex),
}
})