Permalink
Browse files

raise NoLyricsError if data indicates missing lyrics

The song info endpoint (e.g.
/api.php?artist=Al+Green&action=lyrics&song=Let%27+Stay+Together&fmt=realjson)
response includes a field `lyrics` containing the first few lines of the
song's lyrics. If the song's lyrics are missing, the field will contain
the string "Not found". In that case, don't bother trying to fetch any
more information about the song (n.b. the URL in the response data can
be the edit page on the wiki).
  • Loading branch information...
alxndr committed May 1, 2016
1 parent 924d5fb commit a01056c21db5619e13d282d6e2b524857411b443
Showing with 9 additions and 0 deletions.
  1. +5 −0 lib/lyriki/legacy/song_data.rb
  2. +4 −0 lib/lyriki/legacy/song_lyrics.rb
@@ -10,6 +10,9 @@ class SongData
def initialize(**args)
raise ArgumentError unless args[:artist] && args[:song]
@data = get(url_for_song(args[:artist], args[:song]))
+ if response_data["lyrics"] == "Not found"
+ raise NoLyricsError, "lyrics not found: #{response_data}"
+ end
end
def response_data
@@ -25,3 +28,5 @@ def url_for_song(artist, song)
end
end
end
+
+class NoLyricsError < StandardError; end
@@ -11,6 +11,10 @@ class SongLyrics
def initialize(**args)
raise ArgumentError unless args[:artist] && args[:song]
song_data = SongData.new(args).response_data
+ if song_data["lyrics"] == "Not found"
+ raise NoLyricsError, "lyrics not found: #{song_data}"
+ end
+
@data = get(song_data["url"])
end

0 comments on commit a01056c

Please sign in to comment.