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)
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) ]
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)
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)
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')