forked from xhochy/scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,51 @@ | ||
module Scrobbler | ||
# @todo everything | ||
class Playlist < Base | ||
attr_reader :url | ||
attr_reader :url, :id, :title, :date, :creator | ||
attr_reader :description, :size, :duration, :streamable | ||
class << self | ||
def new_from_libxml(xml) | ||
data = {} | ||
|
||
xml.children.each do |child| | ||
data[:id] = child.content.to_i if child.name == 'id' | ||
data[:title] = child.content if child.name == 'title' | ||
|
||
if child.name == 'image' | ||
data[:image_small] = child.content if child['size'] == 'small' | ||
data[:image_medium] = child.content if child['size'] == 'medium' | ||
data[:image_large] = child.content if child['size'] == 'large' | ||
end | ||
data[:date] = Time.parse(child.content) if child.name == 'date' | ||
|
||
data[:size] = child.content.to_i if child.name == 'size' | ||
data[:description] = child.content if child.name == 'description' | ||
data[:duration] = child.content.to_i if child.name == 'duration' | ||
|
||
if child.name == 'streamable' | ||
if ['1', 'true'].include?(child.content) | ||
data[:streamable] = true | ||
else | ||
data[:streamable] = false | ||
end | ||
end | ||
data[:creator] = child.content if child.name == 'creator' | ||
data[:url] = child.content if child.name == 'url' | ||
end | ||
Playlist.new(data[:url],data) | ||
end | ||
end | ||
|
||
def initialize(url) | ||
def initialize(url,data={}) | ||
@url = url | ||
populate_data(data) | ||
end | ||
|
||
def image(which=:small) | ||
which = which.to_s | ||
raise ArgumentError unless ['small', 'medium', 'large'].include?(which) | ||
instance_variable_get("@image_#{which}") | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<lfm status="ok"> | ||
<playlists user="RJ"> | ||
<playlist> | ||
<id>5606</id> | ||
<title>Misc gubbins</title> | ||
<description>This is a misc test playlist with a few random tracks in it.</description> | ||
<date>2006-11-15T13:05:48</date> | ||
<size>10</size> | ||
<duration>2771</duration> | ||
<streamable>0</streamable> | ||
<creator>http://www.last.fm/user/RJ</creator> | ||
<url>http://www.last.fm/user/RJ/library/playlists/4bq_misc_gubbins</url> | ||
<image size="small">http://userserve-ak.last.fm/serve/34/4218758.jpg</image> | ||
<image size="medium">http://userserve-ak.last.fm/serve/64/4218758.jpg</image> | ||
<image size="large">http://userserve-ak.last.fm/serve/126/4218758.jpg</image> | ||
</playlist> | ||
<playlist> | ||
<id>2615079</id> | ||
<title>Duck playlist</title> | ||
<description>Duck and cover</description> | ||
<date>2008-05-22T09:40:09</date> | ||
<size>10</size> | ||
<duration>2143</duration> | ||
<streamable>0</streamable> | ||
<creator>http://www.last.fm/user/RJ</creator> | ||
<url>http://www.last.fm/user/RJ/library/playlists/1k1t3_duck_playlist</url> | ||
<image size="small">http://userserve-ak.last.fm/serve/34/5985590.jpg</image> | ||
<image size="medium">http://userserve-ak.last.fm/serve/64/5985590.jpg</image> | ||
<image size="large">http://userserve-ak.last.fm/serve/126/5985590.jpg</image> | ||
</playlist> | ||
<playlist> | ||
<id>2614993</id> | ||
<title>Doglist</title> | ||
<description>Guess what i searched for..</description> | ||
<date>2008-05-22T09:24:23</date> | ||
<size>18</size> | ||
<duration>3544</duration> | ||
<streamable>0</streamable> | ||
<creator>http://www.last.fm/user/RJ</creator> | ||
<url>http://www.last.fm/user/RJ/library/playlists/1k1qp_doglist</url> | ||
<image size="small">http://userserve-ak.last.fm/serve/34/5976386.jpg</image> | ||
<image size="medium">http://userserve-ak.last.fm/serve/64/5976386.jpg</image> | ||
<image size="large">http://userserve-ak.last.fm/serve/126/5976386.jpg</image> | ||
</playlist> | ||
<playlist> | ||
<id>2612216</id> | ||
<title>Sexyplaylist</title> | ||
<description>My only regret is that the search feature doesn't give me more than 10 results</description> | ||
<date>2008-05-21T19:43:46</date> | ||
<size>9</size> | ||
<duration>2416</duration> | ||
<streamable>0</streamable> | ||
<creator>http://www.last.fm/user/RJ</creator> | ||
<url>http://www.last.fm/user/RJ/library/playlists/1jzlk_sexyplaylist</url> | ||
<image size="small">http://userserve-ak.last.fm/serve/34/5976429.jpg</image> | ||
<image size="medium">http://userserve-ak.last.fm/serve/64/5976429.jpg</image> | ||
<image size="large">http://userserve-ak.last.fm/serve/126/5976429.jpg</image> | ||
</playlist> | ||
</playlists> | ||
</lfm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters