Class: AutoTune::Obtainer
- Inherits:
-
Object
- Object
- AutoTune::Obtainer
- Defined in:
- lib/autotune/obtainer.rb
Class Method Summary collapse
- .get_album_artist(album_details) ⇒ Object
- .get_album_details(album, artist, clean, deluxe) ⇒ Object
- .get_artwork(album_details) ⇒ Object
- .get_copyright(album_details) ⇒ Object
- .get_genre_id(album_details) ⇒ Object
- .get_tags(album, artist, clean, deluxe) ⇒ Object
- .get_track_number(song) ⇒ Object
Class Method Details
.get_album_artist(album_details) ⇒ Object
53 54 55 |
# File 'lib/autotune/obtainer.rb', line 53 def self.get_album_artist(album_details) return album_details.dig('results', 0, 'artistName').to_s end |
.get_album_details(album, artist, clean, deluxe) ⇒ Object
13 14 15 16 17 |
# File 'lib/autotune/obtainer.rb', line 13 def self.get_album_details(album, artist, clean, deluxe) album_id = get_album_id(album, artist, clean, deluxe) lookup = "https://itunes.apple.com/lookup?id=#{album_id}" return JSON.parse(Net::HTTP.get(URI.parse(lookup))) end |
.get_artwork(album_details) ⇒ Object
19 20 21 22 23 |
# File 'lib/autotune/obtainer.rb', line 19 def self.get_artwork(album_details) artwork_url = album_details.dig('results', 0, 'artworkUrl100') artwork_url = artwork_url.gsub!(/100x100bb.jpg/, '1000000000x1000000000bb.jpg') File.write('/var/tmp/artwork.jpg', Net::HTTP.get(URI.parse(URI.encode(artwork_url.to_s)))) end |
.get_copyright(album_details) ⇒ Object
49 50 51 |
# File 'lib/autotune/obtainer.rb', line 49 def self.get_copyright(album_details) return album_details.dig('results', 0, 'copyright').to_s end |
.get_genre_id(album_details) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/autotune/obtainer.rb', line 31 def self.get_genre_id(album_details) genre_name = album_details.dig('results', 0, 'primaryGenreName') genre_appendix_lookup = 'http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/genres' unless genre_name.nil? genre_appendix = JSON.parse(Net::HTTP.get(URI.parse(genre_appendix_lookup))) genre_appendix['34']['subgenres'].each { |genres| genres.each { |genre| unless genre.nil? if genre['name'].to_s.include? genre_name return genre['id'].to_i end end } } end end |
.get_tags(album, artist, clean, deluxe) ⇒ Object
7 8 9 10 11 |
# File 'lib/autotune/obtainer.rb', line 7 def self.(album, artist, clean, deluxe) album_id = get_album_id(album, artist, clean, deluxe) lookup = "https://itunes.apple.com/lookup?id=#{album_id}&entity=song" return JSON.parse(Net::HTTP.get(URI.parse(lookup))) end |
.get_track_number(song) ⇒ Object
25 26 27 28 29 |
# File 'lib/autotune/obtainer.rb', line 25 def self.get_track_number(song) TagLib::FileRef.open(song) do |tune| return tune.tag.track unless tune.nil? end end |