diff --git a/README.md b/README.md index 3cd525a..98f1daf 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ pip install lyricy - Easy to add lyrics to your offline songs - Preview of lyrics - Synced lyrics with lru time tags -- Lyrics lru without tags +- Lyrics without lru tags +- Save lyrics as lru file +- Add your own lyrics or downloaed lyrics to songs ## Usage @@ -42,10 +44,18 @@ Commands: show Show the lyrics of TRACK if available. ``` +- [Searching for lyrics using your queries](#searching-for-lyrics-using-your-queries) +- [Searching for lyrics for your track](#searching-for-lyrics-for-your-track) +- [Adding lyrics](#adding-lyrics) +- [Remove lyrics](#remove-lyrics) +- [Show lyrics](#show-lyrics) +- [Downloading lrc file](#downloading-lrc-file) +- [Add lrc file to song](#add-lrc-file-to-song) + ### Searching for lyrics using your queries ```txt -Usage: [OPTIONS] +Usage: python -m lyricy search [OPTIONS] Search for lyrics for given track or query @@ -53,8 +63,9 @@ Options: -t, --track PATH file path of track -d, --disable-preview Disable the preview -l, --only-lyrics Show Lyrics Only (without LRC tag) + -s, --save TEXT Save file as .lrc -q, --query TEXT search query of track name - --help Show this message and exit. + --help Show this message and exit ``` ```bash @@ -76,26 +87,32 @@ After searching it print list of lyrics, enter the index number lyrics to get th Adding lyrics to track metadata to get synced lyrics ```txt -Usage: lyricy add [OPTIONS] TRACK +Usage: python -m lyricy add [OPTIONS] TRACK Search and add lyrics to given TRACK. TRACK is the filepath of track. Options: + -q, --query TEXT search for this query instead of track name -d, --disable-preview Disable the preview --show Print the lyrics and ask for confirmation + --lru PATH Lyrics file to add on track --help Show this message and exit. ``` -Track must have ablum metameta `title` - ```bash lyricy add 'Imagine Dragons - Believer.mp3' ``` select the prefferd lyrics for the song to add it +If track does not have metadata `title` or any other unrevelant name, use can use `--query` option to override this. + +```bash +lyricy add 'some-track.mp3' --query "vikram title track" +``` + ### Remove lyrics ```txt @@ -131,6 +148,22 @@ Options: lyricy show 'Imagine Dragons - Believer.mp31 ``` +### Downloading lrc file + +```bash +lyricy search --query "new york" --save "new_york" +``` + +This search and ask for the prompt, select any song it will download and save as `lrc` file + +### Add lrc file to song + +```bash +lyricy add track.mp3 --lru track.lru +``` + +It will add the lyrics to song metadata + ## Source of lyrics All lyrics are scraped from [https://www.megalobiz.com/](https://www.megalobiz.com/) diff --git a/lyricy/cli.py b/lyricy/cli.py index 1fe6cbe..35b36cd 100644 --- a/lyricy/cli.py +++ b/lyricy/cli.py @@ -5,6 +5,7 @@ import pylrc from rich import print from rich.columns import Columns +from rich import box from rich.console import Console from rich.panel import Panel from rich.text import Text @@ -50,8 +51,9 @@ def cli(): @click.option( "--only-lyrics", "-l", is_flag=True, help="Show Lyrics Only (without LRC tag)" ) +@click.option("-s", "--save", help="Save file as .lrc") @click.option("-q", "--query", type=str, help="search query of track name") -def search(track: str, query: str, disable_preview: bool, only_lyrics: bool): +def search(track: str, query: str, disable_preview: bool, only_lyrics: bool, save: str): """Search for lyrics for given track or query""" if track: f = music_tag.load_file(track) @@ -81,45 +83,56 @@ def search(track: str, query: str, disable_preview: bool, only_lyrics: bool): lyric = Megalobiz.get_lyrics(selected_lyrics.link) if only_lyrics: - lyric_panel = Panel( - Text(lyrics_without_tags(lyric), justify="left"), - title=selected_lyrics.title, - ) + if save: + with open(f"{save}.lru", "w") as file: + file.write(lyrics_without_tags(lyric)) + print(lyrics_without_tags(lyric)) else: - lyric_panel = Panel(Text(lyric, justify="left"), title=selected_lyrics.title) - print(lyric_panel) + if save: + with open(f"{save}.lru", "w") as file: + file.write(lyric) + print(lyric) @click.command() @click.argument("track", type=click.Path(exists=True)) +@click.option("--query", "-q", help="search for this query instead of track name") @click.option("--disable-preview", "-d", is_flag=True, help="Disable the preview") @click.option("--show", is_flag=True, help="Print the lyrics and ask for confirmation") -def add(track, show, disable_preview): +@click.option("--lru", type=click.Path(exists=True), help="Lyrics file to add on track") +def add(track: str, show: bool, disable_preview: bool, lru: str, query: str): """Search and add lyrics to given TRACK. TRACK is the filepath of track. """ f = music_tag.load_file(track) - title = str(f["title"]) - with console.status(f"[bold green]Searching lyrics for {title}") as _: - results = Megalobiz.search_lyrics(title) - - songs_lyrics_renderables = [ - Panel(format_table(result, disable_preview), expand=True) for result in results - ] - console.print(Columns(songs_lyrics_renderables)) - - selected_lyrics_index = str( - click.prompt("Enter the index of lyrics", type=int, default=1) - 1 - ) + if lru: + with open(lru, "r") as file: + lyric = file.read() + else: + if query: + title = query + else: + title = str(f["title"]) + with console.status(f"[bold green]Searching lyrics for {title}") as _: + results = Megalobiz.search_lyrics(title) + + songs_lyrics_renderables = [ + Panel(format_table(result, disable_preview), expand=True) + for result in results + ] + console.print(Columns(songs_lyrics_renderables)) + + selected_lyrics_index = str( + click.prompt("Enter the index of lyrics", type=int, default=1) - 1 + ) - selected_lyrics = results[int(selected_lyrics_index)] - with console.status("[bold green]Fetching Lyrics") as _: - lyric = Megalobiz.get_lyrics(selected_lyrics.link) + selected_lyrics = results[int(selected_lyrics_index)] + with console.status("[bold green]Fetching Lyrics") as _: + lyric = Megalobiz.get_lyrics(selected_lyrics.link) if show: - lyric_panel = Panel(Text(lyric, justify="left"), title=selected_lyrics.title) - print(lyric_panel) + print(lyric) if click.confirm("Do you want add this lyrics?", abort=True): with console.status("[bold green]Adding Lyrics") as _: @@ -157,12 +170,9 @@ def show(track, only_lyrics): f = music_tag.load_file(track) lyric = str(f["lyrics"]) if only_lyrics: - lyric_panel = Panel( - Text(lyrics_without_tags(lyric), justify="left"), title=str(f["title"]) - ) + print(lyrics_without_tags(lyric)) else: - lyric_panel = Panel(Text(lyric, justify="left"), title=str(f["title"])) - print(lyric_panel) + print(lyric) cli.add_command(search) diff --git a/lyricy/source.py b/lyricy/source.py index a35a711..f57d141 100644 --- a/lyricy/source.py +++ b/lyricy/source.py @@ -37,7 +37,9 @@ def search_lyrics(song_name: str) -> list[Lyrics]: ) if len(results) == 0: - return None + return [ + Lyrics(title=" No result found", link="", sample_lyrics="", index="1") + ] else: return results diff --git a/setup.py b/setup.py index 108e691..21b3e1f 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='lyricy', - version='1.0.0', + version='1.1', author='Yogeshwaran R', author_email='yogeshin247@gmail.com', description='A command line lyrics utitly tool which \