Skip to content

Instantly share code, notes, and snippets.

@arion
Created August 20, 2012 12:46
Show Gist options
  • Save arion/3403784 to your computer and use it in GitHub Desktop.
Save arion/3403784 to your computer and use it in GitHub Desktop.
scrobble all you local files to last.fm
# -*- encoding : utf-8 -*-
require "mp3info"
require "rockstar"
require "pry"
IMPORT_DIR = '/Users/arion/Music'
Rockstar.lastfm = YAML.load_file('lastfm.yml')
a = Rockstar::Auth.new
token = a.token
puts
puts "Please open http://www.last.fm/api/auth/?api_key=#{Rockstar.lastfm_api_key}&token=#{token}"
puts
puts "Press enter when done."
gets
session = a.session(token)
not_scrobble = []
scrobled = 0
Dir[File.join(IMPORT_DIR, '**', '*.mp3')].each do |mp3_path|
begin
Mp3Info.open(mp3_path) do |mp3|
puts "title: #{mp3.tag.title}, artist: #{mp3.tag.artist}, album: #{mp3.tag.album}"
track = Rockstar::Track.new(mp3.tag.artist, mp3.tag.title)
puts "scrobble: #{track.scrobble(Time.now, session.key)}"
scrobled += 1
puts "---"
end
rescue Exception => e
puts "error: #{e.message}"
not_scrobble << mp3_path
end
end
puts "Scrobble: (#{scrobled})"
puts "Not scrobble: (#{not_scrobble.size})"
puts not_scrobble
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment