Class: Gracenote
- Inherits:
-
Object
- Object
- Gracenote
- Defined in:
- lib/gracenote.rb
Constant Summary collapse
- @@ALL_RESULTS =
class variables
'1'
- @@BEST_MATCH_ONLY =
'0'
Instance Method Summary collapse
-
#albumToc(toc) ⇒ Object
Function: albumToc Fetches album metadata based on a table of contents.
-
#fetchContributor(gn_id) ⇒ Object
Function: fetchContributor Fetches details of a contributor from gn_id Arguments: gn_id.
-
#fetchOETData(gn_id) ⇒ Object
Function: fetchOETData Gets data based on gn_id Arguments: gn_id.
-
#fetchSeason(gn_id) ⇒ Object
Function: fetchSeason Fetches details of a season from gn_id Arguments: gn_id.
-
#fetchTVShow(gn_id) ⇒ Object
Function: fetchTVShow Fetches details of TV Show from gn_id Arguments: gn_id.
-
#findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findAlbum finds an Album Arguments: artistName albumTitle trackTitle matchMode.
-
#findArtist(artistName, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findArtist Finds a Artist Arguments: artistName matchMode.
-
#findContributor(name) ⇒ Object
Function: findContributor Find details of a contributor from name Arguments: name.
-
#findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findTrack Finds a track Arguments: artistName albumTitle trackTitle matchMode.
-
#findTVShow(name, single = true) ⇒ Object
Function: findTVShow Finds TVShows which matches the name Arguments: name single.
-
#initialize(spec) ⇒ Gracenote
constructor
Function: initialize Sets the following instance variables clientID clientTag userID apiURL.
-
#registerUser(clientID = nil) ⇒ Object
Function: registerUser Registers a user and returns userID.
Constructor Details
#initialize(spec) ⇒ Gracenote
Function: initialize Sets the following instance variables
clientID
clientTag
userID
apiURL
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gracenote.rb', line 16 def initialize (spec) if(spec[:clientID].nil? || spec[:clientID] == "") raise "clientID cannot be nil" end if(spec[:clientTag].nil? || spec[:clientTag] == "") raise "clientTag cannot be nil" end @clientID = spec[:clientID] @clientTag = spec[:clientTag] @userID = spec[:userID].nil? ? nil : spec[:userID] @apiURL = "https://c" + @clientID + ".web.cddbp.net/webapi/xml/1.0/" end |
Instance Method Details
#albumToc(toc) ⇒ Object
Function: albumToc Fetches album metadata based on a table of contents. Arguments:
toc
98 99 100 101 102 103 104 105 |
# File 'lib/gracenote.rb', line 98 def albumToc(toc) if @userID == nil registerUser end body = "<TOC><OFFSETS>" + toc + "</OFFSETS></TOC>" data = constructAlbumQueryBody(body, "ALBUM_TOC") return parseAlbumRES(data) end |
#fetchContributor(gn_id) ⇒ Object
Function: fetchContributor Fetches details of a contributor from gn_id Arguments:
gn_id
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/gracenote.rb', line 207 def fetchContributor (gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE,MEDIAGRAPHY_IMAGES</VALUE> </OPTION>" data = constructQueryReq(body, "CONTRIBUTOR_FETCH") resp = api(data) return checkRES(resp) end |
#fetchOETData(gn_id) ⇒ Object
Function: fetchOETData Gets data based on gn_id Arguments:
gn_id
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/gracenote.rb', line 111 def fetchOETData(gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>ARTIST_OET</VALUE> </OPTION> <OPTION> <PARAMETER>SELECT_DETAIL</PARAMETER> <VALUE>ARTIST_ORIGIN:4LEVEL,ARTIST_ERA:2LEVEL,ARTIST_TYPE:2LEVEL</VALUE> </OPTION>" data = constructQueryReq(body, "ALBUM_FETCH") resp = api(data) resp = checkRES resp json = resp["RESPONSES"] output = Array.new() output[:artist_origin] = json["RESPONSE"]["ALBUM"]["ARTIST_ORIGIN"].nil? ? "" : _getOETElem(json["RESPONSE"]["ALBUM"]["ARTIST_ORIGIN"]) output[:artist_era] = json["RESPONSE"]["ALBUM"]["ARTIST_ERA"].nil? ? "" : _getOETElem(json["RESPONSE"]["ALBUM"]["ARTIST_ERA"]) output[:artist_type] = json["RESPONSE"]["ALBUM"]["ARTIST_TYPE"].nil? ? "" : _getOETElem(json["RESPONSE"]["ALBUM"]["ARTIST_TYPE"]) return output end |
#fetchSeason(gn_id) ⇒ Object
Function: fetchSeason Fetches details of a season from gn_id Arguments:
gn_id
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gracenote.rb', line 145 def fetchSeason (gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID>" data = constructQueryReq(body, "SEASON_FETCH") resp = api(data) return checkRES(resp) end |
#fetchTVShow(gn_id) ⇒ Object
Function: fetchTVShow Fetches details of TV Show from gn_id Arguments:
gn_id
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/gracenote.rb', line 161 def fetchTVShow (gn_id) if @userID == nil registerUser end body = "<GN_ID>" + gn_id + "</GN_ID> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE</VALUE> </OPTION>" data = constructQueryReq(body, "SERIES_FETCH") resp = api(data) return checkRES(resp) end |
#findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findAlbum finds an Album Arguments:
artistName
albumTitle
trackTitle
matchMode
90 91 92 |
# File 'lib/gracenote.rb', line 90 def findAlbum(artistName, albumTitle, matchMode = @@ALL_RESULTS) return findTrack(artistName, albumTitle, "", matchMode) end |
#findArtist(artistName, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findArtist Finds a Artist Arguments:
artistName
matchMode
79 80 81 |
# File 'lib/gracenote.rb', line 79 def findArtist(artistName, matchMode = @@ALL_RESULTS) return findTrack(artistName, "", "", matchMode) end |
#findContributor(name) ⇒ Object
Function: findContributor Find details of a contributor from name Arguments:
name
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/gracenote.rb', line 228 def findContributor (name) if @userID == nil registerUser end body = "<TEXT TYPE='NAME'>" + name + "</TEXT> <MODE>SINGLE_BEST</MODE> <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE,MEDIAGRAPHY_IMAGES</VALUE> </OPTION>" data = constructQueryReq(body, "CONTRIBUTOR_SEARCH") resp = api(data) return checkRES(resp) end |
#findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) ⇒ Object
Function: findTrack Finds a track Arguments:
artistName
albumTitle
trackTitle
matchMode
65 66 67 68 69 70 71 72 |
# File 'lib/gracenote.rb', line 65 def findTrack(artistName, albumTitle, trackTitle, matchMode = @@ALL_RESULTS) if @userID == nil registerUser end body = constructAlbumQueryBody(artistName, albumTitle, trackTitle, "", "ALBUM_SEARCH", matchMode) data = api(constructQueryReq(body)) return parseAlbumRES(data); end |
#findTVShow(name, single = true) ⇒ Object
Function: findTVShow Finds TVShows which matches the name Arguments:
name
single
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/gracenote.rb', line 183 def findTVShow (name, single=true) if @userID == nil registerUser end singleText = single ? '<MODE>SINGLE_BEST</MODE>' : '' body = "<TEXT TYPE='TITLE'>" + name + "</TEXT> " + singleText + " <OPTION> <PARAMETER>SELECT_EXTENDED</PARAMETER> <VALUE>IMAGE</VALUE> </OPTION>" data = constructQueryReq(body, "SERIES_SEARCH") resp = api(data) return checkRES(resp) end |
#registerUser(clientID = nil) ⇒ Object
Function: registerUser Registers a user and returns userID
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gracenote.rb', line 35 def registerUser (clientID = nil) if(clientID.nil?) clientID = @clientID + "-" + @clientTag end if not @userID.nil? p "user already registered. No need to register again" return @userID end #send req to server and get user ID data = "<QUERIES> <QUERY CMD='REGISTER'> <CLIENT>"+ clientID +"</CLIENT> </QUERY> </QUERIES>" resp = api(data) resp = checkRES resp @userID = resp['RESPONSES']['RESPONSE']['USER'] return @userID end |