class RemiAudio::Xspf::Playlist

Overview

The Playlist class contains general information about the playlist, as well as a list of tracks. This also acts as the toplevel class for XSPF/JSPF data, allowing you to read and write XSPF and JSPF files.

Reading an XSPF file:

playlist = File.open("/path/to/file.xspf", "r") do |file|
  RemiAudio::Xspf::Playlist.read(file)
end

# Print the locations for every track
playlist.each do |trk|
  puts trk.locations
end

Writing an XSPF file:

playlist = RemiAudio::Xspf::Playlist.new
playlist.title = "A Neat Playlist"
playlist.add(title: "Rabio", creator: "Partition 36", "/path/to/file/03 - Rabio.mp3")
playlist.add(title: "Searching for My Identity", creator: "Partition 36",
             "/path/to/file/06 - Searching for My Identity.mp3")

puts playlist.write # Write XML to a String
playlist.write("/path/to/dest.xspf") # Write XSPF to a file

# Write JSPF to a file.
playlist.write("/path/to/dest.xspf", RemiAudio::Xspf::Playlist::Format::Json)

Included Modules

Defined in:

remiaudio/xspf/xspf.cr

Constant Summary

VERSION = 1

The version of the specification that we support. Note that version 1 is backwards compatible with version 0.

Constructors

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]
def self.new #

Creates a new Playlist instance. The new instance has no tracks associated with it, and so at least one must be added before it can be serialized.


[View source]
def self.read(io : IO, *, format : Format = Format::Xml) : Playlist #

Creates a new Playlist instance by reading data from io.


[View source]
def self.read(str : String, *, format : Format = Format::Xml) : Playlist #

Creates a new Playlist instance by reading data from str.


[View source]

Instance Method Detail

def add(*locationURIs : URI, title : String | Nil = nil, album : String | Nil = nil, creator : String | Nil = nil, trackNumber : UInt64 | Nil = nil) #

Adds a new track to this playlist.


[View source]
def annotate : String | Nil #

[View source]
def annotate=(annotate : String | Nil) #

[View source]
def attribution : Attribution | Nil #

[View source]
def attribution=(attribution : Attribution | Nil) #

[View source]
def creator : String | Nil #

The human-readable name of the creator of this playlist, if any. If this is nil, then no <creator> element is emitted for the <playlist> element.


[View source]
def creator=(creator : String | Nil) #

The human-readable name of the creator of this playlist, if any. If this is nil, then no <creator> element is emitted for the <playlist> element.


[View source]
def date : Time | Nil #

[View source]
def date=(date : Time | Nil) #

[View source]
def each(& : Track -> ) : Nil #

Loops through all of the tracks in this playlist, yielding a Track instance for each one.


[View source]
def identifier : URI | Nil #

A URI describing the canonical identifier of this playlist. If this is nil, then no <identifier> element is emitted for the <playlist> element.


[View source]
def identifier=(identifier : URI | Nil) #

A URI describing the canonical identifier of this playlist. If this is nil, then no <identifier> element is emitted for the <playlist> element.


[View source]
def image : URI | Nil #

A URI pointing to an image that can be displayed when a track has no artwork of its own. If this is nil, then no <image> element is emitted for the <playlist> element.


[View source]
def image=(image : URI | Nil) #

A URI pointing to an image that can be displayed when a track has no artwork of its own. If this is nil, then no <image> element is emitted for the <playlist> element.


[View source]
def info : URI | Nil #

A URI of a web page that provides more information about this playlist. If this is nil, then no <info> element is emitted for the <playlist> element.


[View source]
def info=(info : URI | Nil) #

A URI of a web page that provides more information about this playlist. If this is nil, then no <info> element is emitted for the <playlist> element.


[View source]
def license : URI | Nil #

A URI to a resource that provides information about the license this playlist is under. If this is nil, then no <license> element is emitted for the <playlist> element.


[View source]
def license=(license : URI | Nil) #

A URI to a resource that provides information about the license this playlist is under. If this is nil, then no <license> element is emitted for the <playlist> element.


[View source]
def links : Array(Link) #

[View source]
def links=(links : Array(Link)) #

[View source]
def location : URI | Nil #

A URI of a web page that acts as the source for this playlist. If this is nil, then no <location> element is emitted for the <playlist> element.


[View source]
def location=(location : URI | Nil) #

A URI of a web page that acts as the source for this playlist. If this is nil, then no <location> element is emitted for the <playlist> element.


[View source]
def meta : Array(Meta) #

[View source]
def meta=(meta : Array(Meta)) #

[View source]
def title : String | Nil #

The human-readable name title of this playlist, if any. If this is nil, then no <title> element is emitted for the <playlist> element.


[View source]
def title=(title : String | Nil) #

The human-readable name title of this playlist, if any. If this is nil, then no <title> element is emitted for the <playlist> element.


[View source]
def tracks : Array(Track) #

[View source]
def write(dest : String | Path, *, mode : String = "w", format : Format = Format::Xml) : Nil #

Writes this Playlist instance to a file at dest in the given format. The mode parameter is the same as for File#open. There must be at least one track in this playlist, or this will raise an Error.


[View source]
def write(io : IO, *, format : Format = Format::Xml) : Nil #

Writes this Playlist instance to io in the given format. There must be at least one track in this playlist, or this will raise an Error.


[View source]
def write(*, format : Format = Format::Xml) : String #

Writes this Playlist instance to a new String in the given format. There must be at least one track in this playlist, or this will raise an Error.


[View source]