Skip to content

Middledot/shazam.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shazam.py

Python library for the Shazam API. This library is based off of ShazamAPI and SongRec but some added features.

NOTE: that this is still in its design and development phase. It works and *could* be used in production but beware of possible breaking changes.

Install

pip3 install shazam.py

If you're on linux, you'll also have to install pkg-config and libasound2-dev with your preferred package manager.

Usage

Synchronous Shazam:

from shazam import Shazam

mp3_file = open('a.mp3', 'rb').read()

with Shazam(mp3_file) as shazam:
    print(shazam.result)  # data received from the shazam api
    print(shazam.response.name)  # structured data

A partially-asynchronous method is also provided: (partially because only requests are done asynchronously and not the signature generation. See #1)

from shazam import AsyncShazam

mp3_file = open('a.mp3', 'rb').read()

async with AsyncShazam(mp3_file) as shazam:
    print(shazam.result)
    print(shazam.response.name)

There is also support for using your own session objects and using Shazam and AsyncShazam outside of a context manager using the execute function.

Notes on the Shazam API

Shazam's api takes a "signature" of a song to search in their database before returning a result.

If you want to know more about the specifics of the algorithm, you can read the paper written by a co-founder of Shazam.

The implementation of the algorithm was written by @marin-m in their project. It was adapted to work with python through pyo3 here.

Credits to:

https://github.com/marin-m/SongRec

About

Shazam API wrapper

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors