feat: Support artist - song format in command line arguments

Updated the CLI to accept arguments in two formats:
1. Single argument with dash separator: "ARTIST - SONG"
2. Two separate arguments: ARTIST SONG

This makes it more convenient for users to input artist and song information.
Also updated README to document both usage formats.
This commit is contained in:
2025-08-11 14:28:04 +02:00
parent d53c080ce6
commit 43a8203f70
2 changed files with 32 additions and 6 deletions

View File

@@ -28,8 +28,14 @@ A Python package to fetch song lyrics from [paroles.net](https://www.paroles.net
### Command Line Interface
After installation, you can use the command line interface:
After installation, you can use the command line interface with two formats:
1. Single argument with dash separator:
```bash
paroles-scraper "Artist Name - Song Title"
```
2. Two separate arguments:
```bash
paroles-scraper "Artist Name" "Song Title"
```
@@ -37,6 +43,7 @@ paroles-scraper "Artist Name" "Song Title"
### Examples
```bash
paroles-scraper "SCORPIONS - SEND ME AN ANGEL"
paroles-scraper "Ed Sheeran" "Shape of You"
paroles-scraper "Imagine Dragons" "Believer"
```

View File

@@ -125,25 +125,44 @@ def search_song(artist, song_title):
def main():
parser = argparse.ArgumentParser(description='Fetch song lyrics from paroles.net')
parser.add_argument('artist', help='Artist name')
parser.add_argument('song', help='Song title')
parser.add_argument('query', help='Artist and song in format "ARTIST - SONG TITLE" or separate artist and song arguments')
parser.add_argument('song', nargs='?', help='Song title (optional if using ARTIST - SONG format)')
parser.add_argument('--search', action='store_true', help='Use search functionality instead of direct URL construction')
args = parser.parse_args()
# Handle both input formats:
# 1. Single argument: "ARTIST - SONG TITLE"
# 2. Two arguments: ARTIST SONG_TITLE
if args.song is None:
# Single argument format: split on " - "
if " - " in args.query:
artist, song = args.query.split(" - ", 1)
else:
print("Error: Please provide artist and song in format 'ARTIST - SONG TITLE'")
return
else:
# Two argument format: artist and song provided separately
artist = args.query
song = args.song
# Strip any leading/trailing whitespace
artist = artist.strip()
song = song.strip()
if args.search:
# First search for the song to get the correct URL
search_result = search_song(args.artist, args.song)
search_result = search_song(artist, song)
if search_result.startswith("http"):
# Extract artist and song from the URL
print(f"Found song at: {search_result}")
# For simplicity, we'll still call get_song_lyrics with original params
lyrics = get_song_lyrics(args.artist, args.song)
lyrics = get_song_lyrics(artist, song)
print(lyrics)
else:
print(search_result) # Print error message
else:
lyrics = get_song_lyrics(args.artist, args.song)
lyrics = get_song_lyrics(artist, song)
print(lyrics)