Exemple #1
0
    def from_local(self):
        with ignored(ImportError):
            self._config.from_object('shiva.config.local')

            return True

        return False
Exemple #2
0
    def get_album(self, name, artist):
        name = name.strip() if type(name) in (str, unicode) else None
        if not name or not artist:
            return None

        if name in self.albums:
            return self.albums[name]
        else:
            release_year = self.get_release_year()
            cover = None
            if self.use_lastfm:
                log.debug('[ Last.FM ] Retrieving album "%s" by "%s"' % (
                          name, artist.name))
                with ignored(Exception, print_traceback=True):
                    _artist = self.lastfm.get_artist(artist.name)
                    _album = self.lastfm.get_album(_artist, name)
                    release_year = self.get_release_year(_album)
                    pylast_cover = self.pylast.COVER_EXTRA_LARGE
                    cover = _album.get_cover_image(size=pylast_cover)

            album = m.Album(name=name, year=release_year, cover=cover)
            self.session.add(album)
            self.albums[name] = album

        return album
Exemple #3
0
    def from_local(self):
        with ignored(ImportError):
            self._config.from_object("shiva.config.local")

            return True

        return False
Exemple #4
0
    def get_album(self, name, artist):
        name = name.strip() if type(name) in (str, unicode) else None
        if not name or not artist:
            return None

        if name in self.albums:
            return self.albums[name]
        else:
            release_year = self.get_release_year()
            cover = None
            if self.use_lastfm:
                log.debug('[ Last.FM ] Retrieving album "%s" by "%s"' %
                          (name, artist.name))
                with ignored(Exception, print_traceback=True):
                    _artist = self.lastfm.get_artist(artist.name)
                    _album = self.lastfm.get_album(_artist, name)
                    release_year = self.get_release_year(_album)
                    pylast_cover = self.pylast.COVER_EXTRA_LARGE
                    cover = _album.get_cover_image(size=pylast_cover)

            album = m.Album(name=name, year=release_year, cover=cover)
            self.session.add(album)

            if not self.low_ram:
                self.albums[name] = album

        return album
Exemple #5
0
    def get_artist_image(self, name):
        image = None

        log.debug('[ Last.FM ] Retrieving artist image for "%s"' % name)
        with ignored(Exception, print_traceback=True):
            image = self.get_artist(name).get_cover_image()

        return image
Exemple #6
0
    def get_artist_image(self, name):
        image = None

        log.debug('[ Last.FM ] Retrieving artist image for "%s"' % name)
        with ignored(Exception, print_traceback=True):
            image = self.get_artist(name).get_cover_image()

        return image
Exemple #7
0
    def get_artist(self, name):
        artist = self.cache.get(name, {}).get('object')

        if not artist:
            log.debug('[ Last.FM ] Retrieving artist "%s"' % name)
            with ignored(Exception, print_traceback=True):
                artist = self.lib.get_artist(name)
            if artist and self.use_cache:
                self.cache.update({name: {'object': artist}})

        return artist
Exemple #8
0
    def get_album_cover(self, album_name, artist_name):
        cover = None
        album = self.get_album(album_name, artist_name)

        if not album:
            return None

        log.debug('[ Last.FM ] Retrieving album "%s" by "%s" cover image' %
                  (album_name, artist_name))
        with ignored(Exception, print_traceback=True):
            cover = album.get_cover_image(size=self.pylast.COVER_EXTRA_LARGE)

        return cover
Exemple #9
0
    def get_album_cover(self, album_name, artist_name):
        cover = None
        album = self.get_album(album_name, artist_name)

        if not album:
            return None

        log.debug('[ Last.FM ] Retrieving album "%s" by "%s" cover image' % (
                  name, artist.name))
        with ignored(Exception, print_traceback=True):
            cover = album.get_cover_image(size=self.lib.COVER_EXTRA_LARGE)

        return cover
Exemple #10
0
    def get_release_date(self, album_name, artist_name):
        rdate = None
        album = self.get_album(album_name, artist_name)

        if not album:
            return None

        log.debug('[ Last.FM ] album "%s" by "%s" release date' %
                  (album_name, artist_name))
        with ignored(Exception, print_traceback=True):
            rdate = album.get_release_date()
            rdate = datetime.strptime(rdate, '%d %b %Y, %H:%M')

        return rdate
