Created
August 19, 2011 02:01
-
-
Save joeyrobert/1155855 to your computer and use it in GitHub Desktop.
lastfm_mediamonkey.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32ole' | |
require 'net/http' | |
require 'rexml/document' | |
class FindSongs | |
def initialize(user, api_key) | |
@username = user | |
@api_key = api_key | |
@mediamonkey = WIN32OLE.new('SongsDB.SDBApplication') | |
end | |
def get_media_monkey_artists | |
artists = @mediamonkey.Player.CurrentSongList.Artists | |
number_of_artists = artists.Count | |
artist_list = [] | |
number_of_artists.times do |i| | |
artist_list << artists.Item(i).Name | |
end | |
artist_list | |
end | |
def get_last_fm_artists(page=1, limit=2000) | |
url = "http://ws.audioscrobbler.com/2.0/?method=library.getartists&api_key=#{@api_key}&user=#{@username}&limit=#{limit}&page=#{page}" | |
xml_data = Net::HTTP.get_response(URI.parse(url)).body | |
doc = REXML::Document.new(xml_data) | |
artist_list = [] | |
doc.elements.each('lfm/artists/artist') do |artist| | |
artist_list << artist.elements['name'].text | |
end | |
artist_list | |
end | |
end | |
fs = FindSongs.new('xaxisx', '39b60f2eda803f079929334a8e823d3d') | |
last_fm_artists = fs.get_last_fm_artists | |
media_monkey_artists = fs.get_media_monkey_artists | |
puts "Last.fm artists: #{last_fm_artists.count}" | |
puts "MediaMonkey artists: #{media_monkey_artists.count}" | |
puts "In MM but not Last.fm: #{(media_monkey_artists - last_fm_artists).count}" | |
puts "In Last.fm but not MM: #{(last_fm_artists - media_monkey_artists).count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment