-
Notifications
You must be signed in to change notification settings - Fork 1
/
serializers.py
66 lines (56 loc) · 1.63 KB
/
serializers.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
class Song(object):
title = ''
artist = ''
album = ''
id = ''
def __init__(self, title, artist, album, id):
self.title = title
self.artist = artist
self.album = album
self.id = id
def __repr__(self):
return f"Song<{self.title} - {self.artist}>"
@staticmethod
def from_spotify(json):
return Song(
title=json['name'],
artist=json['artists'][0]['name'], # Just take the first artist
album=json['album']['name'],
id=json['id'],
)
@staticmethod
def from_gpm(json):
return Song(
title=json['title'],
artist=json['artist'],
album=json['album'],
id=json.get('storeId'), # This isn't always present
)
class Playlist(object):
songs = []
title = ''
description = ''
id = ''
def __init__(self, songs, title, description, id):
self.songs = songs
self.title = title
self.description = description
self.id = id
def __repr__(self):
return f"Playlist<{self.title}>"
@staticmethod
def from_spotify(json):
return Playlist(
songs=[Song.from_spotify(item['track']) for item in json['tracks']['items']],
title=json['name'],
description=json['description'],
id=json['id'],
)
@staticmethod
def from_gpm(json):
return Playlist(
songs=[Song.from_gpm(item['track']) for item in json['tracks']],
title=json['name'],
description=json['description'],
id=json['id'],
)