def metadataToPara(self, SongPath):
     # print(SongPath)
     metadataDict = ManageMetaData.ReadMetaData(self, SongPath)
     text = ""
     for item in metadataDict:
         text = text + metadataDict.get(item, " ") + " "
     # print(text)
     return text
Beispiel #2
0
 def populateEditMetadataDialog(self):
     print("populate Edit MetadataDialog")
     currentPlayingSongPath = self.mediaPlayer.currentMedia().canonicalUrl(
     ).toString()
     currentPlayingSongPath = currentPlayingSongPath[8:]
     # get path of selected song in playlist view, and if that song is
     # currently being played don't let user edit metadata of it
     model = self.playlistView.model()
     indexes = self.playlistView.selectionModel().selectedRows()
     pathIndex = ""
     row = None
     for index in sorted(indexes):
         # print('Row %d is selected' % index.row())
         row = index.row()
         pathIndex = model.index(row, 1)
     # print(row)
     if row is None:
         self.buildMessageBox("Select a Song to edit metadata")
     else:
         # print(pathIndex)
         self.metadataDialog.songPath = model.data(pathIndex)
         # print("current songpath in populateEditMetadataDialog")
         # print(self.metadataDialog.songPath)
         if self.metadataDialog.songPath == currentPlayingSongPath:
             # print("don't let user edit metadata")
             self.buildMessageBox(
                 "you can't edit metadata of currently playing song")
             return False
         else:
             metadata = ManageMetaData.ReadMetaData(
                 self, self.metadataDialog.songPath)
             self.metadataDialog.metadataDict["TPE1"] = metadata.get("TPE1")
             self.metadataDialog.metadataDict["TPE2"] = metadata.get("TPE2")
             self.metadataDialog.metadataDict["TALB"] = metadata.get("TALB")
             self.metadataDialog.metadataDict["TSOP"] = metadata.get("TSOP")
             self.metadataDialog.metadataDict["USLT"] = metadata.get("USLT")
             self.metadataDialog.metadataDict["TDRC"] = metadata.get("TDRC")
             self.metadataDialog.metadataDict["TDOR"] = metadata.get("TDOR")
             self.metadataDialog.metadataDict["TPUB"] = metadata.get("TPUB")
             self.metadataDialog.metadataDict["TIT2"] = metadata.get("TIT2")
             self.metadataDialog.metadataDict["TCON"] = metadata.get("TCON")
             # print("printing inside populatEditMetadataDialog")
             # print(self.metadataDialog.metadataDict)
             self.metadataDialog.ui.titleLineEdit.setText(
                 metadata.get("TIT2"))
             self.metadataDialog.ui.artistLineEdit.setText(
                 metadata.get("TPE1"))
             self.metadataDialog.ui.albumLineEdit.setText(
                 metadata.get("TALB"))
             self.metadataDialog.ui.albumArtistLineEdit.setText(
                 metadata.get("TPE2"))
             self.metadataDialog.ui.genreLineEdit.setText(
                 metadata.get("TCON"))
             self.metadataDialog.ui.yearLineEdit.setText(
                 metadata.get("TDRC"))
             # publisher, lyrics is skipped,fix it in metadata module
             return True
 def fetchRelevantSongOffline(self, SongPath):
     # print("in fetchRelevantSongOffline")
     metadataDict = {}
     year = ""
     # list of path of all the relevant songs
     relevantSongPathList = []
     # dict that contains metadata of songs in paragraph as value and songPath as key
     relevantSongDict = {}
     # print("test")
     # print(SongPath)
     metadataDict = ManageMetaData.ReadMetaData(self, SongPath)
     # print(metadataDict)
     # get year out of metadata TDRC tag
     if metadataDict.get("TDRC"):
         match = re.match(r'\d{4}', metadataDict.get("TDRC"))
         if match is not None:
             # it found a match!
             year = match.group(0)
     # print(year)
     TPE1 = metadataDict.get("TPE1")
     # print(metadataDict.get("TPE1"))
     # print(self.mls)
     # print(self.mls.db.databaseName())
     query = QSqlQuery(self.mls.db)
     queryString = "SELECT SPath FROM songs WHERE TPE1 = :TPE1 OR year = :year"
     if self.mls.db.open():
         # print("db is open")
         query.prepare(queryString)
         query.bindValue(":TPE1", TPE1)
         query.bindValue(":year", year)
         # print("executing queryString")
         record = query.exec_()
         # print(record)
         if record:
             # print("read successful, it seems")
             while query.next():
                 relevantSongPathList.append(query.value(0))
         else:
             print("read not successful")
             # print("error")
             # print(query.lastError().text())
             return False
     else:
         print("could not read from the database, connection not found")
         return False
     # build relevantSongDict
     for path in relevantSongPathList:
         # print(path)
         relevantSongDict[path] = self.metadataToPara(path)
     # predict
     # if SongPath:
     #     self.predict(SongPath, relevantSongDict)
     # else:
     #     print("problem with SongPath so can't call predict")
     return relevantSongDict
    def write(self, SongPath):
        # print(SongPath)
        if self.db.isOpen():
            # print("trying to write in DB")
            metadataDict = {}
            year = ""
            metadataDict = ManageMetaData.ReadMetaData(self, SongPath)
            # get year out of metadata's TDRC tag
            if metadataDict.get("TDRC"):
                match = re.match(r'\d{4}', metadataDict.get("TDRC"))
                if match is not None:
                    # Then it found a match!
                    year = match.group(0)
            # print(year)
            """
            songDict come in undefined order always,we make a ordered list out of it.
            so we can iterate and insert it in db as it in db schema
            order of elements in db table/schema
            SID, SPath, isUpdated, TIT2, TALB, TPE1, TPE2, TSOP, TDRC, TCON, year
            """
            self.query.prepare(
                "insert into songs(SPath, isUpdated, TIT2, TALB, TPE1, TPE2, TSOP, TDRC, TCON, year ) values(:SPath, :isUpdated, :TIT2, :TALB, :TPE1, :TPE2, :TSOP, :TDRC, :TCON, :year)"
            )
            # SPath, isUpdated, TIT2, TALB, TPE1, TPE2, TSOP, TDRC, TCON, these are required, SID is auto incrimented
            self.query.bindValue(":SPath", SongPath)
            self.query.bindValue(":isUpdated", 0)
            self.query.bindValue(":TIT2", metadataDict.get("TIT2", "NULL"))
            self.query.bindValue(":TALB", metadataDict.get("TALB", "NULL"))
            self.query.bindValue(":TPE1", metadataDict.get("TPE1", "NULL"))
            self.query.bindValue(":TPE2", metadataDict.get("TPE2", "NULL"))
            self.query.bindValue(":TSOP", metadataDict.get("TSOP", "NULL"))
            self.query.bindValue(":TDRC", metadataDict.get("TDRC", "NULL"))
            self.query.bindValue(":TCON", metadataDict.get("TCON", "NULL"))
            self.query.bindValue(":year", year)
            isQuerySuccessful = self.query.exec_()

            if isQuerySuccessful:
                print("insertion successful")
                # print("no of rows affected: " + str(self.query.numRowsAffected()))
            elif self.query.lastError().number() is 19:
                pass
                # print("unique Construct failed")
                # print(self.query.lastError().number().text())
            else:
                print("insertion not successful")
                # print("error:")
                print(self.query.lastError().number())
                return False
        else:
            print("connection could not be established")
            return False
        return True
