Skip to content

Commit

Permalink
cli: open text editor for lyrics
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Oct 23, 2024
1 parent 4517faa commit 9aea7ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
24 changes: 13 additions & 11 deletions yohane-cli/yohane_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
parse_song_argument,
save_separated_tracks,
)
from yohane_cli.lyrics import parse_lyrics_argument

logger = logging.getLogger(__name__)

Expand All @@ -19,19 +20,18 @@

@app.command(help="Generate a karaoke (full pipeline)")
def generate(
song: Annotated[
Path,
song_file: Annotated[
str,
typer.Argument(
parser=parse_song_argument,
help="Video or audio file of the song. Can be an URL to download with yt-dlp.",
),
],
lyrics: Annotated[
typer.FileText,
lyrics_file: Annotated[
Path | None,
typer.Argument(
help="Text file which contains the lyrics.",
help="Text file which contains the lyrics. (Optional: otherwise, a text editor will open.)",
),
],
] = None,
separator_choice: Annotated[
SeparatorChoice,
typer.Option(
Expand All @@ -41,12 +41,14 @@ def generate(
),
] = SeparatorChoice.VocalRemover,
):
song = parse_song_argument(song_file)
lyrics = parse_lyrics_argument(lyrics_file)
separator = get_separator(separator_choice)

yohane = Yohane(separator)

yohane.load_song(song)
yohane.load_lyrics(lyrics.read())
yohane.load_lyrics(lyrics)

yohane.extract_vocals()
save_separated_tracks(yohane, song)
Expand All @@ -61,10 +63,9 @@ def generate(

@app.command(help="Seperate vocals and instrumental tracks")
def separate(
song: Annotated[
Path,
song_file: Annotated[
str,
typer.Argument(
parser=parse_song_argument,
help="Video or audio file of the song. Can be an URL to download with yt-dlp.",
),
],
Expand All @@ -77,6 +78,7 @@ def separate(
),
] = SeparatorChoice.VocalRemover,
):
song = parse_song_argument(song_file)
separator = get_separator(separator_choice)
if separator is None:
raise RuntimeError("No separator selected")
Expand Down
2 changes: 1 addition & 1 deletion yohane-cli/yohane_cli/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def parse_song_argument(value: str) -> Path:
song_path = Path(value)

if not song_path.is_file():
logger.info(f"Using yt-dlp as {value} is not an existing file")
logger.info("Song file not found, calling yt-dlp")
song_path = ydl_download(value)

if "ffmpeg" not in torchaudio.list_audio_backends():
Expand Down
17 changes: 17 additions & 0 deletions yohane-cli/yohane_cli/lyrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
from pathlib import Path

import click

logger = logging.getLogger(__name__)


def parse_lyrics_argument(value: Path | None) -> str:
if isinstance(value, Path):
return value.read_text()

logger.info("No lyrics text file, opening text editor")
input = click.edit()
if input is None:
raise click.MissingParameter()
return input

0 comments on commit 9aea7ac

Please sign in to comment.