njh / ruby-playlist

A ruby gem to convert playlists between different formats
https://rubygems.org/gems/playlist
MIT License
7 stars 1 forks source link
cue-sheet jspf m3u playlist ruby xspf

Build Status

Playlist

This ruby gem allows you to create and manipulate playlists of musical tracks.

It supports parsing and generating playlists in the following formats:

Installation

Add this line to your application's Gemfile:

gem 'playlist'

And then execute:

$ bundle

Or install it yourself as:

$ gem install playlist

Usage

For full details, please see the API Documentation.

Creating a Playlist

The playlist gem provides data model classes for creating and manipulating playlists and music metadata in ruby.

Playlists can be constructed by passing a list of attributes to the constructor or by setting the attributes directly:

playlist = Playlist.new(:title => "My awesome playlist")
playlist.description = "Each week I add best tracks I can think of."
playlist.add_track(
  :performer => "Jon Hopkins",
  :title => "Everything Connected"
)

track = Playlist::Track.new(:title => "Get Your Shirt")
track.add_contributor(:name => "Underworld", :role => :performer)
track.add_contributor(:name => "Iggy Pop", :role => :performer)
playlist.add_track(track)

Parsing a playlist file

The playlist gem supports a number of different playlist file formats. Here is an example of parsing a M3U file:

File.open("playlist.m3u") do |file|
  playlist = Playlist::Format::M3U.parse(file)
  puts "The playlist contains #{playlist.tracks.count} tracks"
end

Generating a playlist file

Having created a Playlist object, it can be converted to a playlist file using:

File.open("playlist.m3u", "wb") do |file|
  file.write Playlist::Format::M3U.generate(playlist)
end

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/njh/ruby-playlist.

License

The gem is available as open source under the terms of the MIT License.