Exemplo n.º 1
0
    def __init__(self, appconfig, userconfig):
        self.logger = logging.getLogger('Library')
        database_context.init(appconfig.DATABASE_FILE)

        Song.create_table(True)
        Album.create_table(True)
        Artist.create_table(True)
        Playlist.create_table(True)

        self.appconfig = appconfig
        self.userconfig = userconfig
Exemplo n.º 2
0
    def test_sync(self):
        self.library.sync()

        time.sleep(1)
        self.assertEqual(Song.select().count(), 8)
        self.assertEqual(Artist.select().count(), 2)
        self.assertEqual(Album.select().count(), 4)
        self.assertEqual(Playlist.select().count(), 1)

        self.library.sync()

        self.assertEqual(Song.select().count(), 8)
        self.assertEqual(Artist.select().count(), 2)
        self.assertEqual(Album.select().count(), 4)
        self.assertEqual(Playlist.select().count(), 1)
Exemplo n.º 3
0
 def get_album(self, name, albumartist):
     try:
         return Album.get(
             Album.Name == name,
             peewee.fn.lower(Album.Artist) == albumartist.lower())
     except peewee.DoesNotExist:
         return None
Exemplo n.º 4
0
 def __init__(self, album=None, song_path=None):
     if album:
         self.album = album
     elif song_path:
         song = Song.get(Song.Path == song_path)
         self.album = Album.get(
             Album.Name == song.Album,
             peewee.fn.lower(Album.Artist) == song.AlbumArtist.lower())
Exemplo n.º 5
0
 def collections_album(self,
                       order=AbstractPlaylist.OrderBy.DEFAULT,
                       desc=False):
     return [
         AlbumPlaylist(x) for x in Album.select().where(
             peewee.fn.lower(Album.Artist) ==
             self.artist.Name.lower()).order_by(-Album.Year)
     ]
Exemplo n.º 6
0
    def get_playlist(self, name):
        try:
            x = Artist.get(Artist.Name == name)
            return playlists.ArtistPlaylist(x)
        except peewee.DoesNotExist:
            pass

        try:
            x = Album.get(Album.Name == name)
            return playlists.AlbumPlaylist(x)
        except peewee.DoesNotExist:
            pass

        return None
Exemplo n.º 7
0
    def test_sync_with_delete(self):
        self.library.sync()

        for index, path in enumerate(LibraryTest.DST_FILE):
            if index != 0:
                pathlib.Path(path).unlink()

        pathlib.Path(self.PLAYLIST_FILE).unlink()

        self.library.sync()

        self.assertEqual(Song.select().count(), 1)
        self.assertEqual(Album.select().count(), 1)
        self.assertEqual(Artist.select().count(), 1)
        self.assertEqual(Playlist.select().count(), 0)
Exemplo n.º 8
0
    def test_sync_with_add(self):
        self.library.sync()

        new_song_path = './test/library/songa.ogg'
        shutil.copy(LibraryTest.SRC_FILE, new_song_path)

        song = Song(Path=new_song_path)
        song.read_tags()
        song.Title = 'Title!'
        song.Artist = 'Artist!'
        song.Album = 'Album!'
        song.write_tags()

        self.library.sync()

        self.assertEqual(Song.select().count(), 9)
        self.assertEqual(Artist.select().count(), 3)
        self.assertEqual(Album.select().count(), 5)
Exemplo n.º 9
0
    def sync_artwork(self):
        """ For every album and artist with a missing cover try to fetch it """
        with database_context.atomic():
            for album in Album.select():
                if not album.Cover or not pathlib.Path(album.Cover).exists():
                    path = pathlib.Path(album.Path).parent if pathlib.Path(
                        album.Path).is_file else album.Path
                    album.Cover = artworks.get_album_artwork(
                        self.appconfig.LASTFM_SECRET_API_KEY,
                        self.artworks_folder, album.Name, album.Artist, path)
                    album.save()

            for artist in Artist.select():
                if not artist.Cover or not pathlib.Path(artist.Cover).exists():
                    artist.Cover = artworks.get_artist_artwork(
                        self.appconfig.LASTFM_SECRET_API_KEY,
                        self.artworks_folder, artist.Name)
                    artist.save()

        self.logger.info(f'Artworks fetch completed')