tiegz-ruby-mtv 1.2 → 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/TODO +2 -1
- data/lib/mtv.rb +1 -0
- data/lib/mtv/artist.rb +8 -8
- data/lib/mtv/video.rb +29 -50
- data/ruby-mtv.gemspec +2 -1
- data/test/unit/artist_test.rb +1 -1
- data/test/unit/video_test.rb +1 -1
- metadata +10 -1
data/TODO
CHANGED
data/lib/mtv.rb
CHANGED
data/lib/mtv/artist.rb
CHANGED
@@ -89,9 +89,9 @@ module MTV
|
|
89
89
|
protected
|
90
90
|
# Parses a response xml string for artists.
|
91
91
|
def parse_many(body) # :nodoc:
|
92
|
-
entries =
|
93
|
-
raise Error, "That artist not found!" if entries.nil?
|
92
|
+
entries = (Hpricot.XML(body)/:entry)
|
94
93
|
entries = [entries] unless entries.is_a? Array
|
94
|
+
raise Error, "That artist not found!" if entries.nil?
|
95
95
|
entries.map { |entry|
|
96
96
|
instantiate entry
|
97
97
|
}.reject { |artist| MTV::Artist.name.nil? || MTV::Artist.name.empty? }
|
@@ -99,17 +99,17 @@ module MTV
|
|
99
99
|
|
100
100
|
# Parses a response xml string for an artist.
|
101
101
|
def parse_one(body) # :nodoc:
|
102
|
-
entry =
|
103
|
-
name = entry
|
102
|
+
entry = Hpricot.XML(body)
|
103
|
+
name = (entry/'author/name').inner_html
|
104
104
|
raise Error, "That artist not found!" if name.nil? || name.empty?
|
105
105
|
instantiate entry
|
106
106
|
end
|
107
107
|
|
108
108
|
def instantiate(entry={})
|
109
|
-
Artist.new(:name => entry
|
110
|
-
:uri => entry
|
111
|
-
:links => entry
|
112
|
-
:updated => entry
|
109
|
+
Artist.new(:name => (entry/'author/name').inner_html,
|
110
|
+
:uri => (entry/'author/uri').inner_html,
|
111
|
+
:links => (entry/'link').map { |l| l.attributes['href'] },
|
112
|
+
:updated => (entry/'updated').inner_html)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
data/lib/mtv/video.rb
CHANGED
@@ -4,7 +4,7 @@ module MTV
|
|
4
4
|
attr_accessor :artist, :artist_name, :artist_uri, :category, :content, :credit,
|
5
5
|
:media_player_url, :media_thumbnails, :media_title, :media_description,
|
6
6
|
:media_keywords, :media_duration, :media_expression, :media_url, :media_type,
|
7
|
-
:media_credits, :media_category, :media_medium,
|
7
|
+
:media_credits, :media_category, :media_medium, :published, :thumbnails,
|
8
8
|
:title, :published, :uid, :updated, :uri, :vid
|
9
9
|
|
10
10
|
#-----------------
|
@@ -73,21 +73,19 @@ module MTV
|
|
73
73
|
protected
|
74
74
|
# Parses a response xml string for videos.
|
75
75
|
def parse_many(body) # :nodoc:
|
76
|
-
|
77
|
-
entries = XmlSimple.xml_in(body)['entry']
|
78
|
-
raise Error, "That video not found!" if entries.nil?
|
76
|
+
entries = (Hpricot.XML(body)/:entry)
|
79
77
|
entries = [entries] unless entries.is_a? Array
|
78
|
+
raise Error, "That video not found!" if entries.nil?
|
80
79
|
entries.reject! { |entry| entry.nil? }
|
81
80
|
entries.map { |entry|
|
82
81
|
instantiate entry
|
83
|
-
}
|
84
|
-
|
82
|
+
}.reject { |artist| MTV::Artist.name.nil? || MTV::Artist.name.empty? }
|
83
|
+
end
|
85
84
|
|
86
85
|
# Parses a response xml string for a video.
|
87
86
|
def parse_one(body) # :nodoc:
|
88
|
-
|
89
|
-
|
90
|
-
artist_name = entry['author'].first['name'].first
|
87
|
+
entry = Hpricot.XML(body)
|
88
|
+
artist_name = (entry/'author/name').inner_html
|
91
89
|
raise Error, "That video not found!" if artist_name.nil? || artist_name.empty?
|
92
90
|
instantiate entry
|
93
91
|
end
|
@@ -99,32 +97,28 @@ module MTV
|
|
99
97
|
response.strip.gsub('<?xml version="1.0" encoding="iso-8859-1"?>', '').empty? ? "" : response
|
100
98
|
end
|
101
99
|
|
102
|
-
# HACK because XmlSimple doesn't seem to handle enclosures, we'll replace colons with hyphens
|
103
|
-
# TODO write a better regexp for that hack :\
|
104
|
-
def hack_media_enclosures(body) # :nodoc:
|
105
|
-
body.gsub("<media:", "<media_").gsub("</media:", "</media_")
|
106
|
-
end
|
107
|
-
|
108
100
|
def instantiate(entry={})
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
101
|
+
# TODO I did encounter a bug with a search for 'creep' on the first result... it
|
102
|
+
# has a media:credit node that is self-closing, and it appears to break hpricot.
|
103
|
+
Video.new(:title => (entry/'title').inner_html, # entry['title'].to_s,
|
104
|
+
:artist_uri => (entry/'author/uri').inner_html, # entry['author'].first['uri'].to_s,
|
105
|
+
:artist_name => (entry/'author/name').inner_html, # entry['author'].first['name'].to_s,
|
106
|
+
:published => (entry/'published').inner_html, # entry['published'].first.to_s,
|
107
|
+
:content => (entry/'content').inner_html, # Artist Name, Video Title, and Record Label
|
108
|
+
:uri => (entry/'link').select { |link| link.attributes['rel'] == 'self' }.first.attributes['href'],
|
109
|
+
:updated => ((entry/'updated').inner_html.to_datetime rescue nil), # (entry['updated'].to_s.to_datetime rescue nil),
|
110
|
+
:media_category => (entry/'media:category').inner_html, # entry['media_category'].to_s, # governing agreement
|
111
|
+
:media_credits => (entry/'media:credit').map { |credit| "#{credit.inner_html || 'N/A'} (#{credit.attributes['role']})" }.join(', '), # entry['media_credit'],
|
112
|
+
:media_description => (entry/'media:description').inner_html, # entry['media_description'].to_s,
|
113
|
+
:media_duration => ((entry/'media:content').first.attributes['duration'] rescue nil), # entry['media_content'].first['duration'].to_s,
|
114
|
+
:media_expression => ((entry/'media:content').first.attributes['expression'] rescue nil), #entry['media_content'].first['expression'].to_s,
|
115
|
+
:media_keywords => (entry/'media:keywords').inner_html, #entry['media_keywords'].to_s,
|
116
|
+
:media_medium => ((entry/'media:content').first.attributes['medium'] rescue nil), #entry['media_content'].first['medium'].to_s,
|
117
|
+
:media_player_url => ((entry/'media:player').first.attributes['url'] rescue nil), #entry['media_player'].first['url'].to_s,
|
118
|
+
:thumbnails => (entry/'media:thumbnail').map { |t| Thumbnail.new(t.attributes['url'], t.attributes['width'], t.attributes['height']) }, #entry['media_thumbnail'],
|
119
|
+
:media_title => (entry/'media:title').inner_html, #entry['media_title'].to_s,
|
120
|
+
:media_type => ((entry/'media:content').first.attributes['type'] rescue nil), # entry['media_content'].first['type'].to_s,
|
121
|
+
:media_url => ((entry/'media:content').first.attributes['url'] rescue nil)) #entry['media_content'].first['url'].to_s)
|
128
122
|
end
|
129
123
|
end
|
130
124
|
|
@@ -144,7 +138,7 @@ module MTV
|
|
144
138
|
def initialize(values={})
|
145
139
|
super(values)
|
146
140
|
self.uid = uri.gsub(self.class.base_url + "/video", '').delete '/' unless @uid
|
147
|
-
self.vid = media_url.split(':').last
|
141
|
+
self.vid = media_url.split(':').last if media_url
|
148
142
|
end
|
149
143
|
|
150
144
|
# Returns the artist object for the video.
|
@@ -183,20 +177,5 @@ module MTV
|
|
183
177
|
attrs = [:title, :artist_uri].map { |name| "#{name}: #{attribute_for_inspect(name)}" }.compact.join(", ")
|
184
178
|
"#<#{self.class} #{attrs}>"
|
185
179
|
end
|
186
|
-
|
187
|
-
# Returns an array of thumbnails for this video.
|
188
|
-
#
|
189
|
-
# ==== Examples
|
190
|
-
#
|
191
|
-
# MTV::Video.search('mellow gold').first.thumbnails
|
192
|
-
# > [#<MTV::Thumbnail:0x184e274 @width="70", @height="53", @url="http://www.mtv.com/shared/promoimages/bands/b/beck/video_stills/loser/loser_70x53.jpg"> ... ]
|
193
|
-
def thumbnails
|
194
|
-
@thumbnails
|
195
|
-
end
|
196
|
-
|
197
|
-
# Parses the video thumbnails and sets them into an array.
|
198
|
-
def thumbnails=(val) # :nodoc:
|
199
|
-
@thumbnails = (val.is_a?(Array) ? val : [val]).map { |t| Thumbnail.new(t['url'], t['width'], t['height']) unless t.nil? }
|
200
|
-
end
|
201
180
|
end
|
202
181
|
end
|
data/ruby-mtv.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "ruby-mtv"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.3"
|
4
4
|
s.date = "2008-10-27"
|
5
5
|
s.summary = "Ruby wrapper library for MTV api"
|
6
6
|
s.email = "tieg.zaharia+github@gmail.com"
|
@@ -36,4 +36,5 @@ Gem::Specification.new do |s|
|
|
36
36
|
s.rdoc_options = ["--main", "README"]
|
37
37
|
s.extra_rdoc_files = ["README"]
|
38
38
|
s.add_dependency("active-support", ["> 2.0.2"])
|
39
|
+
s.add_dependency("hpricot", ["> 0.6"])
|
39
40
|
end
|
data/test/unit/artist_test.rb
CHANGED
data/test/unit/video_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiegz-ruby-mtv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "1.
|
4
|
+
version: "1.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tieg Zaharia
|
@@ -21,6 +21,15 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 2.0.2
|
23
23
|
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: hpricot
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0.6"
|
32
|
+
version:
|
24
33
|
description: ruby-mtv is a Ruby library for accessing Artist and Video objects through the MTVN api.
|
25
34
|
email: tieg.zaharia+github@gmail.com
|
26
35
|
executables: []
|