Skip to content

Just play a song and sngfetch will recognize it and give you all the details right in the command line.

License

Notifications You must be signed in to change notification settings

lenartkladnik/Sngfetch

Repository files navigation

Sngfetch 🎵

A Python application that identifies a song through your microphone and fetches detailed information about it.

Python License

1. About

Sngfetch is a Python app designed to retrieve data about a song by analyzing audio captured through your microphone.
With Sngfetch, you can:

  • Identify a song.
  • Fetch song metadata (e.g., title, artist, album).
  • Optionally retrieve the song lyrics.

2. How It Works

Sngfetch utilizes three APIs:

  1. Shazam API: To identify the song and its metadata.

    Note: The shazam api is accessed trough shazamio.

  2. Deezer API: To provide additional details about the song.
  3. Genius API: (Optional) To fetch song lyrics.

    Note: To use the Genius API, you'll need to create a free account and register an application to get your client access token.


3. Getting Started

Prerequisites

Make sure you have the following:

  • Python 3.7+

    Only if you are running the python file yourself.

  • A microphone-enabled device.

Running

  1. Clone the repository:

    git clone https://github.com/pyth0g/Sngfetch.git
    cd Sngfetch
  2. Here you can either use a packaged python binary from the ./bin folder (windows or linux), or you can run the python file:

    This should work but there are some issues with shazamio that can arise:

    python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
    cd src
    python sngfetch.py -h

    In case you get an error when installing the packages try:

    python -m venv .venv
    source .venv/bin/activate
    git clone https://github.com/shazamio/shazamio-core.git
    cd shazamio-core
    pip install .
    cd ..
    pip install -r requirements.txt
    cd src
    python sngfetch.py -h

Packaging

If you wish to package the app yourself:

  • Make sure that if you are using a virtual environment your source is in the env, then run:
    pip install pyinstaller
    pyinstaller sngfetch.spec
    This will create a dist folder in which is your executable.

4. Usage

  • Run the file with the instructions from Running.
  • These are all the possible flags:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -l, --lyrics          Display the lyrics of the song fetched.
  -ls, --lyrics-setup   Setup the access token for the Genius API.
  -cd, --continuous-until-different [CONTINUOUS_UNTIL_DIFFERENT]
                        Keep searching even after a song is found, you can specify the delay between searches after the flag, stop by keyboard interrupt.
  -c, --continuous [CONTINUOUS]
                        Keep searching even after a song is found, you can specify the delay between searches after the flag, stop by keyboard interrupt.
  -hi, --history [HISTORY]
                        Show the history of fetched songs or a specific song by title.
  -hic, --history-clear
                        Clear all the history of fetched songs.
  -m, --minimalist [MINIMALIST]
                        Display data in a more minimal style the amount of data can be controlled with an integer (0..2) after the flag.
  -r, --remove REMOVE   Remove a song from the history by it's title.
  -d, --duration DURATION
                        The default duration of each audio sample to be taken in seconds.
  -t, --total TOTAL     The total amount of time to listen for in seconds.
  -inc, --increase INCREASE
                        Increase the duration of each audio sample to be taken in seconds.
  -i, --infinite        Keep trying until interrupted.
  -s, --size SIZE       The size of the cover art.
  --debug               Debug mode.
  -ve, --verbosity VERBOSITY
                        Set the verbosity level of debug (will only have affect if debug is on).
  --disable-stdout      Disable stdout and remove it from log.
  --log                 Log all the output in sngfetch_i.log in the current directory (recommended to use in conjunction with disable-stdout).
  --freeze FREEZE       Freeze basic song data to specified json file.

Setting up lyrics

To setup lyrics fetching you will need to:

  • Visit https://genius.com/api-clients and sign up for an account.
  • Click on New API Client, fill out the form (you can put in any data) and click save.
  • Click on Generate Access Token (bellow Client Secret) and copy the token.
  • Run the program with the -ls or --lyrics-setup flag, it will create the file where you can store the token.
  • The program will prompt you to open the file, confirm and paste the token in after Access-Token:

5. Examples

Result

Single Result

Lyrics

Result with lyrics

History

History

Demo Video

Demo Video


6. Contributing

Contributions are welcome! Here's how you can contribute:

  • Fork the repository.
  • Create a new branch (git checkout -b feature/YourFeature).
  • Commit your changes (git commit -m 'Add YourFeature').
  • Push to the branch (git push origin feature/YourFeature).
  • Open a pull request.

7. License

Distributed under the MIT License. See LICENSE.txt for more information.


8. Contact

For any questions or issues, please open an issue on the GitHub repository.
I will try to get back to you as soon as possible.

About

Just play a song and sngfetch will recognize it and give you all the details right in the command line.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages