logger

Amarok 1.x Scripts

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net

0
Score 50.0%
Description:

(For the Amarok 2 port of logger, see http://kde-apps.org/content/show.php?content=107836 )

logger is an Amarok script that logs all songs listened. The reason why I had to write it as a score script is that I wanted the information how long the song was listened. The script imitates the behaviour of the default score script. Additionally, each song (genre, artist, album, title) listened for more than 50 % is stored in an SQLite database (per month). So, nice statistics can be produced.

The database is located in ~/.kde/share/apps/amarok/scripts-data/logger.db.

The playstat script is an example statistics script. It can be run from a console (and will print some status messages to STDERR there) or from Amarok's script interface. It has an INI-Style configuration file at ~/.kde/share/apps/amarok/scripts-data/playstat.cfg (that will be created with the default configuration on the first run) that tells it which statistics should be made and will write the HTML output to ~/.kde/share/apps/amarok/scripts-data/playstat.htm by default. Feel free to experiment with it :-)

Version 0.3.3 introduces a few new configuration options for the playstat script. The best would perhaps be to remove your config file and let the playstat script generate a new default one.
Last changelog:

10 years ago

2009-09-16 (Version 0.3.6)
Bugfix release. Fixed an UTF-8 problem with Python >=2.5 and made logger work again.

2009-03-08 (Version 0.3.5)
Bugfix release. Fixed a query problem when there are songs with the same name from different artists and made logger (hopefully) work if Amarok 1.* is started in KDE 4.

(See ChangeLog for the rest ;-)

2008-05-28 (Version 0.1):
Initial release

tzd

11 years ago

Tried it out and man that's a nice feature :)
I have one question/suggestion:
Instead of having the web site that's being generated stored in scripts-data, would it be possible to store it in directly under the home folder? E.g. /home/username/playstat.htm

That way i don't have to browse around that much to find the actual web site.

Also, for the generated script, I recently came upon a web site that seems to have covers for 99.5% of all album releases. Since the scripts original web site only knows about 65% of my different albums it would be nice to use this site (www.discogs.com) instead for cover fetching.
Actually, the script would be amazing if it could use several sources for cover fetching :)

I don't know how difficult these suggestions are to implement and I also know you've left the script open for everyone else to develop. I was just suggesting above in case you're bored and wishes to improve it :P I'll have a look on it as well, but to be honest, I'm not much of a programmer. Hopefully I'll learn something and could improve some myself. :)

Report

tzd

11 years ago

UPDATE: just had a look on the playstat script and I managed to change the html output directory very easily! Thanks for making it that easy :)

Report

tzd

11 years ago

When changing titles and other default text messages in the loggerStatistics file it works as long as I don't use Swedish characters. May I ask how to get this working please?

It works as long as I avoid the characters: 'å' 'ä' 'ö'

Cheers again :)

Report

C

l3u

11 years ago

You can't use non-ASCII characters in the Python source code by default. An easy way to do that is to write the characters as escaped Unicode characters.

E. g. u"\xe4" instead of "ä".

You can find out these character sequences by starting python in a console and doing the following:

from locale import getpreferredencoding
localEncoding = getpreferredencoding()

Then, you can do something like

"ÄÖÜäöü".decode(localEncoding)

and Python will print out the escaped Unicode string, e. g.:

u'\xc4\xd6\xdc\xe4\xf6\xfc'

Report

tzd

11 years ago

I've tried it but it wouldn't work.

I've tried pasting this in Konsole:
from locale import getpreferredencoding
localEncoding = getpreferredencoding()

but all i get is:
from: can't read /var/mail/locale

i suppose i could reuse the code from your previous post although I'm still missing the letter: 'Å', 'å' :)

Report

C

l3u

11 years ago

You have to start the Python debugging console first by entering "python" in the shell. Bash does not know anything about Python commands and can'tr import any Python modules ;-)

The missing characters should be u"\xc5" for "Å" and u"\xe5" for "å".

(The "u" before the string indicated that the following string is Unicode-encoded, just to have said this :-)

Perhaps, we should do a i18n via gettext? Would be pretty cool, wouldn't it?! But perhaps, one should first make the statistisc script rock and be configurable by some GUI or at least an easy-to-understand configuration file ...

Report

tzd

11 years ago

Ah that would explain why the commands wouldn't work :)

