Amarok/Archives/Amarok 1.4/User Guide/Submit your amaroK database to musicmobs

From KDE Community Wiki

Description

Similar to Audioscrobbler but with a different focus, there is the site musicmobs.com, which has at the moment only plugins for a few players available. With the following script you can upload your Amarok database to musicmobs. You will need a musicmobs account to do so.

Update

The Musicmobs XML-RPC API is depricated. The new, supported API is the REST interface seen here:

[mobdev.pbwiki.com Musicmobs REST API]

This API also supports playlist syncing.

Prerequisites

For this script you need a recent version of Python, the SQLite libraries / command client (Version 3.2) and the APSW module for Python installed.

The script

Save this file as amarok2musicmobs.py

1#!/usr/bin/python
# amaroK to musicmobs scripts
# (C) 2005 by Titus Stahl <[email protected]>
# Licensed under the GPL Version 2 and above
import apsw,sys 
import xmlrpclib
 
def submit(file, username, password):
	artists = {}
	albums = {}
	genres = {}
	
	#Fetch artists
	connection=apsw.Connection(file)
	cursor=connection.cursor()

	for aid,aname in cursor.execute("select id, name from artist"):
		artists[aid] = aname
	for aid,aname in cursor.execute("select id, name from album"):
    		albums[aid] = aname
	for aid,aname in cursor.execute("select id, name from genre"):
    		genres[aid] = aname

	s = ""
	for title, album, artist, genre, score, counter in cursor.execute("select tags.title, tags.album, tags.artist, tags.genre, statistics.percentage, statistics.playcounter FROM tags, statistics WHERE tags.url = statistics.url"):
		if score <= 20:
			score = 20
		if 20 < score <= 40:
			score = 40
		if 40 < score <= 60:
			score = 60
		if 60 < score <= 80:
			score = 80
		if score > 80:
			score = 100
		s += artists[artist] +"\t" + title + "\t"+str(counter)+"\t"+albums[album]+"\t"+str(score)+"\n" 
		#print s
	bs = s.encode('ascii', 'ignore').encode('base64')
	server = xmlrpclib.ServerProxy("http://www.musicmobs.com/services/xmlrpc.php")
	print "OK"
	try:
		res = server.musicmobs.updateProfile(username, password, bs)
	except xmlrpclib.ProtocolError:
		print "MusicMobs.com plugin: Could not submit tracks (Network Error)" 
	except:
		print "XML-RPC ERROR: Check your credentials"
		
if __name__ == "__main__":
	if len(sys.argv) < 4:
		print "Usage: amarok2musicmobs.py /path/to/your/collection.db username password"
	else:
		submit(sys.argv[1],sys.argv[2],sys.argv[3])

Usage

If you mark the file as executable and move it somewhere into your path, you can update your metadata as follows:

1amarok2musicmobs.py /path/to/your/collection.db username password

For example:

1amarok2musicmobs.py ~/.kde/share/apps/amarok/collection.db username password

If you want your profile to be updated regularly, consider a cron job.