Skip to content

Commit

Permalink
removed command play
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienPensart committed Nov 12, 2023
1 parent 9d2332b commit 3022f3c
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 287 deletions.
73 changes: 19 additions & 54 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ Commands
-h, --help Show this message and exit.
Commands:
completion Shell completion
console Starts interpreter
database (db) DB management
folder Manage folders
help Print help
local Local music management
music (file) Music file
readme (doc) Generates a README.rst
spotify Spotify tool
version Print version
youtube Youtube tool
completion Shell completion
console Starts interpreter
database (db,edgedb) DB management
folder Manage folders
help Print help
local Local music management
music (file) Music file
readme (doc) Generates a README.rst
spotify Spotify tool
version Print version
youtube Youtube tool
musicbot completion
*******************
Expand Down Expand Up @@ -164,9 +164,10 @@ musicbot database graphiql
Options:
MusicDB options:
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
-h, --help Show this message and exit.
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
--open / --no-open [default: open]
-h, --help Show this message and exit.
musicbot database graphql
*************************
Expand Down Expand Up @@ -219,10 +220,11 @@ musicbot database ui
Explore with EdgeDB UI
Options:
--open / --no-open [default: open]
MusicDB options:
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
-h, --help Show this message and exit.
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
-h, --help Show this message and exit.
musicbot folder
***************
Expand Down Expand Up @@ -408,7 +410,6 @@ musicbot local
clean (wipe) Clean all musics
folders List folders and some stats
help Print help
player (play) Music player
playlist Generate a new playlist
remove (delete) Remove one or more music
scan Load musics
Expand Down Expand Up @@ -495,42 +496,6 @@ musicbot local folders
--output [json|table|m3u] Output format [default: table]
-h, --help Show this message and exit.
musicbot local player
*********************
.. code-block::
Usage: musicbot local player [OPTIONS]
to-fix: keyword=(tofix|todo|spotify-error)
no-artist: artist=^$
no-album: album=^$
no-title: title=^$
no-genre: genre=^$
no-keyword: keyword=^$
no-rating: max_rating=0.0
bests-4.0: keyword=^((?!cutoff|bad|demo|intro).)$,min_rating=4.0
bests-4.5: keyword=^((?!cutoff|bad|demo|intro).)$,min_rating=4.5
bests-5.0: keyword=^((?!cutoff|bad|demo|intro).)$,min_rating=5.0
Options:
MusicDB options:
--dsn TEXT DSN to MusicBot EdgeDB
--graphql TEXT DSN to MusicBot GrapQL
Filter options:
--prefilter [bests-4.0|bests-4.5|bests-5.0|no-album|no-artist|no-genre|no-keyword|no-rating|no-title|to-fix]
Music pre filters (repeatable)
--filter TEXT Music filters (repeatable), fields: genre,keyword,artist,title,album,pattern,min_size,
max_size,min_length,max_length,min_rating,max_rating,limit
Links options:
--kind, --kinds [all|local|local-http|local-ssh|remote|remote-http|remote-ssh]
Generate musics paths of types [default: local]
--relative / --no-relative Generate relative links [default: no-relative]
Ordering options: [mutually_exclusive]
--shuffle / --no-shuffle Randomize selection [default: no-shuffle]
--interleave / --no-interleave Interleave tracks by artist [default: no-interleave]
--vlc-params TEXT VLC params [default: --vout=dummy --aout=pulse]
-h, --help Show this message and exit.
musicbot local playlist
***********************
.. code-block::
Expand Down
4 changes: 2 additions & 2 deletions doc/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions musicbot/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def confirm(ctx: click.Context, param: Any, value: bool) -> None: # pylint: dis
callback=confirm,
)

open_option = click.option(
"--open/--no-open",
"_open",
is_flag=True,
default=True,
show_default=True,
)