Thanks for your unicode translation! Will try to modify it now to fit my needs. I'll try to assist in any way possible to ease up the GUI for the web interface even though I'm not a programmer.
Hopefully there's something i can help with ;)

Report

tzd

11 years ago

Yeah, i think that thing works now since i don't get that error message anymore! :)

Instead i receive a new error message after the song has finished:


The script 'logger' ended with error code 1.

Traceback (most recent call last):
File "/home/johan/.kde/share/apps/amarok/scripts/logger/logger", line 174, in <module>
db.execute('INSERT INTO log(date, genre, artist, album, title, count) VALUES(?, ?, ?, ?, ?, ?)', (date, songInfo['genre'], songInfo['artist'], songInfo['album'], songInfo['title'], 1))
sqlite3.OperationalError: no such table: log

Report

C

l3u

11 years ago

Try to delete ~/.kde/share/apps/amarok/scripts-data/logger.db -- it seems that the database does not contain the table it should contain. The database will be re-created after a new start.

Report

tzd

11 years ago

Yaay! That sure did the trick :) It logs to the db file now and no error messages... sweet!

Had a quick look on the playstat script which was a lot more editable than I originally thought.
I don't quite understand how I produce the web site or where it will be located?

When I try running the "playstat" script within Amarok nothing happens.

Haven't found any info regarding this so was hoping you could point me in any direction please ;)

Thanks for the amazingly fast replies and, not to forget, the patches!
Highly appreciated!

Report

C

l3u

11 years ago

Thanks for the bug report ;-)

I added this to the readme file (and to the description above): "The current progress is written to stderr and the HTML is written to stdout, so do e. g. ./playstat > stat.htm on a console to have the HTML written to stat.htm"

The playstat script was only thought to be an example how the database could be queried to produce some statistics. Perhaps, one could modify it in a way that it can be configured and run from Amarok. I'll see ... :-)

Report

tzd

11 years ago

Thanks, got it to work now. If i dare, i might try to modify the script to fit my html needs :)

I wanted to file another bug report though. Noticed this today actually. When playing a few classical music mp3s i get an error message from logger saying it's unable to process the mp3.
I do believe this has to do with the name of my classical mp3 files.

For instance, a typical name for one of the songs would be:

Kirov Orchestra, Valery Gergiev - Act I, Tableau 1, Clara and the Nutcracker.mp3

I don't know if logger using the album info too. IF it does then for the above example it would also be:
Tchaikovsky: The Nutcracker, Op. 71

Basically all my classical tunes are very long when it comes to name.
Other mp3s with "smaller" names seems to work well.

Report

tzd

11 years ago

Thanks, got it to work now. If i dare, i might try to modify the script to fit my html needs :)

I wanted to file another bug report though. Noticed this today actually. When playing a few classical music mp3s i get an error message from logger saying it's unable to process the mp3.
I do believe this has to do with the name of my classical mp3 files.

For instance, a typical name for one of the songs would be:

Kirov Orchestra, Valery Gergiev - Act I, Tableau 1, Clara and the Nutcracker.mp3

I don't know if logger using the album info too. IF it does then for the above example it would also be:
Tchaikovsky: The Nutcracker, Op. 71

Basically all my classical tunes are very long when it comes to name.
Other mp3s with "smaller" names seems to work well.

Report

C

l3u

11 years ago

P.S.

you can also search the database by simply doing (for example):

sqlite3 ~/.kde/share/apps/amarok/collection.db "SELECT url FROM tags WHERE url LIKE '%Tchaikovsky%'"

from a console.

Report

tzd

11 years ago

You are absolutely right my friend!
When playing the same songs again it works (before it wasn't in the collection).

Now when I have added and updated the collection everything is back to normal with perfect logging etc.

Sorry about the double post, updated the web page and it was posted twice unfortunately.

Will try the latest version with the improved script later on tonight or tomorrow.
Thanks once again for your support!

Report

C

l3u

11 years ago

Hi!

Artist, album, title and genre are logged by logger. I don't think that the length of the filename causes this error. Are you sure that the files are in the collection database? If so, it would be very interesting if the URL stored in the database differs from the actual url. If you know SQL a bit, you could search directly inside the database doing "sqlite3 ~/.kde/share/apps/amarok/collection.db", querying the table "tags". The data is not fetched from the mp3 (or whatever) files theirselves, but from Amarok's database. So the songs have to be indexed by Amarok.

Try modifying the playstat.py script from version 0.2 -- that should be way easier than modifying the previous versions :-)

