2022-11-19 15:14:12 -08:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import typer
|
|
|
|
|
2022-11-20 16:26:40 -08:00
|
|
|
from pathlib import Path
|
2022-12-06 16:34:58 -08:00
|
|
|
from typing import Optional
|
2022-11-19 15:14:12 -08:00
|
|
|
from dotenv import load_dotenv
|
2022-12-21 15:17:13 -08:00
|
|
|
from rich.logging import RichHandler
|
2022-11-20 01:00:54 -08:00
|
|
|
|
2022-11-30 00:09:23 -08:00
|
|
|
from groove.shell import interactive_shell
|
2022-11-20 09:28:00 -08:00
|
|
|
from groove.db.manager import database_manager
|
2022-12-02 21:43:51 -08:00
|
|
|
from groove.webserver import webserver
|
2022-11-19 15:14:12 -08:00
|
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
|
2022-11-20 01:00:54 -08:00
|
|
|
def initialize():
|
|
|
|
load_dotenv()
|
2022-11-20 09:28:00 -08:00
|
|
|
debug = os.getenv('DEBUG', None)
|
2022-12-21 15:17:13 -08:00
|
|
|
logging.basicConfig(
|
|
|
|
format='%(message)s',
|
|
|
|
level=logging.DEBUG if debug else logging.INFO,
|
|
|
|
handlers=[
|
|
|
|
RichHandler(rich_tracebacks=True, tracebacks_suppress=[typer])
|
|
|
|
]
|
|
|
|
)
|
|
|
|
logging.getLogger('asyncio').setLevel(logging.ERROR)
|
2022-11-20 01:00:54 -08:00
|
|
|
|
|
|
|
|
2022-12-21 15:17:13 -08:00
|
|
|
@app.command()
|
2022-11-25 15:40:24 -08:00
|
|
|
def list():
|
|
|
|
"""
|
|
|
|
List all Playlists
|
|
|
|
"""
|
|
|
|
initialize()
|
|
|
|
with database_manager() as manager:
|
2022-12-21 15:17:13 -08:00
|
|
|
shell = interactive_shell.InteractiveShell(manager)
|
|
|
|
shell.list(None)
|
2022-11-25 15:40:24 -08:00
|
|
|
|
|
|
|
|
2022-11-20 16:26:40 -08:00
|
|
|
@app.command()
|
|
|
|
def scan(
|
2022-12-21 15:17:13 -08:00
|
|
|
path: Optional[Path] = typer.Option(
|
|
|
|
'',
|
|
|
|
help="A path to scan, relative to your MEDIA_ROOT. "
|
|
|
|
"If not specified, the entire MEDIA_ROOT will be scanned."
|
2022-11-20 16:26:40 -08:00
|
|
|
),
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Scan the filesystem and create track entries in the database.
|
|
|
|
"""
|
|
|
|
initialize()
|
|
|
|
with database_manager() as manager:
|
2022-12-21 15:17:13 -08:00
|
|
|
shell = interactive_shell.InteractiveShell(manager)
|
|
|
|
shell.console.print("Starting the Groove on Demand scanner...")
|
|
|
|
shell.scan([str(path)])
|
2022-11-27 18:42:46 -08:00
|
|
|
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def shell():
|
|
|
|
initialize()
|
2022-11-30 00:09:23 -08:00
|
|
|
interactive_shell.start()
|
2022-11-20 16:26:40 -08:00
|
|
|
|
2022-11-24 13:45:09 -08:00
|
|
|
|
2022-11-19 15:14:12 -08:00
|
|
|
@app.command()
|
|
|
|
def server(
|
|
|
|
host: str = typer.Argument(
|
|
|
|
'0.0.0.0',
|
|
|
|
help="bind address",
|
|
|
|
),
|
|
|
|
port: int = typer.Argument(
|
|
|
|
2323,
|
|
|
|
help="bind port",
|
|
|
|
),
|
|
|
|
debug: bool = typer.Option(
|
|
|
|
False,
|
|
|
|
help='Enable debugging output'
|
|
|
|
),
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Start the Groove on Demand playlsit server.
|
|
|
|
"""
|
2022-11-20 09:28:00 -08:00
|
|
|
initialize()
|
2022-11-20 16:26:40 -08:00
|
|
|
with database_manager() as manager:
|
2022-11-20 09:28:00 -08:00
|
|
|
manager.import_from_filesystem()
|
|
|
|
webserver.start(host=host, port=port, debug=debug)
|
2022-11-19 15:14:12 -08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app()
|