Exemple #1
0
    def RunImportProcess(self, data):
        # show tasks
        self.cli.ClearScreen()
        self.cli.SetCursor(0, 0)

        # rename songs
        for song in data["songs"]:
            oldpath = song[0]
            newpath = song[1]
            if oldpath == newpath:
                continue

            self.cli.PrintText(
                "\033[1;34mRename Song: \033[0;31m%s\033[1;34m -> \033[0;32m%s\n"
                % (song[0], song[1]))
            self.fs.MoveFile(oldpath, newpath)

        # rename album
        oldalbumpath = data["oldalbumpath"]
        newalbumpath = os.path.join(
            data["artistname"],
            data["releasedate"] + " - " + data["albumname"])
        if oldalbumpath != newalbumpath:
            self.cli.PrintText(
                "\033[1;34mRename Album:  \033[0;31m%s\033[1;34m -> \033[0;32m%s\n"
                % (oldalbumpath, newalbumpath))
            self.fs.MoveDirectory(oldalbumpath, newalbumpath)

        # rename artist
        oldartistpath = self.fs.GetDirectory(oldalbumpath)
        newartistpath = data["artistname"]
        if oldartistpath != newartistpath:
            self.cli.PrintText(
                "\033[1;34mRename Artist: \033[0;31m%s\033[1;34m -> \033[0;32m%s\n"
                % (oldartistpath, newartistpath))
            self.fs.MoveDirectory(oldartistpath, newartistpath)

        # import
        artist = self.db.GetArtistByPath(newartistpath)
        if not artist:
            self.cli.PrintText("\033[1;34mAdd new artist \033[0;36m%s\n" %
                               (newartistpath))
            self.db.AddArtist(newartistpath, newartistpath)
            artist = self.db.GetArtistByPath(newartistpath)

        if not artist:
            self.cli.PrintText(
                "\033[1;31mAdding artist failed! \033[1;30m(Retry the import workflow and check the names of the files in the file system)\033[0m"
            )
            return
        else:
            self.cli.PrintText("\033[1;34mImport album \033[0;36m%s\n" %
                               (newalbumpath))
            self.AddAlbum(newalbumpath, artist["id"])

        # set origin
        album = self.db.GetAlbumByPath(newalbumpath)
        if not album:
            self.cli.PrintText(
                "\033[1;31mImporting album failed! \033[1;30m(Retry the import workflow and check the names of the files in the file system)\033[0m"
            )
            return
        elif album["origin"] != data["origin"]:
            self.cli.PrintText("\033[1;34mSet Origin \033[0;36m%s\n" %
                               (data["origin"]))
            album["origin"] = data["origin"]
            self.db.WriteAlbum(album)
        self.cli.PrintText("\033[1;32mImporting album succeeded!\n")

        # process
        if data["runartwork"]:
            self.cli.PrintText("\033[1;37mRun Artwork Import\n")
            artwork = MusicDBArtwork(self.cfg, self.db)
            artwork.UpdateAlbumArtwork(album)

        if data["runlyrics"]:
            self.cli.PrintText("\033[1;37mRun Lyrics Import\n")
            metadata = MetaTags(self.cfg.music.path)

            for songtuple in data["songs"]:
                songpath = songtuple[1]
                song = self.db.GetSongByPath(songpath)
                if not song:
                    continue
                songid = song["id"]

                metadata.Load(songpath)
                lyrics = metadata.GetLyrics()
                if lyrics:
                    self.db.SetLyrics(songid, lyrics,
                                      SONG_LYRICSSTATE_FROMFILE)

        if data["runmusicai"]:
            self.cli.PrintText("\033[1;37mRun MusicAI\n")
            absalbumpath = self.fs.AbsolutePath(newalbumpath)
            musicai = musicai_module(self.cfg, self.db)
            mdbsongs = musicai.GetSongsFromPath(absalbumpath)
            if not mdbsongs:
                self.cli.PrintText(
                    "\033[1;31mNo songs to analyze found in %s! \033[1;30m\033[0m"
                    % (absalbumpath))
                return

            musicai.GenerateFeatureset(mdbsongs)
            prediction = musicai.PerformPrediction(mdbsongs)
            musicai.StorePrediction(prediction)