Beispiel #5
0
 def writeCache(self, recommendedSongsPathList, SPath):
     # recommendedSongsPathList is a list that contains path of all recommended Songs Path
     isQuerySuccessful = None
     if self.db.isOpen():
         # print("trying to write in DB")
         for item in recommendedSongsPathList:
             metadataDict = ManageMetaData.ReadMetaData(self, item)
             self.query.prepare(
                 "insert into cache(SPath, SPathRec, Title, Artist) values(:SPath, :SPathRec, :Title, :Artist)"
             )
             self.query.bindValue(":SPath", SPath)
             self.query.bindValue(":SPathRec", item)
             self.query.bindValue(":Title",
                                  metadataDict.get("TIT2", "NULL"))
             self.query.bindValue(":Artist",
                                  metadataDict.get("TPE1", "NULL"))
             isQuerySuccessful = self.query.exec_()
         if isQuerySuccessful:
             print("insertion successful")
             # print("no of rows affected: " + str(self.query.numRowsAffected()))
         elif self.query.lastError().number() is 19:
             pass
             # print("unique Construct failed")
             # print(self.query.lastError().number().text())
         else:
             self.buildMessageBox(
                 "Not Enough Data to recommend songs for this song, please update metadata or add more songs to collection"
             )
             print("insertion not successful")
             # print("error:")
             print(self.query.lastError().number())
             return False
     else:
         print("connection could not be established")
         return False
     return True
# D:\\Songs(english)\\naked\\13 Hey There Delilah.mp3
# All Of Me - John Legend.mp3

# For manually testing ManageMetadata module.

from Metadata.ManageMetaDataModule import ManageMetaData

print ("starting test...")
obj=ManageMetaData()
print(obj.titleTIT2)
a=obj.ReadMetaData("D:\\Songs(english)\\naked\\All Of Me - John Legend.mp3")
print(obj.titleTIT2)
print ("printing metadata read:\n")
print(a)
print ("read metadata done")
obj.WriteMetaData(a,"D:/Songs(english)/Imagine Dragons/Imagine dragons-demons.mp3")
print ("write metadata done")

print("lets now see if it has worked!!!\n")
a=obj.ReadMetaData("D:/Songs(english)/Imagine Dragons/Imagine dragons-demons.mp3")
print ("printing metadata read:\n")
print(a)