class RemiAudio::Xspf::Playlist
- RemiAudio::Xspf::Playlist
- Reference
- Object
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
- JSON::Serializable
Defined in:
remiaudio/xspf/xspf.crConstant Summary
-
VERSION =
1 -
The version of the specification that we support. Note that version 1 is backwards compatible with version 0.
Constructors
- .new(pull : JSON::PullParser)
-
.new
Creates a new
Playlistinstance. -
.read(io : IO, *, format : Format = Format::Xml) : Playlist
Creates a new
Playlistinstance by reading data fromio. -
.read(str : String, *, format : Format = Format::Xml) : Playlist
Creates a new
Playlistinstance by reading data fromstr.
Instance Method Summary
-
#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.
-
#annotate : String | Nil
A human-readable comment for this playlist, if any.
-
#annotate=(annotate : String | Nil)
A human-readable comment for this playlist, if any.
-
#attribution : Attribution | Nil
An
Attributioninstance that contains additional information that can be used to satisfy attribution requirements for licenses. -
#attribution=(attribution : Attribution | Nil)
An
Attributioninstance that contains additional information that can be used to satisfy attribution requirements for licenses. -
#creator : String | Nil
The human-readable name of the creator of this playlist, if any.
-
#creator=(creator : String | Nil)
The human-readable name of the creator of this playlist, if any.
-
#date : Time | Nil
The date this playlist was created (NOT the last-modified date).
-
#date=(date : Time | Nil)
The date this playlist was created (NOT the last-modified date).
-
#each(& : Track -> ) : Nil
Loops through all of the tracks in this playlist, yielding a
Trackinstance for each one. -
#identifier : URI | Nil
A URI describing the canonical identifier of this playlist.
-
#identifier=(identifier : URI | Nil)
A URI describing the canonical identifier of this playlist.
-
#image : URI | Nil
A URI pointing to an image that can be displayed when a track has no artwork of its own.
-
#image=(image : URI | Nil)
A URI pointing to an image that can be displayed when a track has no artwork of its own.
-
#info : URI | Nil
A URI of a web page that provides more information about this playlist.
-
#info=(info : URI | Nil)
A URI of a web page that provides more information about this playlist.
-
#license : URI | Nil
A URI to a resource that provides information about the license this playlist is under.
-
#license=(license : URI | Nil)
A URI to a resource that provides information about the license this playlist is under.
-
#links : Array(Link)
An array of
Linkinstances that allow a playlist to be extended without extra XML namespaces. -
#links=(links : Array(Link))
An array of
Linkinstances that allow a playlist to be extended without extra XML namespaces. -
#location : URI | Nil
A URI of a web page that acts as the source for this playlist.
-
#location=(location : URI | Nil)
A URI of a web page that acts as the source for this playlist.
-
#meta : Array(Meta)
An array of
Metainstances that specify metadata for a playlist. -
#meta=(meta : Array(Meta))
An array of
Metainstances that specify metadata for a playlist. -
#title : String | Nil
The human-readable name title of this playlist, if any.
-
#title=(title : String | Nil)
The human-readable name title of this playlist, if any.
-
#tracks : Array(Track)
A list of
Trackinstances stored in this playlist. -
#write(dest : String | Path, *, mode : String = "w", format : Format = Format::Xml) : Nil
Writes this
Playlistinstance to a file atdestin the givenformat. -
#write(io : IO, *, format : Format = Format::Xml) : Nil
Writes this
Playlistinstance toioin the givenformat. -
#write(*, format : Format = Format::Xml) : String
Writes this
Playlistinstance to a new String in the givenformat.
Constructor Detail
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.
Creates a new Playlist instance by reading data from io.
Creates a new Playlist instance by reading data from str.
Instance Method Detail
Adds a new track to this playlist.
A human-readable comment for this playlist, if any. If this is nil, then
no <annotation> element is emitted for the <playlist> element. This
should never contain markup.
A human-readable comment for this playlist, if any. If this is nil, then
no <annotation> element is emitted for the <playlist> element. This
should never contain markup.
An Attribution instance that contains additional information that can be
used to satisfy attribution requirements for licenses. If this is nil,
then no <attribution> element is emitted for the <playlist> element.
An Attribution instance that contains additional information that can be
used to satisfy attribution requirements for licenses. If this is nil,
then no <attribution> element is emitted for the <playlist> element.
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.
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.
The date this playlist was created (NOT the last-modified date). If this
is nil, then no <attribution> element is emitted for the <playlist>
element.
The date this playlist was created (NOT the last-modified date). If this
is nil, then no <attribution> element is emitted for the <playlist>
element.
Loops through all of the tracks in this playlist, yielding a Track
instance for each one.
A URI describing the canonical identifier of this playlist. If this is
nil, then no <identifier> element is emitted for the <playlist>
element.
A URI describing the canonical identifier of this playlist. If this is
nil, then no <identifier> element is emitted for the <playlist>
element.
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.
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.
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.
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.
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.
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.
An array of Link instances that allow a playlist to be extended without
extra XML namespaces. If this is empty, then no <link> element is
emitted for the <playlist> element.
An array of Link instances that allow a playlist to be extended without
extra XML namespaces. If this is empty, then no <link> element is
emitted for the <playlist> element.
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.
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.
An array of Meta instances that specify metadata for a playlist. If
this is empty, then no <meta> element is emitted for the <playlist>
element.
An array of Meta instances that specify metadata for a playlist. If
this is empty, then no <meta> element is emitted for the <playlist>
element.
The human-readable name title of this playlist, if any. If this is nil,
then no <title> element is emitted for the <playlist> element.
The human-readable name title of this playlist, if any. If this is nil,
then no <title> element is emitted for the <playlist> element.
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.
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.