Coder Social home page Coder Social logo

lyricfy's Introduction

Lyricfy

Song Lyrics for your Ruby apps.

Build Status Code Climate Gem Version

Installation

Add this line to your application's Gemfile:

gem 'lyricfy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lyricfy

Usage

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

The Lyricfy::Fetcher#search method returns a Lyricfy::Song object with the following methods:

  • title
  • author
  • lines
  • body

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.

Changelog

v0.1.0

  • Cleaner API
  • Added a Song class
  • Added custom separators for the lyrics
  • Added memoization. Thanks to @marksim

v0.0.2

  • Fixed a small bug inside Lyricfy::Fetcher#search
  • Added some small refactorings

v0.0.1

  • Initial release

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

lyricfy's People

Contributors

javichito avatar marksim avatar

Watchers

Kain avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.