-
Notifications
You must be signed in to change notification settings - Fork 1
/
da.py
72 lines (53 loc) · 1.36 KB
/
da.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
67
68
69
70
71
72
import models
import time
import json
def get_library():
return list(models.Song.select())
def get_song(id):
return list(models.Song.selectBy(id=id))[0]
def add_song(name, artist, url, art, tags):
try:
song = models.Song(
name=name,
artist=artist,
url=url,
art=art,
liked=0,
lyrics='',
added=time.time(),
tags=json.dumps([tag.strip() for tag in tags.split(',')])
)
song.set()
return True, None
except Exception as e:
return False, e
def delete_song(song_id):
try:
song = get_song(song_id)
song.delete(id=song_id)
return True
except Exception as e:
print(e)
return False
def edit_song(id, name, artist, tags):
song = get_song(id)
if song is not None:
song.name = name
song.artist = artist
song.tags = json.dumps([tag.strip() for tag in tags.split(',')])
song.syncUpdate()
return True
else:
return False
def update_song_lyrics(song, lyrics):
song.lyrics = lyrics
song.syncUpdate()
def like_unlike_song(song, liked):
try:
song.liked = liked
song.syncUpdate()
return True
except:
return False
def get_liked_songs():
return list(models.Song.selectBy(liked=True))