#!/usr/bin/env ruby## Score2Rating 1.5 (for Amarok 1.4.1)# -----------------------------------## First of all:# PLEASE MAKE A BACKUP OF YOUR DATABASE BEFORE RUNNING THIS SCRIPT!# It might do bad things, although it shouldn't.## This script will convert the scores of your (played) tracks to ratings,# mostly to give you somewhat of a starting point for the new rating system.# It will ignore tracks that already has ratings.#if !system( "dcop amarok playlist popupMessage \"Score2Rating started. Click the 'Configure' button in the script manager (with Score2Rating selected) to start the conversion. IT IS RECOMMENDED THAT YOU MAKE A BACKUP OF YOUR DATABASE BEFORE DOING THIS!\" > /dev/null 2>&1" ) then #Info message, and running check combined print "ERROR: A suitable Amarok wasn't found running!\n" exit(1) #Exit with errorendloop do message = gets().chomp() command = /[A-Za-z]*/.match( message ).to_s() case command when "configure" result = `dcop amarok collection query "SELECT url FROM statistics WHERE playcounter>0"` #List that have been played at least once list = result.split( "\n" ) success = true #Assume the procedure is successful list.each do |url| sqlurl = url.gsub( /[']/, '\\\\\'' ) #\Escape single 'quotes' percentage = Float( `dcop amarok collection query "SELECT percentage FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) case percentage #The intervals are wrapped so that no scores will be left out. when 0...10 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 1 then rating = 1 end when 10...20 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 2 then rating = 2 #Awful end when 20...30 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 3 then rating = 3 #Barely Tolerable end when 30...40 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 4 then rating = 4 #Tolerable end when 40...50 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 5 then rating = 5 #Okay end when 50...60 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 6 then rating = 6 #Good end when 60...70 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 7 then rating = 7 #Very good end when 70...80 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 8 then rating = 8 #Excellent end when 80...90 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 9 then rating = 9 #Amazing end when 90...100 rating = Float( `dcop amarok collection query "SELECT rating FROM statistics WHERE url='#{sqlurl}'"`.gsub( /\n/, '' ) ) if rating < 10 then rating = 10 #Favourite end end if !system( "dcop amarok collection query \"UPDATE statistics SET rating='#{rating}' WHERE url='#{sqlurl}'\" > /dev/null 2>&1" ) then #If the command fails: success = false #The procedure wasn't successful end end if success == true then #If the procedure was sucessful system( "dcop amarok playlist popupMessage \"Done! All your tracks (that have been played at least once) should now have ratings. You will have to restart Amarok to see them.\" > /dev/null" ) exit(0) #Exit without error else system( "dcop amarok playlist popupMessage \"Score2Rating has finished its conversion, but the process failed for at least one track. You might want to try running it again.\" > /dev/null" ) exit(1) #Exit with error end endend