This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Scripting: Rated score, hlp needed.

Tags: None
(comma "," separated)
Paven
Registered Member
Posts
7
Karma
0

Scripting: Rated score, hlp needed.

Fri Mar 02, 2007 7:11 am
Well i am not a ruby programmer and this is my first amaroK script, so i would like anyone to give me tips on what's wrong. I gues this is the right forum for this.

Basicly it is a rating script that uses rating in the scoring algorithm, so that user defined rating is valued in with prev-score and precent.

so what I need is to get the rating of the song, i don't know if i am doing right.
And i need help geting the script  started.

(I know how to pakage it as a amarok script and add it. so that is not the question)

Since it's not working, i wouldn't recomend anyone to try the script.
Would be nice to know if I Handeling the licence right, the script is based on the default.

regards

Code: Select all
#!/usr/bin/env ruby
#
# amaroK Script for rated scoring
# (c) 2007 Patrik Gustafsson <**>
# Based on
# amaroK Script for custom scoring
# (c) 2006 Gábor Lehel <**>
#
# License: GNU General Public License V2

require 'uri'
require "#{File.dirname( File.expand_path(__FILE__))}/amarok.rb" ##needed?

loop do
    args = gets.chomp.split(" ")

    case args[0]
        when "configure"
            msg  = 'This script does not require any configuration.'
            `dcop amarok playlist popupMessage "#{msg}"`

        when "requestNewScore"
            url = args[1]
            prevscore = args[2].to_f
            playcount = args[3].to_i
            length = args[4].to_i
            percentage = args[5].to_i
            reason = args[6]
       rating = `dcop amarok collection query "select rating from statistics where url = \\"#{url}\\""`.to_i
            rating = rating * rating #?amaroK uses 1-10 for ratings and 1-100 for script ?
            #rating = (`dcop amarok collection query "select rating from statistics where url = " . url`).to_i
       #rating = 0 # `dcop amarok collection query "select rating from statistics where url = "\\"#{url}\\""`.to_i

            if(rating <= 0) #set defoult value if no rating..
                rating = 15
            end
            if( playcount <= 0 ) # not supposed to be less, but what the hell.
               if (prevscore <= 0)
                   newscore = ( percentage + rating )/2
          else
                   newscore = ( prevscore + percentage + rating) / 3
               end
            else
               newscore = ( ( prevscore * playcount ) + percentage*2 + rating ) / ( playcount + 3 )
            end

            system( "dcop", "amarok", "player", "setScoreByPath", URI::decode( url ), newscore.to_s )
    end
end
User avatar
markey
KDE Developer
Posts
2286
Karma
3
OS
How exactly is it not working? Do you get an error message?


--
Mark Kretschmann - Amarok Developer
Paven
Registered Member
Posts
7
Karma
0
Mark Kretschmann wrote:How exactly is it not working? Do you get an error message?


I started out modefing the defoult, and before made changes to the changes to the code, i made changes in the name etc and that worked.
But when i changed the code. The script gav an 255 error message and was then removed from the script manager.
When i make, a amarokscource.tar of it and add it via script manager, i now get an error message saying it the script isn't runeble.

Code: Select all
rating = `dcop amarok collection query "select rating from statistics where url = \"#{url}\""`.to_i

this line was borrowed slightly modifed from the rate it script, ifigured that i could us the url arg instead of current_url that was created by that script. but i am not sure if i did this line right

thanx
P
User avatar
markey
KDE Developer
Posts
2286
Karma
3
OS
chmod +x your script file.


--
Mark Kretschmann - Amarok Developer
Paven
Registered Member
Posts
7
Karma
0
It's always the most obvious solutions one can not see.
Thanx , it helped.

But the
Code: Select all
rating = `dcop amarok collection query "select rating from statistics where url = \\"#{url}\\""`.to_i

only returns 0, anyone now how to get the rating? or whats wrong with this line.
:/
Paven
Registered Member
Posts
7
Karma
0
Code: Select all
...edit...


Did a work around, storing the rating from player one song ahead. This is not a fully satisfying soultion since this script will use the old rating if rating is changed during play.

-edit-
now the first public version is distrubuted.
http://kde-apps.org/content/show.php?content=54051
Thanx for the help.
P

Last edited by Paven on Sun Mar 04, 2007 6:20 pm, edited 1 time in total.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], lockheed, Sogou [Bot]