grooveondemand/groove/cli.py

91 lines
2.0 KiB
Python
Raw Normal View History

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
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
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()
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-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
@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)
if __name__ == '__main__':
app()