Mixonomer/music/model/playlist.py

62 lines
1.7 KiB
Python
Raw Normal View History

2019-10-23 14:44:17 +01:00
from enum import Enum
2020-04-30 14:54:05 +01:00
from fireo.models import Model
from fireo.fields import TextField, BooleanField, DateTime, NumberField, ListField
2019-10-23 14:44:17 +01:00
class Sort(Enum):
default = 1
shuffle = 2
release_date = 3
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
class Playlist(Model):
class Meta:
collection_name = 'playlists'
2020-04-30 14:54:05 +01:00
uri = TextField()
name = TextField(required=True)
type = TextField(required=True)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
include_recommendations = BooleanField(default=False)
recommendation_sample = NumberField(default=10)
include_library_tracks = BooleanField(default=False)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
parts = ListField(default=[])
playlist_references = ListField(default=[])
shuffle = BooleanField(default=False)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
sort = TextField(default='release_date')
description_overwrite = TextField()
description_suffix = TextField()
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
last_updated = DateTime()
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
lastfm_stat_count = NumberField(default=0)
lastfm_stat_album_count = NumberField(default=0)
lastfm_stat_artist_count = NumberField(default=0)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
lastfm_stat_percent = NumberField(default=0)
lastfm_stat_album_percent = NumberField(default=0)
lastfm_stat_artist_percent = NumberField(default=0)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
lastfm_stat_last_refresh = DateTime()
2020-04-30 14:54:05 +01:00
add_last_month = BooleanField(default=False)
add_this_month = BooleanField(default=False)
day_boundary = NumberField(default=21)
2019-10-23 14:44:17 +01:00
chart_range = TextField(default='MONTH')
2020-04-30 14:54:05 +01:00
chart_limit = NumberField(default=50)
2019-10-23 14:44:17 +01:00
def to_dict(self):
2020-04-30 14:54:05 +01:00
to_return = super().to_dict()
2020-04-30 14:54:05 +01:00
to_return["playlist_references"] = [i.get().to_dict().get('name') for i in to_return['playlist_references']]
2020-04-30 14:54:05 +01:00
# remove unnecessary and sensitive fields
to_return.pop('id', None)
to_return.pop('key', None)
2020-04-30 14:54:05 +01:00
return to_return