Report

tzd

11 years ago

Cool, thanks :)

Report

C

l3u

11 years ago

Try version 0.1.4, it _really_ should work now ;-)

Report

tzd

11 years ago

Can't get it to work. Installed it and started "logger" in Amarok. The database file is created in the stated directory although nothing is being written to it.

I've changed permissions just in case to a=wrx but that didn't help.

The error I receive in Amarok after playing the song is this:

logger: Error processing file /media/mp3/Singles/Pop/Katie Melua - Crawling up a Hill.mp3

Would love to have it up and running since the whole idea with html outputs is great imho. Thanks so far! :)

Report

tzd

11 years ago

Just noticed the database dor this script is Sqllite. I'm not sure if my problem above is related to the fact that I'm running a regular Mysql database for Amarok?

Should also mention a few more details:
I'm on kubuntu Hardy (8.04) with kde 3.5.9 and Amarok 1.4.9.1

Report

C

l3u

11 years ago

Should be fixed with version 0.1.3 :-)

Report

tzd

11 years ago

Tried the new version but received the same error I'm afraid.

Also tried the command you told me to run and received the following output:

johan@Pingu:~$ dcop amarok collection query 'select url from tags limit 10'
./Singles/Alternative Electronic/St. Germain - La Goutte D'Or.mp3
./Singles/Alternative Electronic/St. Germain - Land Of.mp3
./Singles/Alternative Electronic/St. Germain - Montego Bay Spleen.mp3
./Singles/Alternative Electronic/St. Germain - Pont Des Arts.mp3
./Singles/Alternative Electronic/St. Germain - Rose Rouge.mp3
./Singles/Alternative Electronic/St. Germain - So Flute.mp3
./Singles/Alternative Electronic/St. Germain - Sure Thing.mp3
./Singles/Alternative Rock/Bad Cash Quartet - Big day coming.mp3
./Singles/Alternative Rock/Bad Cash Quartet - Competition ain't nothing.mp3
./Singles/Alternative Rock/Bad Cash Quartet - Heart attack.mp3
johan@Pingu:~$


Hope that might help? Thanks for your fast reply! :)

Report

C

l3u

11 years ago

Okay ... here, it worked, I included some directory from /var and it worked after the fix ... so, where are your songs stored? Is the absolute path "/Singles/Alternative Electronic/..." or where is that directory? Do you know a little coding Python? I would really love to fix this issue ... but I can't reproduce it at the moment!

Report

tzd

11 years ago

I've got my Amarok collection on a separate partition that's mounted on /media/singles/X/Y

where X is a directory for genre, e.g. Rock and where Y is the actual song.

For instance, the full path to the song New years day by rockartist U2 would be:

/media/singles/rock/u2 - new years day.mp3

I'm afraid i don't know any python coding. If it would be possible to change it to the absolute path then perhaps it would work? Seems a little strange with the "." before /singles/..

Tell me what to do and I'll do it :)

Report

C

l3u

11 years ago

I'm just trying to find out in which way one can get the database's url parameter out of the url parameter passed to the scripts in a convient way. Seems like the first directory, if it's /home or seomething else ... is replaced by a "./". On the other hand, it worked for me to just add a "." before a song located in /var here ... and /var was present in the database. Confusing. I posted a topic on the Amarok forums ( http://amarok.kde.org/forum/index.php/topic,15543.0.html ). Perhaps, somebody there knows the underlying mechanism. I'll let you know it ;-)

Report

10 years ago

2009-09-16 (Version 0.3.6)
Bugfix release. Fixed an UTF-8 problem with Python >=2.5 and made logger work again.

2009-03-08 (Version 0.3.5)
Bugfix release. Fixed a query problem when there are songs with the same name from different artists and made logger (hopefully) work if Amarok 1.* is started in KDE 4.

(See ChangeLog for the rest ;-)

2008-05-28 (Version 0.1):
Initial release

12345678910
product-maker Base: 4 x 5.0 Ratings
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs ocs-url or ocs-store to install things
Pling
0 Affiliates
Details
license
version
0.3.6
updated Sep 16 2009
added May 28 2008
downloads 24h
0
pageviews 24h 2
System Tags addon