Files
musicfetch/server/mf.py

52 lines
2.1 KiB
Python

"""Loads the sibling standalone `musicfetch` script (no .py extension) as a
module and re-exports the symbols the API reuses. This is the single seam
between the REST API and the CLI; musicfetch itself is unchanged."""
import importlib.machinery
import importlib.util
import os
import sys
_HERE = os.path.dirname(os.path.abspath(__file__))
_MF_PATH = os.environ.get("MUSICFETCH_BIN", os.path.join(_HERE, "..", "musicfetch"))
# spec_from_file_location returns None for extension-less files, so use
# SourceFileLoader directly to handle the bare `musicfetch` binary.
_loader = importlib.machinery.SourceFileLoader("musicfetch_core", _MF_PATH)
_spec = importlib.util.spec_from_loader("musicfetch_core", _loader)
_mod = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_mod) # safe: musicfetch guards main() behind __main__
sys.modules["musicfetch_core"] = _mod
Hit = _mod.Hit
build_combined_hits = _mod.build_combined_hits
lidarr_search = _mod.lidarr_search
find_library_artist = _mod.find_library_artist
ensure_artist = _mod.ensure_artist
ensure_album = _mod.ensure_album
list_releases = _mod.list_releases
sort_releases = _mod.sort_releases
release_label = _mod.release_label
grab_release = _mod.grab_release
pick = _mod.pick
act_youtube = _mod.act_youtube
act_lidarr_album = _mod.act_lidarr_album
act_lidarr_artist = _mod.act_lidarr_artist
QUALITY_CHOICES = _mod.QUALITY_CHOICES
is_url = _mod.is_url
probe_url = _mod.probe_url
download_hits = _mod.download_hits
download_single = _mod.download_single
_is_direct_url = _mod._is_direct_url
odesli_resolve = _mod.odesli_resolve
resolve_link_hits = _mod.resolve_link_hits
handle_link = _mod.handle_link
OdesliError = _mod.OdesliError
__all__ = ["Hit", "build_combined_hits", "lidarr_search", "find_library_artist",
"ensure_artist", "ensure_album", "list_releases", "sort_releases",
"release_label", "grab_release", "pick", "act_youtube",
"act_lidarr_album", "act_lidarr_artist", "QUALITY_CHOICES",
"is_url", "probe_url", "download_hits", "download_single",
"_is_direct_url", "odesli_resolve", "resolve_link_hits",
"handle_link", "OdesliError"]