navidrome/plugins/pdk/python/host/nd_host_artwork.py

184 lines
5.1 KiB
Python

# Code generated by ndpgen. DO NOT EDIT.
#
# This file contains client wrappers for the Artwork host service.
# It is intended for use in Navidrome plugins built with extism-py.
#
# IMPORTANT: Due to a limitation in extism-py, you cannot import this file directly.
# The @extism.import_fn decorators are only detected when defined in the plugin's
# main __init__.py file. Copy the needed functions from this file into your plugin.
from dataclasses import dataclass
from typing import Any
import extism
import json
class HostFunctionError(Exception):
"""Raised when a host function returns an error."""
pass
@extism.import_fn("extism:host/user", "artwork_getartisturl")
def _artwork_getartisturl(offset: int) -> int:
"""Raw host function - do not call directly."""
...
@extism.import_fn("extism:host/user", "artwork_getalbumurl")
def _artwork_getalbumurl(offset: int) -> int:
"""Raw host function - do not call directly."""
...
@extism.import_fn("extism:host/user", "artwork_gettrackurl")
def _artwork_gettrackurl(offset: int) -> int:
"""Raw host function - do not call directly."""
...
@extism.import_fn("extism:host/user", "artwork_getplaylisturl")
def _artwork_getplaylisturl(offset: int) -> int:
"""Raw host function - do not call directly."""
...
def artwork_get_artist_url(id: str, size: int) -> str:
"""GetArtistUrl generates a public URL for an artist's artwork.
Parameters:
- id: The artist's unique identifier
- size: Desired image size in pixels (0 for original size)
Returns the public URL for the artwork, or an error if generation fails.
Args:
id: str parameter.
size: int parameter.
Returns:
str: The result value.
Raises:
HostFunctionError: If the host function returns an error.
"""
request = {
"id": id,
"size": size,
}
request_bytes = json.dumps(request).encode("utf-8")
request_mem = extism.memory.alloc(request_bytes)
response_offset = _artwork_getartisturl(request_mem.offset)
response_mem = extism.memory.find(response_offset)
response = json.loads(extism.memory.string(response_mem))
if response.get("error"):
raise HostFunctionError(response["error"])
return response.get("url", "")
def artwork_get_album_url(id: str, size: int) -> str:
"""GetAlbumUrl generates a public URL for an album's artwork.
Parameters:
- id: The album's unique identifier
- size: Desired image size in pixels (0 for original size)
Returns the public URL for the artwork, or an error if generation fails.
Args:
id: str parameter.
size: int parameter.
Returns:
str: The result value.
Raises:
HostFunctionError: If the host function returns an error.
"""
request = {
"id": id,
"size": size,
}
request_bytes = json.dumps(request).encode("utf-8")
request_mem = extism.memory.alloc(request_bytes)
response_offset = _artwork_getalbumurl(request_mem.offset)
response_mem = extism.memory.find(response_offset)
response = json.loads(extism.memory.string(response_mem))
if response.get("error"):
raise HostFunctionError(response["error"])
return response.get("url", "")
def artwork_get_track_url(id: str, size: int) -> str:
"""GetTrackUrl generates a public URL for a track's artwork.
Parameters:
- id: The track's (media file) unique identifier
- size: Desired image size in pixels (0 for original size)
Returns the public URL for the artwork, or an error if generation fails.
Args:
id: str parameter.
size: int parameter.
Returns:
str: The result value.
Raises:
HostFunctionError: If the host function returns an error.
"""
request = {
"id": id,
"size": size,
}
request_bytes = json.dumps(request).encode("utf-8")
request_mem = extism.memory.alloc(request_bytes)
response_offset = _artwork_gettrackurl(request_mem.offset)
response_mem = extism.memory.find(response_offset)
response = json.loads(extism.memory.string(response_mem))
if response.get("error"):
raise HostFunctionError(response["error"])
return response.get("url", "")
def artwork_get_playlist_url(id: str, size: int) -> str:
"""GetPlaylistUrl generates a public URL for a playlist's artwork.
Parameters:
- id: The playlist's unique identifier
- size: Desired image size in pixels (0 for original size)
Returns the public URL for the artwork, or an error if generation fails.
Args:
id: str parameter.
size: int parameter.
Returns:
str: The result value.
Raises:
HostFunctionError: If the host function returns an error.
"""
request = {
"id": id,
"size": size,
}
request_bytes = json.dumps(request).encode("utf-8")
request_mem = extism.memory.alloc(request_bytes)
response_offset = _artwork_getplaylisturl(request_mem.offset)
response_mem = extism.memory.find(response_offset)
response = json.loads(extism.memory.string(response_mem))
if response.get("error"):
raise HostFunctionError(response["error"])
return response.get("url", "")