Merge pull request #69 from Who23/bug-fix-68

Fix #68

Can't believe I didn't see this earlier. Thanks for the great work! I'll merge it now.
This commit is contained in:
Cooper Hammond 2020-11-08 01:21:30 -07:00 committed by GitHub
commit c20f4309d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -134,9 +134,15 @@ class Song
tagger.add_album_art(temp_albumart_filename)
tagger.add_text_tag("title", data["name"].to_s)
tagger.add_text_tag("artist", @artist)
if !@album.empty?
tagger.add_text_tag("album", @album)
tagger.add_text_tag("genre",
@spotify_searcher.find_genre(data["artists"][0]["id"].to_s))
end
if genre = @spotify_searcher.find_genre(data["artists"][0]["id"].to_s)
tagger.add_text_tag("genre", genre)
end
tagger.add_text_tag("track", data["track_number"].to_s)
tagger.add_text_tag("disc", data["disc_number"].to_s)

View file

@ -204,8 +204,14 @@ class SpotifySearcher
# ```
# SpotifySearcher.new.authorize(...).find_genre("1dfeR4HaWDbWqFHLkxsg1d")
# ```
def find_genre(id : String) : String
genre = get_item("artist", id)["genres"][0].to_s
def find_genre(id : String) : String | Nil
genre = get_item("artist", id)["genres"]
if genre.as_a.empty?
return nil
end
genre = genre[0].to_s
genre = genre.split(" ").map { |x| x.capitalize }.join(" ")
return genre