Skip to main content

MetroLyrics API

Project description

This repo is actually not directly related to Taylor Swift. It’s just a simple Python API for getting lyrics from MetroLyrics. Here is how easy it is:

from tswift import Artist
import random

tswift = Artist('Taylor Swift')
song = random.choice(tswift.songs)
print(song.format())

Setup

This package depends on lxml, requests, and google. These should be installed when you install this package from pip:

pip install tswift

After installing, you can also print a random Taylor Swift song lyric with the command:

tswift

CLI

The module comes with a simple command line interface. By default, it will display a random song by Taylor Swift. You can specify an artist like this:

tswift 'Lynyrd Skynyrd'

You can choose a particular song:

tswift 'Lynyrd Skynyrd' -s Freebird

There is also a “lyric search mode”, which allows you to search for a song by lyrics, e.g.:

tswift -l 'I would walk 500 miles'

Im Gonna Be 500 Miles
Proclaimers
---------------------

When I wake up, well I know I'm gonna be,
I'm gonna be the man who wakes up next you
...

API

Artist class

The constructor takes a single argument, the artist name. This name will be “slugified” in order to use it within URLs. This process involves replacing spaces with hyphens, and making everything lowercase. If this is not sufficient for your particular artist, you’ll need to provide a pre-slugified version of their name.

  • songs - a list of Song instances by this artist. This will call load() if it hasn’t been called yet

  • name - the artist’s slugified name

  • load() - populates the songs list

Song class

The constructor can be called in two ways. In the first, you provide a Metrolyrics URL, and the class will infer the artist and song title:

s = Song(url='url here')

In the second way, you provide a title and artist, which will be slugified.

s = Song('Taylor Swift', 'Love Story')

The attributes are:

  • lyrics - a string. Accessing this will call load() if not yet loaded

  • title - de-slugified title of song

  • artist - de-slugified artist name

  • load() - loads the lyrics

  • format() - returns the lyrics, with a header that includes the title and artist.

The static method Song.find_song(lyrics) takes a string with a search term, and performs a Google search. It returns a Song instance corresponding to the first Metrolyrics link it finds, stopping after 20 results. If nothing is found, returns None.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tswift-0.7.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

tswift-0.7.0-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tswift-0.7.0.tar.gz.

File metadata

  • Download URL: tswift-0.7.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for tswift-0.7.0.tar.gz
Algorithm Hash digest
SHA256 6d1513e012c23201398c65dc29111c97d59472d7f7cec4578528872630e9eeb3
MD5 50a1917b1aebab8b66ea7862febc33d0
BLAKE2b-256 4f0eb9a5308c034405adc0d2d21f3acf8a4a33dbf04852e70fd315bc949a29e2

See more details on using hashes here.

File details

Details for the file tswift-0.7.0-py2.py3-none-any.whl.

File metadata

  • Download URL: tswift-0.7.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for tswift-0.7.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dd217370b1010f6c11999ffeed4a881f954f487bf6736cca2c22e6c4e5311a48
MD5 a2f9f09dcb9d6c6708297458d33d5b9b
BLAKE2b-256 3336ba45cba648a688190d9fe6ed267ae2074b85278b05a9e13cce9c9454adad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page