示例#1
0
    def on_btnSave_clicked(self, button):
        try:
            titles = self.get_value(self.txt_Title)
            artists = self.get_value(self.txt_Artist)
            artistalbums = self.get_value(self.txt_ArtistAlbum)
            albums = self.get_value(self.txt_Album)
            tracknumbers = self.get_value(self.txt_TrackNumber)
            years = self.get_value(self.txt_Year)
            addeds = self.get_value(self.txt_Added)
            genres = self.get_value(self.txt_Genre)
            comments = self.get_value(self.txt_Comment)

            with database_context.atomic():
                for index, song in enumerate(self.songs):
                    song.Title = titles[index]
                    song.Artist = artists[index]
                    song.AlbumArtist = artistalbums[index]
                    song.Album = albums[index]
                    song.Tracknumber = tracknumbers[index]
                    song.Year = years[index]
                    song.Comment = comments[index]
                    song.Genre = genres[index]
                    song.Added = arrow.get(addeds[index]).naive.date()
                    song.save()
                    song.write_tags()

            self.window.destroy()

        except Exception as e:
            logging.exception("Could not save tags")
示例#2
0
    def __sync_songs(self):
        paths = []
        # Create a list of every potential file in the music folder
        for x in pathlib.Path(self.musics_folder).glob('**/*'):
            try:
                if x.is_dir():
                    continue
                if x.suffix.lower() in self.INGORE_EXTENSION:
                    continue
                paths.append(str(x.resolve(False)))
            except OSError:
                self.logger.exception('Error while scanning songs')

        all_paths = set(paths)
        known_paths = {x.Path for x in Song.select(Song.Path)}
        new_paths = all_paths - known_paths
        deleted_paths = known_paths - all_paths

        with database_context.atomic():
            for index, path in enumerate(new_paths):
                mime = mimetypes.guess_type(path)
                if mime[0] and 'audio' in str(
                        mime[0]) and 'mpegurl' not in str(mime[0]):
                    s = Song(Path=path)
                    s.read_tags()
                    s.save()
                if index % 300 == 0 and index > 0:
                    self.logger.info(
                        f'Scanning songs {index}/{len(new_paths)}')

            for song in deleted_paths:
                Song.delete().where(Song.Path == song).execute()

        self.logger.info(f'Scanning songs completed')
示例#3
0
    def __sync_playlists(self):
        self.logger.info('Scanning playlists')

        all_paths = set(
            str(x)
            for x in pathlib.Path(self.playlists_folder).glob('**/*m3u'))
        known_paths = {x.Path for x in Playlist.select(Playlist.Path)}
        new_paths = all_paths - known_paths
        deleted_paths = known_paths - all_paths
        with database_context.atomic():
            for path in new_paths:
                playlist = M3uParser(path)
                Playlist(Name=playlist.name, Path=playlist.location).save()
            for path in deleted_paths:
                Playlist.delete().where(Playlist.Path == path).execute()
示例#4
0
    def import_song_statistic_from(self, database_file):
        self.logger.info('Importing database songs statistics')
        try:
            from playhouse.sqlite_ext import SqliteExtDatabase
            other_database = SqliteExtDatabase(database_file)
            cursor = other_database.execute_sql(
                "SELECT ADDED, LAST_PLAYED, PLAYED, TITLE, ARTIST, ALBUM FROM SONG"
            )
            with database_context.atomic():
                for row in cursor.fetchall():
                    database_context.execute_sql(
                        "UPDATE SONG SET ADDED = ?, LAST_PLAYED = ?, PLAYED = ? WHERE TITLE = ? AND ARTIST = ? AND ALBUM = ?",
                        row)

            other_database.close()
        except:
            self.logger.exception(
                'Error while importing database songs statistics')
示例#5
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')