Exemple #2
0
    def RunImportProcess(self, data):
        # show tasks
        self.cli.ClearScreen()
        self.cli.SetCursor(0, 0)

        # rename songs
        for song in data["songs"]:
            oldpath = song[0]
            newpath = song[1]
            if oldpath == newpath:
                continue

            self.cli.PrintText(
                "\033[1;34mRename Song: \033[0;31m%s\033[1;34m -> \033[0;32m%s\n"
                % (song[0], song[1]))
            self.fs.MoveFile(oldpath, newpath)

        # rename album
        oldalbumpath = data["oldalbumpath"]
        newalbumpath = os.path.join(
            data["artistname"],
            data["releasedate"] + " - " + data["albumname"])
        if oldalbumpath != newalbumpath:
            self.cli.PrintText(
                "\033[1;34mRename Album:  \033[0;31m%s\033[1;34m -> \033[0;32m%s\n"
                % (oldalbumpath, newalbumpath))
            self.fs.MoveDirectory(oldalbumpath, newalbumpath)

        # rename artist
        oldartistpath = self.fs.GetDirectory(oldalbumpath)
        newartistpath = data["artistname"]
        if oldartistpath != newartistpath:
            self.cli.PrintText(
                "\033[1;34mRename Artist: \033[0;31m%s\033[1;34m -> \033[0;32m%s\n"
                % (oldartistpath, newartistpath))
            self.fs.MoveDirectory(oldartistpath, newartistpath)

        # import
        artist = self.db.GetArtistByPath(newartistpath)
        if not artist:
            self.cli.PrintText("\033[1;34mAdd new artist \033[0;36m%s\n" %
                               (newartistpath))
            self.db.AddArtist(newartistpath, newartistpath)
            artist = self.db.GetArtistByPath(newartistpath)

        if not artist:
            self.cli.PrintText(
                "\033[1;31mAdding artist failed! \033[1;30m(Retry the import workflow and check the names of the files in the file system)\033[0m"
            )
            return
        else:
            self.cli.PrintText("\033[1;34mImport album \033[0;36m%s\n" %
                               (newalbumpath))
            try:
                self.AddAlbum(newalbumpath, artist["id"])
            except Exception as e:
                self.cli.PrintText(
                    "\033[1;31mImporting album failed with exception %s!\033[1;30m (Nothing bad happened, just try to solve the issue and repeat. Were all Paths and file names valid?)\n"
                    % (str(e)))

        # set origin
        album = self.db.GetAlbumByPath(newalbumpath)
        if not album:
            self.cli.PrintText(
                "\033[1;31mImporting album failed! \033[1;30m(Retry the import workflow and check the names of the files in the file system)\033[0m"
            )
            return
        elif album["origin"] != data["origin"]:
            self.cli.PrintText("\033[1;34mSet Origin \033[0;36m%s\n" %
                               (data["origin"]))
            album["origin"] = data["origin"]
            self.db.WriteAlbum(album)
        self.cli.PrintText("\033[1;32mImporting album succeeded!\n")

        # process
        if data["runartwork"]:
            self.cli.PrintText("\033[1;37mRun Artwork Import\n")
            artwork = MusicDBArtwork(self.cfg, self.db)
            artwork.UpdateAlbumArtwork(album)

        if data["runlyrics"]:
            self.cli.PrintText("\033[1;37mRun Lyrics Import\n")
            metadata = MetaTags(self.cfg.music.path)

            for songtuple in data["songs"]:
                songpath = songtuple[1]
                song = self.db.GetSongByPath(songpath)
                if not song:
                    continue
                songid = song["id"]

                metadata.Load(songpath)
                lyrics = metadata.GetLyrics()
                if lyrics:
                    self.db.SetLyrics(songid, lyrics,
                                      SONG_LYRICSSTATE_FROMFILE)