added image capturing

This commit is contained in:
aj 2019-10-08 18:57:42 +01:00
parent 028bce6ee8
commit c1e43eb41b
5 changed files with 44 additions and 14 deletions

View File

@ -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.util.console import Color
@ -13,14 +14,15 @@ class Album(LastFM):
user_scrobbles: int = None,
wiki: Wiki = None,
artist: Artist = None,
):
images: List[Image] = None):
super().__init__(name=name,
url=url,
mbid=mbid,
listeners=listeners,
play_count=play_count,
user_scrobbles=user_scrobbles,
wiki=wiki)
wiki=wiki,
images=images)
self.artist = artist
def __str__(self):

View File

@ -1,5 +1,6 @@
from typing import List
from fmframework.util.console import Color
from fmframework.model.fm import LastFM, Wiki
from fmframework.model.fm import LastFM, Wiki, Image
class Artist(LastFM):
@ -10,14 +11,16 @@ class Artist(LastFM):
listeners: int = None,
play_count: int = None,
user_scrobbles: int = None,
wiki: Wiki = None):
wiki: Wiki = None,
images: List[Image] = None):
super().__init__(name=name,
url=url,
mbid=mbid,
listeners=listeners,
play_count=play_count,
user_scrobbles=user_scrobbles,
wiki=wiki)
wiki=wiki,
images=images)
def __str__(self):
return f'{self.name}'

View File

@ -1,12 +1,26 @@
from __future__ import annotations
from fmframework.util.console import Color
from datetime import datetime
from enum import Enum
from typing import List
from typing import TYPE_CHECKING
if TYPE_CHECKING:
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:
def __init__(self,
date: datetime = None,
@ -29,7 +43,8 @@ class LastFM:
listeners: int = None,
play_count: int = None,
user_scrobbles: int = None,
wiki: Wiki = None):
wiki: Wiki = None,
images: List[Image] = None):
self.name = name
self.url = url
self.mbid = mbid
@ -37,6 +52,7 @@ class LastFM:
self.play_count = play_count
self.user_scrobbles = user_scrobbles
self.wiki = wiki
self.images = images
def __str__(self):
return self.name

View File

@ -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.artist import Artist
from fmframework.util.console import Color
@ -15,14 +16,15 @@ class Track(LastFM):
wiki: Wiki = None,
album: Album = None,
artist: Artist = None,
):
images: List[Image] = None):
super().__init__(name=name,
url=url,
mbid=mbid,
listeners=listeners,
play_count=play_count,
user_scrobbles=user_scrobbles,
wiki=wiki)
wiki=wiki,
images=images)
self.album = album
self.artist = artist

View File

@ -5,7 +5,7 @@ import logging
from enum import Enum
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.album import Album
from fmframework.model.artist import Artist
@ -260,7 +260,8 @@ class Network:
play_count=int(artist_dict.get('stats', {}).get('playcount', 0)),
user_scrobbles=int(artist_dict.get('stats', {}).get('userplaycount',
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:
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)),
user_scrobbles=int(album_dict.get('userplaycount', 0)),
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:
track = Track(name=track_dict.get('name', 'n/a'),
@ -279,7 +281,8 @@ class Network:
listeners=int(track_dict.get('listeners', 0)),
play_count=int(track_dict.get('playcount', 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):
track.album = self.parse_album(track_dict['album'])
@ -289,6 +292,10 @@ class Network:
return track
@staticmethod
def parse_image(image_dict) -> Image:
return Image(size=Image.Size[image_dict['size']], link=image_dict['#text'])
@staticmethod
def parse_scrobble(scrobble_dict) -> Scrobble:
album = None