Created
January 23, 2009 00:49
-
-
Save rrooding/50820 to your computer and use it in GitHub Desktop.
Use this script as a cronjob to generate output from mt-daapd for the lastfmsubmit daemon
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
#!/usr/local/bin/ruby | |
require 'rubygems' | |
require 'sqlite3' | |
require 'yaml' | |
puts "lastfmq.rb 0.1" | |
dbfile="/var/db/mt-daapd/songs3.db" | |
lastfilename="/var/db/mt-daapd/lastfmq.date" | |
# Fetch the last run time | |
if File.exists?(lastfilename) | |
lastfile = File.open(lastfilename, "r") | |
lastruntime = lastfile.readline.chop | |
lastfile.close | |
File.delete(lastfilename) | |
else | |
lastruntime = 0 | |
end | |
puts "Last run: #{lastruntime}" | |
db = SQLite3::Database.new(dbfile) | |
rows = db.execute("select artist,album,title,track,song_length,time_played from songs where time_played > '#{lastruntime}' order by time_played asc") | |
rows.each do |row| | |
realtime = Time.at(row[5].to_i - 3600) | |
timestamp = realtime.strftime("%Y-%m-%d %T") | |
system("/usr/local/bin/lastfmsubmit --artist \"#{row[0]}\" --album \"#{row[1]}\" --title \"#{row[2]}\" --length #{row[4].to_i/1000}") | |
end | |
# Update last runtime | |
newruntime = Time.now.to_i | |
lastfile = File.new(lastfilename, "w") | |
lastfile.puts(newruntime) | |
lastfile.close | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment