pyfmframework/fmframework/model/fm.py

100 lines
2.5 KiB
Python
Raw Normal View History

2019-10-03 19:06:44 +01:00
from __future__ import annotations
from fmframework.util.console import Color
from datetime import datetime
2019-10-08 18:57:42 +01:00
from enum import Enum
from typing import List
2019-10-03 19:06:44 +01:00
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from fmframework.model.track import Track
2019-10-08 18:57:42 +01:00
class Image:
class Size(Enum):
2019-12-28 02:53:16 +00:00
other = 0
2019-10-08 18:57:42 +01:00
small = 1
medium = 2
large = 3
extralarge = 4
mega = 5
2019-10-08 18:57:42 +01:00
def __init__(self, size: Size, link: str):
self.size = size
self.link = link
def __str__(self):
return f'{self.size.name} - {self.link}'
2019-10-08 18:57:42 +01:00
2019-10-03 19:06:44 +01:00
class Wiki:
def __init__(self,
date: datetime = None,
summary: str = None,
content: str = None):
self.date = date
self.summary = summary
self.content = content
def __repr__(self):
return Color.YELLOW + Color.BOLD + 'Wiki:' + Color.END + \
f': {self.date}, {self.summary}, {self.content}'
class LastFM:
def __init__(self,
name: str = None,
url: str = None,
mbid: str = None,
listeners: int = None,
play_count: int = None,
user_scrobbles: int = None,
2019-10-08 18:57:42 +01:00
wiki: Wiki = None,
images: List[Image] = None):
2019-10-03 19:06:44 +01:00
self.name = name
self.url = url
self.mbid = mbid
2019-10-03 19:06:44 +01:00
self.listeners = listeners
self.play_count = play_count
self.user_scrobbles = user_scrobbles
self.wiki = wiki
2019-10-08 18:57:42 +01:00
self.images = images
2019-10-03 19:06:44 +01:00
def __str__(self):
return self.name
def __repr__(self):
return Color.RED + Color.BOLD + 'LastFM' + Color.END + \
f': {self.name}, user({self.user_scrobbles}), play_count({self.play_count}), ' \
f'listeners({self.listeners}), wiki({self.wiki})'
class WeeklyChart:
def __init__(self, from_time, to_time):
self.from_secs = from_time
self.to_secs = to_time
@property
def from_date(self):
return datetime.fromtimestamp(self.from_secs)
@property
def to_date(self):
return datetime.fromtimestamp(self.to_secs)
def __str__(self):
return f'{self.from_secs} -> {self.to_secs}'
2019-10-03 19:06:44 +01:00
class Scrobble:
def __init__(self,
track: Track = None,
time: datetime = None):
self.track = track
self.time = time
def __str__(self):
return self.track
def __repr__(self):
return Color.BLUE + Color.BOLD + 'Scrobble' + Color.END + f': {self.time} {repr(self.track)}'