Exemple #11
0
    def get_release_date(self, album_name, artist_name):
        album = self.get_album(album_name, artist_name)
        if not album:
            return None

        log.debug('[ Last.FM ] album "%s" by "%s" release date' % (
                  name, artist.name))
        with ignored(Exception, print_traceback=True):
            rdate = album.get_release_date()

        if not rdate:
            return None

        return datetime.strptime(rdate, '%d %b %Y, %H:%M')
Exemple #12
0
    def load_debug(self):
        if not self._config.get('DEBUG'):
            return False

        loaded = False
        with ignored(ImportError):
            from shiva.config import debug

            loaded = self._config.from_object(debug)

        debug_py = os.path.join(self.get_xdg_path(), 'shiva/debug.py')
        if not os.path.exists(debug_py):
            return False

        return self._config.from_pyfile(debug_py) or loaded
Exemple #13
0
    def get_artist(self, name):
        artist = self.cache.get(name, {}).get('object')

        if not artist:
            with ignored(Exception, print_traceback=True):
                log.debug('[ Last.FM ] Retrieving artist "%s"' % name)
                artist = self.lib.get_artist(name)
            if artist and self.use_cache:
                self.cache.update({
                    name: {
                        'object': artist
                    }
                })

        return artist
Exemple #14
0
    def load_debug(self):
        if not self._config.get('DEBUG'):
            return False

        loaded = False
        with ignored(ImportError):
            from shiva.config import debug

            loaded = self._config.from_object(debug)

        debug_py = os.path.join(self.get_xdg_path(), 'shiva/debug.py')
        if not os.path.exists(debug_py):
            return False

        return self._config.from_pyfile(debug_py) or loaded
Exemple #15
0
    def get_artist(self, name):
        name = name.strip() if type(name) in (str, unicode) else None
        if not name:
            return None

        if name in self.artists:
            return self.artists[name]
        else:
            cover = None
            if self.use_lastfm:
                log.debug('[ Last.FM ] Retrieving "%s" info' % name)
                with ignored(Exception, print_traceback=True):
                    cover = self.lastfm.get_artist(name).get_cover_image()
            artist = m.Artist(name=name, image=cover)
            self.session.add(artist)
            self.artists[name] = artist

        return artist
Exemple #16
0
    def get_album(self, name, artist_name):
        album = self.cache.get(artist_name, {}).get('albums', {}).get(name)

        if not album:
            artist = self.get_artist(artist_name)
            log.debug('[ Last.FM ] Retrieving album "%s" by "%s"' %
                      (name, artist.name))
            with ignored(Exception, print_traceback=True):
                album = self.lib.get_album(artist, name)

            if album and self.use_cache:
                self.cache.update(
                    {artist.name: {
                        'albums': {
                            album.name: album
                        }
                    }})

        return album
Exemple #17
0
    def get_album(self, name, artist_name):
        album = self.cache.get(artist_name, {}).get('albums', {}).get(name)

        if not album:
            artist = self.get_artist(artist_name)
            log.debug('[ Last.FM ] Retrieving album "%s" by "%s"' % (
                      name, artist.name))
            with ignored(Exception, print_traceback=True):
                album = self.lib.get_album(artist, name)

            if album and self.use_cache:
                self.cache.update({
                    artist.name: {
                        'albums': {
                            album.name: album
                        }
                    }
                })

        return album
Exemple #18
0
    def get_artist(self, name):
        name = name.strip() if type(name) in (str, unicode) else None
        if not name:
            return None

        if name in self.artists:
            return self.artists[name]
        else:
            cover = None
            if self.use_lastfm:
                log.debug('[ Last.FM ] Retrieving "%s" info' % name)
                with ignored(Exception, print_traceback=True):
                    cover = self.lastfm.get_artist(name).get_cover_image()
            artist = m.Artist(name=name, image=cover)
            self.session.add(artist)

            if not self.low_ram:
                self.artists[name] = artist

        return artist
Exemple #19
0
# -*- coding: utf-8 -*-
"""
There are 3 types of settings.
1) System. Stays the same for every project.
2) Local. Specific to each instance of the project. Not versioned.
3) Debug. Applies for debugging. Forbidden for production use.
"""
import logging
import traceback

from shiva.config.project import *
from shiva.utils import ignored
try:
    # Rename the file local.py.example to local.py and edit it.
    from shiva.config.local import *
except ImportError:
    print(traceback.format_exc())
    logging.warning("Couldn't find local settings.")
if DEBUG:
    with ignored(ImportError):
        from shiva.config.debug import *