Song Lyrics for your Ruby apps.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install lyricfy
You need to create an instance of the
Lyricfy::Fetcher class and send the
#search message with the artist name and song title respectively. The following example shows the most basic usage.
fetcher = Lyricfy::Fetcher.new song = fetcher.search 'Coldplay', 'Viva la vida' puts song.body # prints lyrics separated by '\n'
You can also pass a custom separator to the
#body method. For example:
lyrics.body("<br>") # returns a String with the song lyrics separated by a <br> tag
Lyricfy::Fetcher#search method returns a
Lyricfy::Song object with the following methods:
Where title is the song title, author is the song artist, lines is an Array of the lyric paragraphs and body returns a String with the song lyrics separated with
\n by default.
How does it work?
Under the hood, this library fetch the song lyrics by scraping some websites called "Providers". The currently supported providers are:
By default this gem will recursively search for the lyric on each of the providers, if the lyric is not found it will return nil. You can also tell Lyricfy to only use the provider(s) that you want.
fetcher = Lyricfy::Fetcher.new(:metro_lyrics) song = fetcher.search 'Coldplay', 'Viva la vida' puts song.body
In this case Lyricfy will look for the lyric only on MetroLyrics.
- Cleaner API
- Added a
- Added custom separators for the lyrics
- Added memoization. Thanks to @marksim
- Fixed a small bug inside
- Added some small refactorings
- Initial release
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request