My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
"""
Copyright (C) 2011 Renato "Lond" Cerqueira <lond@dcc.ufrj.br>
Based on the source of elord, for

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from xml.dom import minidom
import MySQLdb
import os
import subprocess
from subprocess import Popen
import sys
import re
import shutil

VERBOSE = False
if "--verbose" in sys.argv:
VERBOSE = True

dbpath = "/var/run/mysqld/mysqld."
dbpass = "password"
dbuser = "amarokuser"

socketpath = dbpath + "sock"
dbname = "amarokdb"

#used database interaction
updateQuery = "UPDATE statistics SET playcount=playcount+1 WHERE url=%s"
insertionQuery = "INSERT INTO statistics (playcount, url) VALUES (%s, %s)"
statisticsQuery = "SELECT * FROM statistics WHERE url="
allTracksQuery = "SELECT * FROM playlist_tracks ORDER BY artist, title"
getPathQuery = "SELECT rpath, id FROM urls WHERE uniqueid=%s"

#Updates the database, connection is connection to the amarok DB
def updateDatabase(connection):
artistsCursor = connection.cursor()
tagsCursor = connection.cursor()
statisticsCursor = connection.cursor()
tracksCursor = connection.cursor()
rpathCursor = connection.cursor()

tracksCursor.execute(allTracksQuery) #get tracks in the playlist

for track in tracksCursor:
trackurl = track[3]
rpathCursor.execute(getPathQuery, trackurl)
for path in rpathCursor:
print "Path for "+track[4]+" is "+path[0]
myhome2="."+os.path.expanduser('~')+'/musicas/'
myhome="."+os.path.expanduser('~')+'/musicas2/'
try:mypath=re.sub(myhome2, "", re.sub(myhome, "", path[0]))
except:print "fuu!"
try:os.makedirs(os.path.dirname("/media/disk/Music/"+mypath))
except:print "directory already exists"

nupath = re.sub("^\.","",path[0])
print nupath
print path[1]

try:
shutil.copy(nupath, "/media/disk/Music/"+mypath)

statisticsCursor.execute(statisticsQuery + str(path[1]))
if statisticsCursor.rowcount == 0:
statisticsCursor.execute(insertionQuery,(1, path[1]))
else:
statisticsCursor.execute(updateQuery, path[1])
except:print sys.exc_info()


connection = MySQLdb.connect(unix_socket=socketpath, user=dbuser, passwd=dbpass, db=dbname ) #connect to the server

try: updateDatabase(connection)
except: print "Error in communication."
#finally: server.terminate()

Change log

r2 by renato.lond on Feb 7, 2011   Diff
Initial commit.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2911 bytes, 88 lines
Powered by Google Project Hosting