This repository has been archived by the owner on Jun 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
239 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import logging | ||
|
||
from fuocore.models import ( | ||
BaseModel, | ||
SongModel, | ||
AlbumModel, | ||
ArtistModel, | ||
SearchModel, | ||
) | ||
|
||
from .provider import provider | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LBaseModel(BaseModel): | ||
_detail_fields = () | ||
|
||
class Meta: | ||
allow_get = True | ||
provider = provider | ||
|
||
def __getattribute__(self, name): | ||
cls = type(self) | ||
value = object.__getattribute__(self, name) | ||
if name in cls._detail_fields and value is None: | ||
logger.debug('Field %s value is None, get model detail first.' % name) | ||
obj = cls.get(self.identifier) | ||
for field in cls._detail_fields: | ||
setattr(self, field, getattr(obj, field)) | ||
value = object.__getattribute__(self, name) | ||
elif name in cls._detail_fields and not value: | ||
logger.debug('Field %s value is not None, but is %s' % (name, value)) | ||
return value | ||
|
||
|
||
class LSongModel(SongModel, LBaseModel): | ||
|
||
@classmethod | ||
def get(cls, identifier): | ||
return cls.meta.provider.library._songs.get(identifier) | ||
|
||
@classmethod | ||
def list(cls, identifier_list): | ||
return map(cls.meta.provider.library._songs.get, identifier_list) | ||
|
||
|
||
class LAlbumModel(AlbumModel, LBaseModel): | ||
_detail_fields = ('songs',) | ||
|
||
@classmethod | ||
def get(cls, identifier): | ||
return cls.meta.provider.library._albums.get(identifier) | ||
|
||
|
||
class LArtistModel(ArtistModel, LBaseModel): | ||
_detail_fields = ('songs',) | ||
|
||
@classmethod | ||
def get(cls, identifier): | ||
return cls.meta.provider.library._artists.get(identifier) | ||
|
||
|
||
class LSearchModel(SearchModel, LBaseModel): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.