lazy_yes_option = click.option(
"--yes",
"-y",
Expand Down
2 changes: 1 addition & 1 deletion musicbot/cli/scan_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def sane_scan_folders(ctx: click.Context, param: click.Parameter, value: tuple[s
value = config_list(ctx, param, value)
limit = ctx.params.pop("limit", None)
extensions = ctx.params.pop("extensions", DEFAULT_EXTENSIONS)
paths = [Path(path) for path in value]
paths = [Path(path).expanduser() for path in value]
folders = ScanFolders(
directories=paths,
limit=limit,
Expand Down
4 changes: 2 additions & 2 deletions musicbot/cli/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import click
from beartype import beartype
from click_option_group import optgroup
from click_skeleton import ExpandedPath, add_options
from click_skeleton import add_options
from rich.table import Table
from rich.text import Text

Expand Down Expand Up @@ -142,7 +142,7 @@ def sane_spotify(ctx: click.Context, param: click.Parameter, value: str | None)
spotify_cache_path_option = optgroup.option(
"--spotify-cache-path",
help="Spotify cache path",
type=ExpandedPath(writable=True, readable=True, dir_okay=False),
type=click.Path(writable=True, readable=True, dir_okay=False),
envvar="MB_SPOTIFY_CACHE_PATH",
default=DEFAULT_SPOTIFY_CACHE_PATH,
callback=config_string,
Expand Down
30 changes: 23 additions & 7 deletions musicbot/commands/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

from musicbot import MusicbotObject, MusicDb, syncify
from musicbot.cli.musicdb import musicdb_options
from musicbot.cli.options import yes_option
from musicbot.cli.options import open_option, yes_option


@click.group(help="DB management", cls=AdvancedGroup, aliases=["db"])
@click.group(help="DB management", cls=AdvancedGroup, aliases=["db", "edgedb"])
@beartype
def cli() -> None:
pass
Expand Down Expand Up @@ -59,28 +59,44 @@ def pgcli(ctx: click.Context, musicdb: MusicDb, pgcli_args: tuple[str, ...]) ->

@cli.command(help="Explore with GraphiQL")
@musicdb_options
@open_option
@beartype
def graphiql(musicdb: MusicDb) -> None:
def graphiql(musicdb: MusicDb, _open: bool) -> None:
if musicdb.graphql:
url = f"{musicdb.graphql}/explore"
MusicbotObject.success(url)
if not MusicbotObject.dry:
print(url)
if _open and not MusicbotObject.dry:
_ = webbrowser.open(url)


@cli.command(help="Explore with EdgeDB UI", context_settings=dict(ignore_unknown_options=True, help_option_names=[]))
@click.pass_context
@click.argument("edgedb_args", nargs=-1, type=click.UNPROCESSED)
@open_option
@musicdb_options
@beartype
def ui(ctx: click.Context, musicdb: MusicDb, edgedb_args: tuple[str, ...]) -> None:
def ui(
ctx: click.Context,
musicdb: MusicDb,
_open: bool,
edgedb_args: tuple[str, ...],
) -> None:
if "--help" in edgedb_args:
MusicbotObject.echo(ctx.get_help())
MusicbotObject.echo("\n")

args = ["edgedb", "ui", "--print-url", "--no-server-check", "--dsn", musicdb.dsn] + list(edgedb_args)
try:
_ = subprocess.run(args, check=True)
# _ = subprocess.run(args, check=True)
url = subprocess.check_output(
" ".join(args),
stderr=subprocess.STDOUT,
shell=True,
text=True,
).strip()
print(url)
if _open and not MusicbotObject.dry:
_ = webbrowser.open(url)
except FileNotFoundError:
MusicbotObject.err("Unable to locate edgedb CLI, please install it first with")
MusicbotObject.tip("curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh")
Expand Down
34 changes: 0 additions & 34 deletions musicbot/commands/local.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import asyncio
import codecs
import io
import logging
import shutil
from dataclasses import asdict
from pathlib import Path
from typing import TextIO

import click
import edgedb

# import progressbar # type: ignore
from beartype import beartype
from click_skeleton import AdvancedGroup
from rich.table import Table
Expand Down Expand Up @@ -42,8 +38,6 @@
scan_folders_argument,
)

# from musicbot.defaults import DEFAULT_VLC_PARAMS

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -339,34 +333,6 @@ async def bests(
MusicbotObject.success(f"Playlists: {len(bests)}")


# @cli.command(aliases=["play"], short_help="Music player", help=FILTERS_REPRS)
# @musicdb_options
# @music_filters_options
# @playlist_options
# @click.option("--vlc-params", help="VLC params", default=DEFAULT_VLC_PARAMS, show_default=True)
# @syncify
# @beartype
# async def player(
# music_filters: list[MusicFilter],
# musicdb: MusicDb,
# vlc_params: str,
# playlist_options: PlaylistOptions,
# ) -> None:
# musicdb.set_readonly()
# if not MusicbotObject.config.quiet or not MusicbotObject.is_test():
# progressbar.streams.unwrap(stderr=True, stdout=True)
# try:
# new_playlist = await musicdb.make_playlist(
# music_filters=frozenset(music_filters),
# )
# new_playlist.play(
# vlc_params=vlc_params,
# playlist_options=playlist_options,
# )
# except io.UnsupportedOperation:
# logger.critical("Unable to load UI")


@cli.command(short_help="Copy selected musics with filters to destination folder", help=FILTERS_REPRS)
@destination_argument
@musicdb_options
Expand Down
2 changes: 0 additions & 2 deletions musicbot/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
MIN_INT: int = 0
MAX_INT: int = 2147483647

# DEFAULT_VLC_PARAMS: str = "--vout=dummy --aout=pulse"

KINDS_CHOICES: frozenset[str] = frozenset(["local", "remote", "remote-ssh", "local-ssh", "local-http", "remote-http", "all"])
DEFAULT_KINDS: frozenset[str] = frozenset(["local"])

Expand Down
2 changes: 1 addition & 1 deletion musicbot/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def human_repr(self) -> str:

def links(self, playlist_options: PlaylistOptions | None = None) -> frozenset[str]:
playlist_options = playlist_options if playlist_options is not None else PlaylistOptions()
folder_links = []
folder_links: list[str] = []
for folder in self.folders:
folder_links.extend(folder.links(playlist_options))
return frozenset(folder_links)
Expand Down
2 changes: 1 addition & 1 deletion musicbot/music_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __repr__(self) -> str:
return "{}"

def help_repr(self) -> str:
return ",".join([f"{k}={v}" for k, v in self._short_repr().items()])
return ",".join([f"{k}={v}" for k, v in self._short_repr().items()]) or "default"


NO_KEYWORD = "^((?!cutoff|bad|demo|intro).)$"
Expand Down
3 changes: 2 additions & 1 deletion musicbot/musicdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ async def make_playlist(
**attr_asdict(music_filter),
)
results.update(intermediate_results)
name = " | ".join([music_filter.help_repr() for music_filter in music_filters])
return Playlist.from_edgedb(
name=" | ".join([music_filter.help_repr() for music_filter in music_filters]),
name=name,
results=list(results),
)

Expand Down
4 changes: 2 additions & 2 deletions musicbot/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def fast_kill(cls) -> NoReturn: # pylint: disable=unused-argument
os.killpg(os.getpid(), signal.SIGKILL)

@classmethod
def print_table(cls, table: Table, file: IO | None = None) -> None:
def print_table(cls, table: Table, file: IO | click.utils.LazyFile | None = None) -> None:
"""Print rich table"""
if file is not None:
console = Console(file=io.StringIO(), width=300)
Expand All @@ -339,7 +339,7 @@ def print_table(cls, table: Table, file: IO | None = None) -> None:
def print_json(
cls,
data: Any,
file: IO | None = None,
file: IO | click.utils.LazyFile | None = None,
option: int | None = orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS | orjson.OPT_NON_STR_KEYS, # pylint: disable=maybe-no-member
default: Callable | None = default_encoder,
) -> None:
Expand Down
Loading

0 comments on commit 3022f3c

Please sign in to comment.