This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wimedb.py
66 lines (49 loc) · 1.51 KB
/
wimedb.py
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
import sqlite3
import eyeD3
import time
def insert(filename, database):
conn = sqlite3.connect(database)
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS queue
(FILE text, SONG text, ARTIST text, TIME bigint)''')
song_data = []
song_data.append(filename)
audiofile = eyeD3.Mp3AudioFile(filename)
tag = audiofile.getTag()
tag.link(filename)
song_data.append(tag.getTitle())
song_data.append(tag.getArtist())
song_data.append(int(round(time.time() * 1000)))
c.execute("INSERT INTO queue VALUES (?,?,?,?)", song_data)
conn.commit()
conn.close()
def get(filename, database):
conn = sqlite3.connect(database)
c = conn.cursor()
c.execute("SELECT * FROM queue WHERE FILE = ?", [filename] )
ret = c.fetchone()
conn.close()
return ret
def get_most_recent(database):
conn = sqlite3.connect(database)
c = conn.cursor()
c.execute("SELECT MIN(TIME) FROM queue")
time = c.fetchone()[0]
c.execute("SELECT * FROM queue WHERE TIME = ?", [time])
ret = c.fetchone()
conn.close()
return ret
def get_songs(database):
conn = sqlite3.connect(database)
c = conn.cursor()
ret = []
for row in c.execute("SELECT * FROM queue ORDER BY TIME"):
ret.append(row)
conn.close()
return ret
def remove(filename, database):
conn = sqlite3.connect(database)
c = conn.cursor()
c.execute("DELETE FROM queue WHERE FILE=?", [filename])
conn.commit()
conn.close()