added image capturing
This commit is contained in:
parent
028bce6ee8
commit
c1e43eb41b
@ -1,4 +1,5 @@
|
|||||||
from fmframework.model.fm import LastFM, Wiki
|
from typing import List
|
||||||
|
from fmframework.model.fm import LastFM, Wiki, Image
|
||||||
from fmframework.model.artist import Artist
|
from fmframework.model.artist import Artist
|
||||||
from fmframework.util.console import Color
|
from fmframework.util.console import Color
|
||||||
|
|
||||||
@ -13,14 +14,15 @@ class Album(LastFM):
|
|||||||
user_scrobbles: int = None,
|
user_scrobbles: int = None,
|
||||||
wiki: Wiki = None,
|
wiki: Wiki = None,
|
||||||
artist: Artist = None,
|
artist: Artist = None,
|
||||||
):
|
images: List[Image] = None):
|
||||||
super().__init__(name=name,
|
super().__init__(name=name,
|
||||||
url=url,
|
url=url,
|
||||||
mbid=mbid,
|
mbid=mbid,
|
||||||
listeners=listeners,
|
listeners=listeners,
|
||||||
play_count=play_count,
|
play_count=play_count,
|
||||||
user_scrobbles=user_scrobbles,
|
user_scrobbles=user_scrobbles,
|
||||||
wiki=wiki)
|
wiki=wiki,
|
||||||
|
images=images)
|
||||||
self.artist = artist
|
self.artist = artist
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
from typing import List
|
||||||
from fmframework.util.console import Color
|
from fmframework.util.console import Color
|
||||||
from fmframework.model.fm import LastFM, Wiki
|
from fmframework.model.fm import LastFM, Wiki, Image
|
||||||
|
|
||||||
|
|
||||||
class Artist(LastFM):
|
class Artist(LastFM):
|
||||||
@ -10,14 +11,16 @@ class Artist(LastFM):
|
|||||||
listeners: int = None,
|
listeners: int = None,
|
||||||
play_count: int = None,
|
play_count: int = None,
|
||||||
user_scrobbles: int = None,
|
user_scrobbles: int = None,
|
||||||
wiki: Wiki = None):
|
wiki: Wiki = None,
|
||||||
|
images: List[Image] = None):
|
||||||
super().__init__(name=name,
|
super().__init__(name=name,
|
||||||
url=url,
|
url=url,
|
||||||
mbid=mbid,
|
mbid=mbid,
|
||||||
listeners=listeners,
|
listeners=listeners,
|
||||||
play_count=play_count,
|
play_count=play_count,
|
||||||
user_scrobbles=user_scrobbles,
|
user_scrobbles=user_scrobbles,
|
||||||
wiki=wiki)
|
wiki=wiki,
|
||||||
|
images=images)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.name}'
|
return f'{self.name}'
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from fmframework.util.console import Color
|
from fmframework.util.console import Color
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from enum import Enum
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from fmframework.model.track import Track
|
from fmframework.model.track import Track
|
||||||
|
|
||||||
|
|
||||||
|
class Image:
|
||||||
|
class Size(Enum):
|
||||||
|
small = 1
|
||||||
|
medium = 2
|
||||||
|
large = 3
|
||||||
|
extralarge = 4
|
||||||
|
|
||||||
|
def __init__(self, size: Size, link: str):
|
||||||
|
self.size = size
|
||||||
|
self.link = link
|
||||||
|
|
||||||
|
|
||||||
class Wiki:
|
class Wiki:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
date: datetime = None,
|
date: datetime = None,
|
||||||
@ -29,7 +43,8 @@ class LastFM:
|
|||||||
listeners: int = None,
|
listeners: int = None,
|
||||||
play_count: int = None,
|
play_count: int = None,
|
||||||
user_scrobbles: int = None,
|
user_scrobbles: int = None,
|
||||||
wiki: Wiki = None):
|
wiki: Wiki = None,
|
||||||
|
images: List[Image] = None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.url = url
|
self.url = url
|
||||||
self.mbid = mbid
|
self.mbid = mbid
|
||||||
@ -37,6 +52,7 @@ class LastFM:
|
|||||||
self.play_count = play_count
|
self.play_count = play_count
|
||||||
self.user_scrobbles = user_scrobbles
|
self.user_scrobbles = user_scrobbles
|
||||||
self.wiki = wiki
|
self.wiki = wiki
|
||||||
|
self.images = images
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from fmframework.model.fm import LastFM, Wiki
|
from typing import List
|
||||||
|
from fmframework.model.fm import LastFM, Wiki, Image
|
||||||
from fmframework.model.album import Album
|
from fmframework.model.album import Album
|
||||||
from fmframework.model.artist import Artist
|
from fmframework.model.artist import Artist
|
||||||
from fmframework.util.console import Color
|
from fmframework.util.console import Color
|
||||||
@ -15,14 +16,15 @@ class Track(LastFM):
|
|||||||
wiki: Wiki = None,
|
wiki: Wiki = None,
|
||||||
album: Album = None,
|
album: Album = None,
|
||||||
artist: Artist = None,
|
artist: Artist = None,
|
||||||
):
|
images: List[Image] = None):
|
||||||
super().__init__(name=name,
|
super().__init__(name=name,
|
||||||
url=url,
|
url=url,
|
||||||
mbid=mbid,
|
mbid=mbid,
|
||||||
listeners=listeners,
|
listeners=listeners,
|
||||||
play_count=play_count,
|
play_count=play_count,
|
||||||
user_scrobbles=user_scrobbles,
|
user_scrobbles=user_scrobbles,
|
||||||
wiki=wiki)
|
wiki=wiki,
|
||||||
|
images=images)
|
||||||
self.album = album
|
self.album = album
|
||||||
self.artist = artist
|
self.artist = artist
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from datetime import datetime, date, time, timedelta
|
from datetime import datetime, date, time, timedelta
|
||||||
|
|
||||||
from fmframework.model.fm import Scrobble, Wiki
|
from fmframework.model.fm import Scrobble, Wiki, Image
|
||||||
from fmframework.model.track import Track
|
from fmframework.model.track import Track
|
||||||
from fmframework.model.album import Album
|
from fmframework.model.album import Album
|
||||||
from fmframework.model.artist import Artist
|
from fmframework.model.artist import Artist
|
||||||
@ -260,7 +260,8 @@ class Network:
|
|||||||
play_count=int(artist_dict.get('stats', {}).get('playcount', 0)),
|
play_count=int(artist_dict.get('stats', {}).get('playcount', 0)),
|
||||||
user_scrobbles=int(artist_dict.get('stats', {}).get('userplaycount',
|
user_scrobbles=int(artist_dict.get('stats', {}).get('userplaycount',
|
||||||
artist_dict.get('playcount', 0))),
|
artist_dict.get('playcount', 0))),
|
||||||
wiki=self.parse_wiki(artist_dict['wiki']) if artist_dict.get('wiki', None) else None)
|
wiki=self.parse_wiki(artist_dict['wiki']) if artist_dict.get('wiki', None) else None,
|
||||||
|
images=[self.parse_image(i) for i in artist_dict.get('image', [])])
|
||||||
|
|
||||||
def parse_album(self, album_dict) -> Album:
|
def parse_album(self, album_dict) -> Album:
|
||||||
return Album(name=album_dict.get('name', album_dict.get('title', 'n/a')),
|
return Album(name=album_dict.get('name', album_dict.get('title', 'n/a')),
|
||||||
@ -270,7 +271,8 @@ class Network:
|
|||||||
play_count=int(album_dict.get('playcount', 0)),
|
play_count=int(album_dict.get('playcount', 0)),
|
||||||
user_scrobbles=int(album_dict.get('userplaycount', 0)),
|
user_scrobbles=int(album_dict.get('userplaycount', 0)),
|
||||||
wiki=self.parse_wiki(album_dict['wiki']) if album_dict.get('wiki', None) else None,
|
wiki=self.parse_wiki(album_dict['wiki']) if album_dict.get('wiki', None) else None,
|
||||||
artist=album_dict.get('artist'))
|
artist=album_dict.get('artist'),
|
||||||
|
images=[self.parse_image(i) for i in album_dict.get('image', [])])
|
||||||
|
|
||||||
def parse_track(self, track_dict) -> Track:
|
def parse_track(self, track_dict) -> Track:
|
||||||
track = Track(name=track_dict.get('name', 'n/a'),
|
track = Track(name=track_dict.get('name', 'n/a'),
|
||||||
@ -279,7 +281,8 @@ class Network:
|
|||||||
listeners=int(track_dict.get('listeners', 0)),
|
listeners=int(track_dict.get('listeners', 0)),
|
||||||
play_count=int(track_dict.get('playcount', 0)),
|
play_count=int(track_dict.get('playcount', 0)),
|
||||||
user_scrobbles=int(track_dict.get('userplaycount', 0)),
|
user_scrobbles=int(track_dict.get('userplaycount', 0)),
|
||||||
wiki=self.parse_wiki(track_dict['wiki']) if track_dict.get('wiki', None) else None)
|
wiki=self.parse_wiki(track_dict['wiki']) if track_dict.get('wiki', None) else None,
|
||||||
|
images=[self.parse_image(i) for i in track_dict.get('image', [])])
|
||||||
|
|
||||||
if track_dict.get('album', None):
|
if track_dict.get('album', None):
|
||||||
track.album = self.parse_album(track_dict['album'])
|
track.album = self.parse_album(track_dict['album'])
|
||||||
@ -289,6 +292,10 @@ class Network:
|
|||||||
|
|
||||||
return track
|
return track
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse_image(image_dict) -> Image:
|
||||||
|
return Image(size=Image.Size[image_dict['size']], link=image_dict['#text'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_scrobble(scrobble_dict) -> Scrobble:
|
def parse_scrobble(scrobble_dict) -> Scrobble:
|
||||||
album = None
|
album = None
|
||||||
|
Loading…
Reference in New Issue
Block a user