def writeContents(self): self.changedValueNumber = 0 changedArtistValues = [] uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if self.isRowHidden(rowNo) is False: if self.isChangeableItem(rowNo, "correctedArtist", str(self.values[rowNo]["currentArtist"])): changedArtistValues.append({}) changedArtistValues[-1]["id"] = str(self.values[rowNo]["id"]) value = str(self.item(rowNo, 1).text()) changedArtistValues[-1]["name"] = value Records.add(str(translate("AmarokArtistTable", "Artist")), str(self.values[rowNo]["currentArtist"]), value) self.changedValueNumber += 1 except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() Operations.changeArtistValues(changedArtistValues) return True
def save(self): try: Records.setTitle(translate("AmarokArtistDetails", "Amarok - Artist")) Operations.changeArtistValues( [{"id": self.artistId, "name": str(self.infoValues["correctedArtist"].text())}]) if self.artistName != str(self.infoValues["correctedArtist"].text()): self.changeArtist(Commands.getArtistId(str(self.infoValues["correctedArtist"].text()))) if hasattr(getMainWindow(),"FileManager") and getMainWindow().FileManager is not None: getMainWindow().FileManager.makeRefresh() Records.saveAllRecords() except: ReportBug.ReportBug()
def getFromAmarok(self): try: import Amarok Dialogs.showState(translate("CoverTable", "Checking For Amarok..."), 0, 1) if Amarok.checkAmarok(): from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues() Dialogs.showState(translate("CoverTable", "Values Are Being Processed"), 1, 1) if directoriesAndValues is not None: for rowNo in range(self.rowCount()): if (getMainWindow().checkHiddenColumn("sourceCover") and getMainWindow().checkHiddenColumn("destinationCover")): if self.isChangeableItem(rowNo, "sourceCover"): directoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), str(self.item(rowNo, 0).text()), str(self.item(rowNo, 1).text())) if directoryPath in directoriesAndValues: directoryAndValues = directoriesAndValues[directoryPath] self.item(rowNo, 3).setText( directoryAndValues["coverPath"][0].replace(directoryPath, ".")) self.item(rowNo, 4).setText("./" + Organizer.getIconName( directoryAndValues["artist"][0], directoryAndValues["album"][0], directoryAndValues["genre"][0], directoryAndValues["year"][0])) except: ReportBug.ReportBug()
def refreshTable(self, _path): self.values = [] uni.startThreadAction() Dialogs.showState(translate("AmarokArtistTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: artistValues = Operations.getAllArtistsValues(uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState(translate("AmarokArtistTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if artistValues is not None: allItemNumber = len(artistValues) self.setRowCount(allItemNumber) rowNo = 0 for musicFileRow in artistValues: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: content = {} content["id"] = musicFileRow["id"] content["currentArtist"] = musicFileRow["name"] content["correctedArtist"] = musicFileRow["name"] self.values.append(content) currentName = content["currentArtist"] self.createItem(rowNo, "currentArtist", currentName, currentName, True) newName = Organizer.emend(content["correctedArtist"]) isReadOnlyNewName = (content["correctedArtist"].strip() == "") self.createItem(rowNo, "correctedArtist", newName, content["currentArtist"], isReadOnlyNewName) rowNo += 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def getFromAmarok(self): try: import Amarok Dialogs.showState( translate("CoverTable", "Checking For Amarok..."), 0, 1) if Amarok.checkAmarok(): from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues() Dialogs.showState( translate("CoverTable", "Values Are Being Processed"), 1, 1) if directoriesAndValues is not None: for rowNo in range(self.rowCount()): if (getMainWindow().checkHiddenColumn("sourceCover") and getMainWindow().checkHiddenColumn( "destinationCover")): if self.isChangeableItem(rowNo, "sourceCover"): directoryPath = fu.joinPath( fu.getDirName( fu.getDirName( self.values[rowNo]["path"])), str(self.item(rowNo, 0).text()), str(self.item(rowNo, 1).text())) if directoryPath in directoriesAndValues: directoryAndValues = directoriesAndValues[ directoryPath] self.item(rowNo, 3).setText( directoryAndValues["coverPath"] [0].replace(directoryPath, ".")) self.item(rowNo, 4).setText( "./" + Organizer.getIconName( directoryAndValues["artist"][0], directoryAndValues["album"][0], directoryAndValues["genre"][0], directoryAndValues["year"][0])) except: ReportBug.ReportBug()
def refreshTable(self, _path): self.values = [] uni.startThreadAction() import Amarok Dialogs.showState(translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues(uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState(translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if directoriesAndValues is not None: allItemNumber = len(directoriesAndValues) self.setRowCount(allItemNumber) rowNo = 0 for dirPath, dirRow in directoriesAndValues.items(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isReadableFileOrDir(dirPath, False, True) and fu.isReadableFileOrDir( fu.joinPath(dirPath, ".directory"), False, True): content = {} content["path"] = dirPath content["pathOfParentDirectory"] = fu.getDirName(dirPath) content["baseName"] = fu.getBaseName(dirPath) currentCover, isCorrectedFileContent = fu.getIconFromDirectory(dirPath) if currentCover is None: currentCover = "" content["currentCover"] = (currentCover) content["sourceCover"] = (dirRow["coverPath"][0].replace(dirPath, ".")) content["destinationCover"] = ("./" + Organizer.getIconName( dirRow["artist"][0], dirRow["album"][0], dirRow["genre"][0], dirRow["year"][0])) content["flagColor"] = {} if isCorrectedFileContent is False: content["flagColor"]["currentCover"] = 255, 163, 163 if fu.isFile(content["sourceCover"]) is False: content["flagColor"]["sourceCover"] = 255, 163, 163 self.values.append(content) newPathOfParentDirectory = Organizer.emend( self.values[rowNo]["pathOfParentDirectory"], "directory") self.createItem(rowNo, "pathOfParentDirectory", newPathOfParentDirectory, self.values[rowNo]["pathOfParentDirectory"]) newBaseName = Organizer.emend(self.values[rowNo]["baseName"], "directory") self.createItem(rowNo, "pathOfParentDirectory", newBaseName, self.values[rowNo]["baseName"]) newCurrentCover = fu.getShortPath(self.values[rowNo]["currentCover"], self.values[rowNo]["path"]) itemCurrentCover = self.createItem(rowNo, "currentCover", newCurrentCover, newCurrentCover, True) self.setItemColor(itemCurrentCover, rowNo, 2, "currentCover") newSourceCover = fu.getShortPath(self.values[rowNo]["sourceCover"], self.values[rowNo]["path"]) itemSourceCover = self.createItem(rowNo, "sourceCover", newSourceCover, fu.getShortPath( self.values[rowNo]["currentCover"], self.values[rowNo]["path"])) self.setItemColor(itemSourceCover, rowNo, 3, "sourceCover") newDestinationCover = Organizer.emend( fu.getShortPath(self.values[rowNo]["destinationCover"], self.values[rowNo]["path"]), "file") itemDestinationCover = self.createItem(rowNo, "destinationCover", newDestinationCover, fu.getShortPath( self.values[rowNo]["currentCover"], self.values[rowNo]["path"])) self.setItemColor(itemDestinationCover, rowNo, 4, "destinationCover") rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] startRowNo, rowStep = 0, 1 uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True) for rowNo in range(startRowNo, self.rowCount(), rowStep): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: pathOfParentDirectory = str( self.values[rowNo]["pathOfParentDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if self.isChangeableItem(rowNo, "sourceCover") or self.isChangeableItem(rowNo, "destinationCover"): sourcePath = self.values[rowNo]["sourceCover"] destinationPath = self.values[rowNo]["destinationCover"] if self.isChangeableItem(rowNo, "sourceCover"): sourcePath = str(self.item(rowNo, 3).text()).strip() if self.isChangeableItem(rowNo, "destinationCover"): destinationPath = str(self.item(rowNo, 4).text()).strip() if (str(self.item(rowNo, 2).text()) != sourcePath or sourcePath != destinationPath or str( self.item(rowNo, 2).text()) != destinationPath) or ( str(self.item(rowNo, 2).text()) != self.values[rowNo]["currentCover"] and ( str(self.item(rowNo, 2).text()) != sourcePath and str( self.item(rowNo, 2).text()) != destinationPath)): if str(self.item(rowNo, 3).text()).strip() != "": sourcePath = fu.getRealPath(sourcePath, self.values[rowNo]["path"]) sourcePath = fu.checkSource(sourcePath, "file") if sourcePath is not None: if destinationPath != "": destinationPath = fu.getRealPath(destinationPath, self.values[ rowNo]["path"]) if sourcePath != destinationPath: destinationPath = fu.moveOrChange(sourcePath, destinationPath) else: destinationPath = sourcePath fu.setIconToDirectory(self.values[rowNo]["path"], destinationPath) self.changedValueNumber += 1 else: fu.setIconToDirectory(self.values[rowNo]["path"], "") self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseNameOfDirectory", pathOfParentDirectory): pathOfParentDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath(pathOfParentDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "directory") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if len(oldAndNewPathValues) > 0: from Amarok import Operations Operations.changePaths(oldAndNewPathValues) return True
def refreshTable(self, _path): self.values = [] self.setColumnWidth(6, 70) self.setColumnWidth(7, 40) uni.startThreadAction() import Amarok Dialogs.showState(translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileValuesWithNames = Operations.getAllMusicFileValuesWithNames( uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState(translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if musicFileValuesWithNames is not None: allItemNumber = len(musicFileValuesWithNames) self.setRowCount(allItemNumber) rowNo = 0 for musicFileRow in musicFileValuesWithNames: isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if (fu.isFile(musicFileRow["filePath"]) and fu.isReadableFileOrDir(musicFileRow["filePath"], False, True)): details = fu.getDetails(musicFileRow["filePath"]) content = {} if Amarok.getSelectedTagSourseType("AmarokCopyTable") == "Amarok (Smart)": content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow["filePath"])) content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: if tagger.isSupportInfo: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: if content["artist"].strip() == "": content["artist"] = tagger.getArtist() if content["title"].strip() == "": content["title"] = tagger.getTitle() if content["album"].strip() == "": content["album"] = tagger.getAlbum() if content["albumArtist"].strip() == "": content["albumArtist"] = tagger.getAlbumArtist() if str(content["trackNum"]).strip() == "": content["trackNum"] = tagger.getTrackNum() if str(content["year"]).strip() == "": content["year"] = tagger.getYear() if content["genre"].strip() == "": content["genre"] = tagger.getGenre() if content["firstComment"].strip() == "": content["firstComment"] = tagger.getFirstComment() if content["firstLyrics"].strip() == "": content["firstLyrics"] = tagger.getFirstLyrics() if tagger.isSupportInfo: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() elif Amarok.getSelectedTagSourseType("AmarokCopyTable") == "Only Amarok": content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = "" content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] tagger = Taggers.getTagger() if tagger.isSupportInfo: try: tagger.loadFile(musicFileRow["filePath"]) except: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() else: tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: Dialogs.showError(translate("FileUtils/Musics", "Incorrect Tag"), str(translate("FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags.") ) % Organizer.getLink(musicFileRow["filePath"])) content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = "" content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = tagger.getArtist() content["title"] = tagger.getTitle() content["album"] = tagger.getAlbum() content["albumArtist"] = tagger.getAlbumArtist() content["trackNum"] = tagger.getTrackNum() content["year"] = tagger.getYear() content["genre"] = tagger.getGenre() content["firstComment"] = tagger.getFirstComment() content["firstLyrics"] = tagger.getFirstLyrics() if tagger.isSupportInfo: content["length"] = tagger.getLength() content["bitrate"] = tagger.getBitrate() content["sampleRate"] = tagger.getSampleRate() content["mode"] = tagger.getMode() content["size"] = details[stat.ST_SIZE] content["lastAccessed"] = details[stat.ST_ATIME] content["lastModified"] = details[stat.ST_MTIME] content["lastMetadataChanged"] = details[stat.ST_CTIME] self.values.append(content) newBaseNameOfDirectory = Organizer.emend( self.values[rowNo]["baseNameOfDirectory"], "directory") self.createItem(rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo]["baseNameOfDirectory"]) newBaseName = Organizer.emend(self.values[rowNo]["baseName"], "file") self.createItem(rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newArtist = Organizer.emend(self.values[rowNo]["artist"]) self.createItem(rowNo, "artist", newArtist, self.values[rowNo]["artist"]) newTitle = Organizer.emend(self.values[rowNo]["title"]) self.createItem(rowNo, "title", newTitle, self.values[rowNo]["title"]) newAlbum = Organizer.emend(self.values[rowNo]["album"]) self.createItem(rowNo, "album", newAlbum, self.values[rowNo]["album"]) newAlbumArtist = Organizer.emend(self.values[rowNo]["albumArtist"]) self.createItem(rowNo, "albumArtist", newAlbumArtist, self.values[rowNo]["albumArtist"]) newTrackNum = str(self.values[rowNo]["trackNum"]) self.createItem(rowNo, "trackNum", newTrackNum, self.values[rowNo]["trackNum"]) newYear = Organizer.emend(self.values[rowNo]["year"]) self.createItem(rowNo, "year", newYear, self.values[rowNo]["year"]) newGenre = Organizer.emend(self.values[rowNo]["genre"]) self.createItem(rowNo, "genre", newGenre, self.values[rowNo]["genre"]) newFirstComment = Organizer.emend(self.values[rowNo]["firstComment"]) self.createItem(rowNo, "firstComment", newFirstComment, self.values[rowNo]["firstComment"]) newFirstLyrics = Organizer.emend(self.values[rowNo]["firstLyrics"]) self.createItem(rowNo, "firstLyrics", newFirstLyrics, self.values[rowNo]["firstLyrics"]) if Taggers.getTagger().isSupportInfo: self.createItem(rowNo, "length", content["length"]) self.createItem(rowNo, "bitrate", content["bitrate"]) self.createItem(rowNo, "sampleRate", content["sampleRate"]) self.createItem(rowNo, "mode", content["mode"]) self.createItem(rowNo, "size", Organizer.getCorrectedFileSize(content["size"])) self.createItem(rowNo, "lastAccessed", Organizer.getCorrectedTime(content["lastAccessed"])) self.createItem(rowNo, "lastModified", Organizer.getCorrectedTime(content["lastModified"])) self.createItem(rowNo, "lastMetadataChanged", Organizer.getCorrectedTime(content["lastMetadataChanged"])) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState(translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len(self.values)) # In case of Non Readable Files and Canceled process
def refreshTable(self, _path): self.values = [] uni.startThreadAction() import Amarok Dialogs.showState( translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations directoriesAndValues = Operations.getDirectoriesAndValues( uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState( translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if directoriesAndValues is not None: allItemNumber = len(directoriesAndValues) self.setRowCount(allItemNumber) rowNo = 0 for dirPath, dirRow in directoriesAndValues.items(): isContinueThreadAction = uni.isContinueThreadAction( ) if isContinueThreadAction: try: if fu.isReadableFileOrDir( dirPath, False, True) and fu.isReadableFileOrDir( fu.joinPath( dirPath, ".directory"), False, True): content = {} content["path"] = dirPath content[ "pathOfParentDirectory"] = fu.getDirName( dirPath) content["baseName"] = fu.getBaseName( dirPath) currentCover, isCorrectedFileContent = fu.getIconFromDirectory( dirPath) if currentCover is None: currentCover = "" content["currentCover"] = ( currentCover) content["sourceCover"] = ( dirRow["coverPath"][0].replace( dirPath, ".")) content["destinationCover"] = ( "./" + Organizer.getIconName( dirRow["artist"][0], dirRow["album"][0], dirRow["genre"][0], dirRow["year"][0])) content["flagColor"] = {} if isCorrectedFileContent is False: content["flagColor"][ "currentCover"] = 255, 163, 163 if fu.isFile(content["sourceCover"] ) is False: content["flagColor"][ "sourceCover"] = 255, 163, 163 self.values.append(content) newPathOfParentDirectory = Organizer.emend( self.values[rowNo] ["pathOfParentDirectory"], "directory") self.createItem( rowNo, "pathOfParentDirectory", newPathOfParentDirectory, self.values[rowNo] ["pathOfParentDirectory"]) newBaseName = Organizer.emend( self.values[rowNo]["baseName"], "directory") self.createItem( rowNo, "pathOfParentDirectory", newBaseName, self.values[rowNo]["baseName"]) newCurrentCover = fu.getShortPath( self.values[rowNo]["currentCover"], self.values[rowNo]["path"]) itemCurrentCover = self.createItem( rowNo, "currentCover", newCurrentCover, newCurrentCover, True) self.setItemColor( itemCurrentCover, rowNo, 2, "currentCover") newSourceCover = fu.getShortPath( self.values[rowNo]["sourceCover"], self.values[rowNo]["path"]) itemSourceCover = self.createItem( rowNo, "sourceCover", newSourceCover, fu.getShortPath( self.values[rowNo] ["currentCover"], self.values[rowNo]["path"])) self.setItemColor( itemSourceCover, rowNo, 3, "sourceCover") newDestinationCover = Organizer.emend( fu.getShortPath( self.values[rowNo] ["destinationCover"], self.values[rowNo]["path"]), "file") itemDestinationCover = self.createItem( rowNo, "destinationCover", newDestinationCover, fu.getShortPath( self.values[rowNo] ["currentCover"], self.values[rowNo]["path"])) self.setItemColor( itemDestinationCover, rowNo, 4, "destinationCover") rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState( translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len( self.values)) # In case of Non Readable Files and Canceled process
def changeFile(self, _filePath, _readFrom="tag"): self.musicFile = _filePath self.musicValues = None self.isPlayNow = MToolButton() self.isPlayNow.setToolTip( translate("MusicDetails", "Play Suddenly Music When Open")) self.isPlayNow.setText(translate("MusicDetails", "Play When Open")) self.isPlayNow.setCheckable(True) self.isPlayNow.setChecked(uni.getBoolValue("isPlayNow")) self.isGetFromAmarok = MToolButton() self.isGetFromAmarok.setToolTip( translate("MusicDetails", "Get Values From Amarok")) self.isGetFromAmarok.setText( translate("MusicDetails", "Get From Amarok")) self.isGetFromAmarok.setCheckable(True) if _readFrom.count("Amarok") > 0: import Amarok uni.startThreadAction() Dialogs.showState( translate("MusicDetails", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileRows = Operations.getAllMusicFileValuesWithNames( "filename:\"" + _filePath + "\"") Dialogs.showState( translate("MusicDetails", "Values Are Being Processed"), 1, 1) if len(musicFileRows) > 0: musicFileRow = musicFileRows[0] content = {} content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow["filePath"])) content["baseName"] = fu.getBaseName( musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] content["images"] = [] if _readFrom == "Amarok (Smart)": tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: pass else: if content["artist"].strip() == "": content["artist"] = tagger.getArtist() if content["title"].strip() == "": content["title"] = tagger.getTitle() if content["album"].strip() == "": content["album"] = tagger.getAlbum() if content["albumArtist"].strip() == "": content[ "albumArtist"] = tagger.getAlbumArtist( ) if str(content["trackNum"]).strip() == "": content["trackNum"] = tagger.getTrackNum() if str(content["year"]).strip() == "": content["year"] = tagger.getYear() if content["genre"].strip() == "": content["genre"] = tagger.getGenre() if content["firstComment"].strip() == "": content[ "firstComment"] = tagger.getFirstComment( ) if content["firstLyrics"].strip() == "": content[ "firstLyrics"] = tagger.getFirstLyrics( ) content["images"] = tagger.getImages() self.isGetFromAmarok.setChecked(True) self.musicValues = content else: Dialogs.show( translate("MusicDetails", "Not Exist In Amarok"), translate( "MusicDetails", "This music file not exist in Amarok DB.")) uni.finishThreadAction() if self.musicValues is None: self.isGetFromAmarok.setChecked(False) self.musicValues = Musics.readMusicFile(self.musicFile) self.setWindowTitle(str(fu.getBaseName(self.musicFile))) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.player = MusicPlayer.MusicPlayer(self, "dialog", _filePath) self.infoLabels["baseNameOfDirectory"] = MLabel(self.labels[0]) self.infoLabels["baseName"] = MLabel(self.labels[1]) self.infoLabels["artist"] = MLabel(self.labels[2]) self.infoLabels["title"] = MLabel(self.labels[3]) self.infoLabels["album"] = MLabel(self.labels[4]) self.infoLabels["albumArtist"] = MLabel(self.labels[5]) self.infoLabels["trackNum"] = MLabel(self.labels[6]) self.infoLabels["year"] = MLabel(self.labels[7]) self.infoLabels["genre"] = MLabel(self.labels[8]) self.infoValues["baseNameOfDirectory"] = MLineEdit( str( Organizer.emend(self.musicValues["baseNameOfDirectory"], "directory", False))) self.infoValues["baseName"] = MLineEdit( str(Organizer.emend(self.musicValues["baseName"], "file"))) self.infoValues["artist"] = MLineEdit( str(Organizer.emend(self.musicValues["artist"]))) self.infoValues["title"] = MLineEdit( str(Organizer.emend(self.musicValues["title"]))) self.infoValues["album"] = MLineEdit( str(Organizer.emend(self.musicValues["album"]))) self.infoValues["albumArtist"] = MLineEdit( str(Organizer.emend(self.musicValues["albumArtist"]))) self.infoValues["trackNum"] = MLineEdit( str(Organizer.emend(self.musicValues["trackNum"]))) self.infoValues["year"] = MLineEdit( str(Organizer.emend(self.musicValues["year"]))) self.infoValues["genre"] = MLineEdit( str(Organizer.emend(self.musicValues["genre"]))) self.infoValues["firstComment"] = MPlainTextEdit( str(Organizer.emend(self.musicValues["firstComment"]))) self.infoValues["firstLyrics"] = MPlainTextEdit( str(Organizer.emend(self.musicValues["firstLyrics"]))) self.infoValues["firstComment"].setLineWrapMode(MPlainTextEdit.NoWrap) self.infoValues["firstLyrics"].setLineWrapMode(MPlainTextEdit.NoWrap) if Taggers.getTagger().isSupportImages: self.isOpenImageDetailsOnNewWindow = MCheckBox( translate("MusicDetails", "Show Images In New Window")) self.pbtnAddImage = MPushButton(translate("MusicDetails", "Append")) self.pbtnDeleteImage = MPushButton( translate("MusicDetails", "Delete")) self.pbtnSaveAsImage = MPushButton( translate("MusicDetails", "Save As ...")) self.pbtnCancelAddImage = MPushButton( translate("MusicDetails", "Cancel")) self.pbtnSelectImage = MPushButton( translate("MusicDetails", "Choose Image")) MObject.connect(self.pbtnAddImage, SIGNAL("clicked()"), self.addImage) MObject.connect(self.pbtnDeleteImage, SIGNAL("clicked()"), self.deleteImage) MObject.connect(self.pbtnSaveAsImage, SIGNAL("clicked()"), self.saveAsImage) MObject.connect(self.pbtnCancelAddImage, SIGNAL("clicked()"), self.cancelAddImage) MObject.connect(self.pbtnSelectImage, SIGNAL("clicked()"), self.selectImage) self.leImagePath = MLineEdit("") self.lblImagePath = MLabel( translate("MusicDetails", "Image Path: ")) self.cbImageType = MComboBox() self.cbImageType.addItems(Taggers.getTagger().getImageTypes()) self.lblImageType = MLabel( translate("MusicDetails", "Image Type: ")) self.lstwImages = MListWidget() self.lstwImages.setGridSize(MSize(350, 100)) self.lstwImages.setIconSize(MSize(98, 98)) MObject.connect(self.lstwImages, SIGNAL("doubleClicked(QModelIndex)"), self.openImageDetails) MObject.connect(self.isGetFromAmarok, SIGNAL("toggled(bool)"), self.isGetFromAmarokTiggered) self.lstwImages.clear() for image in self.musicValues["images"]: if len(image) == 5: pixmImage = MPixmap() pixmImage.loadFromData(image[3]) icnImage = QIcon(pixmImage) icnImage.actualSize(MSize(98, 98)) item = MListWidgetItem(icnImage, image[1] + "\n(" + image[2] + ")") item.setSizeHint(MSize(1, 100)) self.lstwImages.addItem(item) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseNameOfDirectory"]) HBOXs[-1].addWidget(self.infoValues["baseNameOfDirectory"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseName"]) HBOXs[-1].addWidget(self.infoValues["baseName"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["artist"]) HBOXs[-1].addWidget(self.infoValues["artist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["title"]) HBOXs[-1].addWidget(self.infoValues["title"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["album"]) HBOXs[-1].addWidget(self.infoValues["album"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["albumArtist"]) HBOXs[-1].addWidget(self.infoValues["albumArtist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["trackNum"]) HBOXs[-1].addWidget(self.infoValues["trackNum"]) HBOXs[-1].addWidget(self.infoLabels["year"]) HBOXs[-1].addWidget(self.infoValues["year"]) HBOXs[-1].addWidget(self.infoLabels["genre"]) HBOXs[-1].addWidget(self.infoValues["genre"]) vblInfos = MVBoxLayout() for hbox in HBOXs: vblInfos.addLayout(hbox) if Taggers.getTagger().isSupportImages: imageBoxs = [] imageBoxs.append(MHBoxLayout()) imageBoxs[0].addWidget(self.leImagePath) imageBoxs[0].addWidget(self.pbtnSelectImage) imageBoxs.append(MHBoxLayout()) imageBoxs[1].addWidget(self.lblImageType) imageBoxs[1].addWidget(self.cbImageType) imageBoxs.append(MHBoxLayout()) imageBoxs[2].addWidget(self.pbtnAddImage) imageBoxs[2].addWidget(self.pbtnDeleteImage) imageBoxs[2].addWidget(self.pbtnSaveAsImage) imageBoxs[2].addWidget(self.pbtnCancelAddImage) vblImages = MVBoxLayout() vblImages.addWidget(self.lstwImages) vblImages.addWidget(self.isOpenImageDetailsOnNewWindow) vblImages.addWidget(self.lblImagePath) vblImages.addLayout(imageBoxs[0]) vblImages.addLayout(imageBoxs[1]) vblImages.addLayout(imageBoxs[2]) vblComments = MVBoxLayout() vblComments.addWidget(self.infoValues["firstComment"]) vblLyrics = MVBoxLayout() vblLyrics.addWidget(self.infoValues["firstLyrics"]) self.tabwTabs = MTabWidget(self.pnlMain) self.pnlComments = MWidget(self.tabwTabs) self.pnlComments.setLayout(vblComments) self.tabwTabs.addTab(self.pnlComments, translate("MusicDetails", "Comments")) self.pnlLyrics = MWidget(self.tabwTabs) self.pnlLyrics.setLayout(vblLyrics) self.tabwTabs.addTab(self.pnlLyrics, translate("MusicDetails", "Lyrics")) if Taggers.getTagger().isSupportImages: self.pnlImages = MWidget(self.tabwTabs) self.pnlImages.setLayout(vblImages) self.tabwTabs.addTab(self.pnlImages, translate("MusicDetails", "Images")) self.pbtnSelectImage.hide() self.leImagePath.hide() self.lblImagePath.hide() self.lblImageType.hide() self.cbImageType.hide() self.pbtnCancelAddImage.hide() hblPlayer = MHBoxLayout() vblExtraButtons = MVBoxLayout() hblPlayer.addWidget(self.player) vblExtraButtons.addWidget(self.isPlayNow) vblExtraButtons.addWidget(self.isGetFromAmarok) hblPlayer.addLayout(vblExtraButtons) vblClearable.addLayout(hblPlayer) vblClearable.addLayout(vblInfos) vblClearable.addWidget(self.tabwTabs)
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] changingTags = [] uni.startThreadAction() import Amarok allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if self.isRowHidden(rowNo): isWritableFileOrDir = fu.isFile( self.values[rowNo] ["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) if isWritableFileOrDir: fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: changingTag = {"path": self.values[rowNo]["path"]} isWritableFileOrDir = fu.isFile( self.values[rowNo] ["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) isSetTagOfFile = False if isWritableFileOrDir: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if Amarok.getSelectedTagTargetType( "AmarokMusicTable").find("To File") > -1: isSetTagOfFile = True tagger = Taggers.getTagger() tagger.loadFileForWrite( self.values[rowNo]["path"]) if self.isChangeableItem(rowNo, "artist"): value = str(self.item(rowNo, 2).text()) if isSetTagOfFile: tagger.setArtist(value) changingTag["artist"] = value Records.add(str(translate("MusicTable", "Artist")), str(self.values[rowNo]["artist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "title"): value = str(self.item(rowNo, 3).text()) if isSetTagOfFile: tagger.setTitle(value) changingTag["title"] = value Records.add(str(translate("MusicTable", "Title")), str(self.values[rowNo]["title"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "album"): value = str(self.item(rowNo, 4).text()) if isSetTagOfFile: tagger.setAlbum(value) changingTag["album"] = value Records.add(str(translate("MusicTable", "Album")), str(self.values[rowNo]["album"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "albumArtist"): value = str(self.item(rowNo, 5).text()) if isSetTagOfFile: tagger.setAlbumArtist(value) changingTag["albumArtist"] = value Records.add( str(translate("MusicTable", "Album Artist")), str(self.values[rowNo]["albumArtist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "trackNum"): value = str(self.item(rowNo, 6).text()) if isSetTagOfFile: tagger.setTrackNum(value) changingTag["trackNum"] = value Records.add( str(translate("MusicTable", "Track No")), str(self.values[rowNo]["trackNum"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "year"): value = str(self.item(rowNo, 7).text()) if isSetTagOfFile: tagger.setDate(value) changingTag["year"] = value Records.add(str(translate("MusicTable", "Year")), str(self.values[rowNo]["year"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "genre"): value = str(self.item(rowNo, 8).text()) if isSetTagOfFile: tagger.setGenre(value) changingTag["genre"] = value Records.add(str(translate("MusicTable", "Genre")), str(self.values[rowNo]["genre"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstComment"): value = str(self.item(rowNo, 9).text()) if isSetTagOfFile: tagger.setFirstComment(value) changingTag["firstComment"] = value Records.add( str(translate("MusicTable", "Comment")), str(self.values[rowNo]["firstComment"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstLyrics"): value = str(self.item(rowNo, 10).text()) if isSetTagOfFile: tagger.setFirstLyrics(value) changingTag["firstLyrics"] = value Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 if len(changingTag) > 1: changingTags.append(changingTag) if isWritableFileOrDir: if isSetTagOfFile: tagger.update() if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str( self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName( fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath( self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange( oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue( "isClearEmptyDirectoriesWhenFileMove" ): fu.checkEmptyDirectories( oldDirName, True, True, uni.getBoolValue( "isAutoCleanSubFolderWhenFileMove" )) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate("FileUtils/Musics", "Writing Music Tags And Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() from Amarok import Operations if Amarok.getSelectedTagTargetType("AmarokMusicTable").find( "Amarok") > -1: Operations.changeTags(changingTags) if len(oldAndNewPathValues) > 0: Operations.changePaths(oldAndNewPathValues, "file") return True
def refreshTable(self, _path): self.values = [] self.setColumnWidth(6, 70) self.setColumnWidth(7, 40) uni.startThreadAction() import Amarok Dialogs.showState( translate("AmarokMusicTable", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileValuesWithNames = Operations.getAllMusicFileValuesWithNames( uni.MySettings[self.amarokFilterKeyName]) Dialogs.showState( translate("AmarokMusicTable", "Values Are Being Processed"), 1, 1) isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: if musicFileValuesWithNames is not None: allItemNumber = len(musicFileValuesWithNames) self.setRowCount(allItemNumber) rowNo = 0 for musicFileRow in musicFileValuesWithNames: isContinueThreadAction = uni.isContinueThreadAction( ) if isContinueThreadAction: try: if (fu.isFile(musicFileRow["filePath"]) and fu.isReadableFileOrDir( musicFileRow["filePath"], False, True)): details = fu.getDetails( musicFileRow["filePath"]) content = {} if Amarok.getSelectedTagSourseType( "AmarokMusicTable" ) == "Amarok (Smart)": content["path"] = musicFileRow[ "filePath"] content[ "baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow[ "filePath"])) content[ "baseName"] = fu.getBaseName( musicFileRow["filePath"]) content["artist"] = musicFileRow[ "artist"] content["title"] = musicFileRow[ "title"] content["album"] = musicFileRow[ "album"] content[ "albumArtist"] = musicFileRow[ "albumArtist"] content["trackNum"] = musicFileRow[ "trackNumber"] content["year"] = musicFileRow[ "year"] content["genre"] = musicFileRow[ "genre"] content[ "firstComment"] = musicFileRow[ "comment"] content[ "firstLyrics"] = musicFileRow[ "lyrics"] tagger = Taggers.getTagger() try: tagger.loadFile( musicFileRow["filePath"]) except: if tagger.isSupportInfo: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: if content["artist"].strip( ) == "": content[ "artist"] = tagger.getArtist( ) if content["title"].strip( ) == "": content[ "title"] = tagger.getTitle( ) if content["album"].strip( ) == "": content[ "album"] = tagger.getAlbum( ) if content[ "albumArtist"].strip( ) == "": content[ "albumArtist"] = tagger.getAlbumArtist( ) if str(content["trackNum"] ).strip() == "": content[ "trackNum"] = tagger.getTrackNum( ) if str(content["year"]).strip( ) == "": content[ "year"] = tagger.getYear( ) if content["genre"].strip( ) == "": content[ "genre"] = tagger.getGenre( ) if content[ "firstComment"].strip( ) == "": content[ "firstComment"] = tagger.getFirstComment( ) if content[ "firstLyrics"].strip( ) == "": content[ "firstLyrics"] = tagger.getFirstLyrics( ) if tagger.isSupportInfo: content[ "length"] = tagger.getLength( ) content[ "bitrate"] = tagger.getBitrate( ) content[ "sampleRate"] = tagger.getSampleRate( ) content[ "mode"] = tagger.getMode( ) elif Amarok.getSelectedTagSourseType( "AmarokMusicTable" ) == "Only Amarok": content["path"] = musicFileRow[ "filePath"] content[ "baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow[ "filePath"])) content[ "baseName"] = fu.getBaseName( musicFileRow["filePath"]) content["artist"] = musicFileRow[ "artist"] content["title"] = musicFileRow[ "title"] content["album"] = musicFileRow[ "album"] content[ "albumArtist"] = musicFileRow[ "albumArtist"] content["trackNum"] = musicFileRow[ "trackNumber"] content["year"] = musicFileRow[ "year"] content["genre"] = musicFileRow[ "genre"] content[ "firstComment"] = musicFileRow[ "comment"] content[ "firstLyrics"] = musicFileRow[ "lyrics"] tagger = Taggers.getTagger() if tagger.isSupportInfo: try: tagger.loadFile( musicFileRow[ "filePath"]) except: content["length"] = "" content["bitrate"] = "" content["sampleRate"] = "" content["mode"] = "" else: content[ "length"] = tagger.getLength( ) content[ "bitrate"] = tagger.getBitrate( ) content[ "sampleRate"] = tagger.getSampleRate( ) content[ "mode"] = tagger.getMode( ) else: tagger = Taggers.getTagger() try: tagger.loadFile( musicFileRow["filePath"]) except: Dialogs.showError( translate( "FileUtils/Musics", "Incorrect Tag"), str( translate( "FileUtils/Musics", "\"%s\" : this file has the incorrect tag so can't read tags." )) % Organizer.getLink( musicFileRow[ "filePath"])) content["path"] = musicFileRow[ "filePath"] content[ "baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow[ "filePath"])) content[ "baseName"] = fu.getBaseName( musicFileRow["filePath"]) content[ "artist"] = tagger.getArtist() content["title"] = tagger.getTitle( ) content["album"] = tagger.getAlbum( ) content[ "albumArtist"] = tagger.getAlbumArtist( ) content[ "trackNum"] = tagger.getTrackNum( ) content["year"] = tagger.getYear() content["genre"] = tagger.getGenre( ) content[ "firstComment"] = tagger.getFirstComment( ) content[ "firstLyrics"] = tagger.getFirstLyrics( ) if tagger.isSupportInfo: content[ "length"] = tagger.getLength( ) content[ "bitrate"] = tagger.getBitrate( ) content[ "sampleRate"] = tagger.getSampleRate( ) content[ "mode"] = tagger.getMode() content["size"] = details[stat.ST_SIZE] content["lastAccessed"] = details[ stat.ST_ATIME] content["lastModified"] = details[ stat.ST_MTIME] content[ "lastMetadataChanged"] = details[ stat.ST_CTIME] self.values.append(content) newBaseNameOfDirectory = Organizer.emend( self.values[rowNo] ["baseNameOfDirectory"], "directory") self.createItem( rowNo, "baseNameOfDirectory", newBaseNameOfDirectory, self.values[rowNo] ["baseNameOfDirectory"]) newBaseName = Organizer.emend( self.values[rowNo]["baseName"], "file") self.createItem( rowNo, "baseName", newBaseName, self.values[rowNo]["baseName"]) newArtist = Organizer.emend( self.values[rowNo]["artist"]) self.createItem( rowNo, "artist", newArtist, self.values[rowNo]["artist"]) newTitle = Organizer.emend( self.values[rowNo]["title"]) self.createItem( rowNo, "title", newTitle, self.values[rowNo]["title"]) newAlbum = Organizer.emend( self.values[rowNo]["album"]) self.createItem( rowNo, "album", newAlbum, self.values[rowNo]["album"]) newAlbumArtist = Organizer.emend( self.values[rowNo]["albumArtist"]) self.createItem( rowNo, "albumArtist", newAlbumArtist, self.values[rowNo]["albumArtist"]) newTrackNum = str( self.values[rowNo]["trackNum"]) self.createItem( rowNo, "trackNum", newTrackNum, self.values[rowNo]["trackNum"]) newYear = Organizer.emend( self.values[rowNo]["year"]) self.createItem( rowNo, "year", newYear, self.values[rowNo]["year"]) newGenre = Organizer.emend( self.values[rowNo]["genre"]) self.createItem( rowNo, "genre", newGenre, self.values[rowNo]["genre"]) newFirstComment = Organizer.emend( self.values[rowNo]["firstComment"]) self.createItem( rowNo, "firstComment", newFirstComment, self.values[rowNo]["firstComment"]) newFirstLyrics = Organizer.emend( self.values[rowNo]["firstLyrics"]) self.createItem( rowNo, "firstLyrics", newFirstLyrics, self.values[rowNo]["firstLyrics"]) if Taggers.getTagger().isSupportInfo: self.createItem( rowNo, "length", content["length"]) self.createItem( rowNo, "bitrate", content["bitrate"]) self.createItem( rowNo, "sampleRate", content["sampleRate"]) self.createItem( rowNo, "mode", content["mode"]) self.createItem( rowNo, "size", Organizer.getCorrectedFileSize( content["size"])) self.createItem( rowNo, "lastAccessed", Organizer.getCorrectedTime( content["lastAccessed"])) self.createItem( rowNo, "lastModified", Organizer.getCorrectedTime( content["lastModified"])) self.createItem( rowNo, "lastMetadataChanged", Organizer.getCorrectedTime( content["lastMetadataChanged"]) ) rowNo += 1 else: allItemNumber -= 1 except: ReportBug.ReportBug() allItemNumber -= 1 else: allItemNumber = rowNo Dialogs.showState( translate("Tables", "Generating Table..."), rowNo, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() self.setRowCount(len( self.values)) # In case of Non Readable Files and Canceled process
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] changingTags = [] uni.startThreadAction() import Amarok allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if self.isRowHidden(rowNo): isWritableFileOrDir = fu.isFile( self.values[rowNo]["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) if isWritableFileOrDir: fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: changingTag = {"path": self.values[rowNo]["path"]} isWritableFileOrDir = fu.isFile( self.values[rowNo]["path"]) and fu.isWritableFileOrDir( self.values[rowNo]["path"], False, True) isSetTagOfFile = False if isWritableFileOrDir: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if Amarok.getSelectedTagTargetType("AmarokMusicTable").find("To File") > -1: isSetTagOfFile = True tagger = Taggers.getTagger() tagger.loadFileForWrite(self.values[rowNo]["path"]) if self.isChangeableItem(rowNo, "artist"): value = str(self.item(rowNo, 2).text()) if isSetTagOfFile: tagger.setArtist(value) changingTag["artist"] = value Records.add(str(translate("MusicTable", "Artist")), str(self.values[rowNo]["artist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "title"): value = str(self.item(rowNo, 3).text()) if isSetTagOfFile: tagger.setTitle(value) changingTag["title"] = value Records.add(str(translate("MusicTable", "Title")), str(self.values[rowNo]["title"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "album"): value = str(self.item(rowNo, 4).text()) if isSetTagOfFile: tagger.setAlbum(value) changingTag["album"] = value Records.add(str(translate("MusicTable", "Album")), str(self.values[rowNo]["album"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "albumArtist"): value = str(self.item(rowNo, 5).text()) if isSetTagOfFile: tagger.setAlbumArtist(value) changingTag["albumArtist"] = value Records.add(str(translate("MusicTable", "Album Artist")), str(self.values[rowNo]["albumArtist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "trackNum"): value = str(self.item(rowNo, 6).text()) if isSetTagOfFile: tagger.setTrackNum(value) changingTag["trackNum"] = value Records.add(str(translate("MusicTable", "Track No")), str(self.values[rowNo]["trackNum"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "year"): value = str(self.item(rowNo, 7).text()) if isSetTagOfFile: tagger.setDate(value) changingTag["year"] = value Records.add(str(translate("MusicTable", "Year")), str(self.values[rowNo]["year"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "genre"): value = str(self.item(rowNo, 8).text()) if isSetTagOfFile: tagger.setGenre(value) changingTag["genre"] = value Records.add(str(translate("MusicTable", "Genre")), str(self.values[rowNo]["genre"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstComment"): value = str(self.item(rowNo, 9).text()) if isSetTagOfFile: tagger.setFirstComment(value) changingTag["firstComment"] = value Records.add(str(translate("MusicTable", "Comment")), str(self.values[rowNo]["firstComment"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstLyrics"): value = str(self.item(rowNo, 10).text()) if isSetTagOfFile: tagger.setFirstLyrics(value) changingTag["firstLyrics"] = value Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 if len(changingTag) > 1: changingTags.append(changingTag) if isWritableFileOrDir: if isSetTagOfFile: tagger.update() if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags And Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() from Amarok import Operations if Amarok.getSelectedTagTargetType("AmarokMusicTable").find("Amarok") > -1: Operations.changeTags(changingTags) if len(oldAndNewPathValues) > 0: Operations.changePaths(oldAndNewPathValues, "file") return True
def changeFile(self, _filePath, _readFrom="tag"): self.musicFile = _filePath self.musicValues = None self.isPlayNow = MToolButton() self.isPlayNow.setToolTip(translate("MusicDetails", "Play Suddenly Music When Open")) self.isPlayNow.setText(translate("MusicDetails", "Play When Open")) self.isPlayNow.setCheckable(True) self.isPlayNow.setChecked(uni.getBoolValue("isPlayNow")) self.isGetFromAmarok = MToolButton() self.isGetFromAmarok.setToolTip(translate("MusicDetails", "Get Values From Amarok")) self.isGetFromAmarok.setText(translate("MusicDetails", "Get From Amarok")) self.isGetFromAmarok.setCheckable(True) if _readFrom.count("Amarok") > 0: import Amarok uni.startThreadAction() Dialogs.showState(translate("MusicDetails", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: from Amarok import Operations musicFileRows = Operations.getAllMusicFileValuesWithNames("filename:\"" + _filePath + "\"") Dialogs.showState(translate("MusicDetails", "Values Are Being Processed"), 1, 1) if len(musicFileRows)>0: musicFileRow = musicFileRows[0] content = {} content["path"] = musicFileRow["filePath"] content["baseNameOfDirectory"] = fu.getBaseName( fu.getDirName(musicFileRow["filePath"])) content["baseName"] = fu.getBaseName(musicFileRow["filePath"]) content["artist"] = musicFileRow["artist"] content["title"] = musicFileRow["title"] content["album"] = musicFileRow["album"] content["albumArtist"] = musicFileRow["albumArtist"] content["trackNum"] = musicFileRow["trackNumber"] content["year"] = musicFileRow["year"] content["genre"] = musicFileRow["genre"] content["firstComment"] = musicFileRow["comment"] content["firstLyrics"] = musicFileRow["lyrics"] content["images"] = [] if _readFrom == "Amarok (Smart)": tagger = Taggers.getTagger() try: tagger.loadFile(musicFileRow["filePath"]) except: pass else: if content["artist"].strip() == "": content["artist"] = tagger.getArtist() if content["title"].strip() == "": content["title"] = tagger.getTitle() if content["album"].strip() == "": content["album"] = tagger.getAlbum() if content["albumArtist"].strip() == "": content["albumArtist"] = tagger.getAlbumArtist() if str(content["trackNum"]).strip() == "": content["trackNum"] = tagger.getTrackNum() if str(content["year"]).strip() == "": content["year"] = tagger.getYear() if content["genre"].strip() == "": content["genre"] = tagger.getGenre() if content["firstComment"].strip() == "": content["firstComment"] = tagger.getFirstComment() if content["firstLyrics"].strip() == "": content["firstLyrics"] = tagger.getFirstLyrics() content["images"] = tagger.getImages() self.isGetFromAmarok.setChecked(True) self.musicValues = content else: Dialogs.show(translate("MusicDetails", "Not Exist In Amarok"), translate("MusicDetails", "This music file not exist in Amarok DB.")) uni.finishThreadAction() if self.musicValues is None: self.isGetFromAmarok.setChecked(False) self.musicValues = Musics.readMusicFile(self.musicFile) self.setWindowTitle(str(fu.getBaseName(self.musicFile))) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.player = MusicPlayer.MusicPlayer(self, "dialog", _filePath) self.infoLabels["baseNameOfDirectory"] = MLabel(self.labels[0]) self.infoLabels["baseName"] = MLabel(self.labels[1]) self.infoLabels["artist"] = MLabel(self.labels[2]) self.infoLabels["title"] = MLabel(self.labels[3]) self.infoLabels["album"] = MLabel(self.labels[4]) self.infoLabels["albumArtist"] = MLabel(self.labels[5]) self.infoLabels["trackNum"] = MLabel(self.labels[6]) self.infoLabels["year"] = MLabel(self.labels[7]) self.infoLabels["genre"] = MLabel(self.labels[8]) self.infoValues["baseNameOfDirectory"] = MLineEdit( str(Organizer.emend(self.musicValues["baseNameOfDirectory"], "directory", False))) self.infoValues["baseName"] = MLineEdit(str(Organizer.emend(self.musicValues["baseName"], "file"))) self.infoValues["artist"] = MLineEdit(str(Organizer.emend(self.musicValues["artist"]))) self.infoValues["title"] = MLineEdit(str(Organizer.emend(self.musicValues["title"]))) self.infoValues["album"] = MLineEdit(str(Organizer.emend(self.musicValues["album"]))) self.infoValues["albumArtist"] = MLineEdit(str(Organizer.emend(self.musicValues["albumArtist"]))) self.infoValues["trackNum"] = MLineEdit(str(Organizer.emend(self.musicValues["trackNum"]))) self.infoValues["year"] = MLineEdit(str(Organizer.emend(self.musicValues["year"]))) self.infoValues["genre"] = MLineEdit(str(Organizer.emend(self.musicValues["genre"]))) self.infoValues["firstComment"] = MPlainTextEdit(str(Organizer.emend(self.musicValues["firstComment"]))) self.infoValues["firstLyrics"] = MPlainTextEdit(str(Organizer.emend(self.musicValues["firstLyrics"]))) self.infoValues["firstComment"].setLineWrapMode(MPlainTextEdit.NoWrap) self.infoValues["firstLyrics"].setLineWrapMode(MPlainTextEdit.NoWrap) if Taggers.getTagger().isSupportImages: self.isOpenImageDetailsOnNewWindow = MCheckBox(translate("MusicDetails", "Show Images In New Window")) self.pbtnAddImage = MPushButton(translate("MusicDetails", "Append")) self.pbtnDeleteImage = MPushButton(translate("MusicDetails", "Delete")) self.pbtnSaveAsImage = MPushButton(translate("MusicDetails", "Save As ...")) self.pbtnCancelAddImage = MPushButton(translate("MusicDetails", "Cancel")) self.pbtnSelectImage = MPushButton(translate("MusicDetails", "Choose Image")) MObject.connect(self.pbtnAddImage, SIGNAL("clicked()"), self.addImage) MObject.connect(self.pbtnDeleteImage, SIGNAL("clicked()"), self.deleteImage) MObject.connect(self.pbtnSaveAsImage, SIGNAL("clicked()"), self.saveAsImage) MObject.connect(self.pbtnCancelAddImage, SIGNAL("clicked()"), self.cancelAddImage) MObject.connect(self.pbtnSelectImage, SIGNAL("clicked()"), self.selectImage) self.leImagePath = MLineEdit("") self.lblImagePath = MLabel(translate("MusicDetails", "Image Path: ")) self.cbImageType = MComboBox() self.cbImageType.addItems(Taggers.getTagger().getImageTypes()) self.lblImageType = MLabel(translate("MusicDetails", "Image Type: ")) self.lstwImages = MListWidget() self.lstwImages.setGridSize(MSize(350, 100)) self.lstwImages.setIconSize(MSize(98, 98)) MObject.connect(self.lstwImages, SIGNAL("doubleClicked(QModelIndex)"), self.openImageDetails) MObject.connect(self.isGetFromAmarok, SIGNAL("toggled(bool)"), self.isGetFromAmarokTiggered) self.lstwImages.clear() for image in self.musicValues["images"]: if len(image) == 5: pixmImage = MPixmap() pixmImage.loadFromData(image[3]) icnImage = QIcon(pixmImage) icnImage.actualSize(MSize(98, 98)) item = MListWidgetItem(icnImage, image[1] + "\n(" + image[2] + ")") item.setSizeHint(MSize(1, 100)) self.lstwImages.addItem(item) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseNameOfDirectory"]) HBOXs[-1].addWidget(self.infoValues["baseNameOfDirectory"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["baseName"]) HBOXs[-1].addWidget(self.infoValues["baseName"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["artist"]) HBOXs[-1].addWidget(self.infoValues["artist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["title"]) HBOXs[-1].addWidget(self.infoValues["title"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["album"]) HBOXs[-1].addWidget(self.infoValues["album"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["albumArtist"]) HBOXs[-1].addWidget(self.infoValues["albumArtist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["trackNum"]) HBOXs[-1].addWidget(self.infoValues["trackNum"]) HBOXs[-1].addWidget(self.infoLabels["year"]) HBOXs[-1].addWidget(self.infoValues["year"]) HBOXs[-1].addWidget(self.infoLabels["genre"]) HBOXs[-1].addWidget(self.infoValues["genre"]) vblInfos = MVBoxLayout() for hbox in HBOXs: vblInfos.addLayout(hbox) if Taggers.getTagger().isSupportImages: imageBoxs = [] imageBoxs.append(MHBoxLayout()) imageBoxs[0].addWidget(self.leImagePath) imageBoxs[0].addWidget(self.pbtnSelectImage) imageBoxs.append(MHBoxLayout()) imageBoxs[1].addWidget(self.lblImageType) imageBoxs[1].addWidget(self.cbImageType) imageBoxs.append(MHBoxLayout()) imageBoxs[2].addWidget(self.pbtnAddImage) imageBoxs[2].addWidget(self.pbtnDeleteImage) imageBoxs[2].addWidget(self.pbtnSaveAsImage) imageBoxs[2].addWidget(self.pbtnCancelAddImage) vblImages = MVBoxLayout() vblImages.addWidget(self.lstwImages) vblImages.addWidget(self.isOpenImageDetailsOnNewWindow) vblImages.addWidget(self.lblImagePath) vblImages.addLayout(imageBoxs[0]) vblImages.addLayout(imageBoxs[1]) vblImages.addLayout(imageBoxs[2]) vblComments = MVBoxLayout() vblComments.addWidget(self.infoValues["firstComment"]) vblLyrics = MVBoxLayout() vblLyrics.addWidget(self.infoValues["firstLyrics"]) self.tabwTabs = MTabWidget(self.pnlMain) self.pnlComments = MWidget(self.tabwTabs) self.pnlComments.setLayout(vblComments) self.tabwTabs.addTab(self.pnlComments, translate("MusicDetails", "Comments")) self.pnlLyrics = MWidget(self.tabwTabs) self.pnlLyrics.setLayout(vblLyrics) self.tabwTabs.addTab(self.pnlLyrics, translate("MusicDetails", "Lyrics")) if Taggers.getTagger().isSupportImages: self.pnlImages = MWidget(self.tabwTabs) self.pnlImages.setLayout(vblImages) self.tabwTabs.addTab(self.pnlImages, translate("MusicDetails", "Images")) self.pbtnSelectImage.hide() self.leImagePath.hide() self.lblImagePath.hide() self.lblImageType.hide() self.cbImageType.hide() self.pbtnCancelAddImage.hide() hblPlayer = MHBoxLayout() vblExtraButtons = MVBoxLayout() hblPlayer.addWidget(self.player) vblExtraButtons.addWidget(self.isPlayNow) vblExtraButtons.addWidget(self.isGetFromAmarok) hblPlayer.addLayout(vblExtraButtons) vblClearable.addLayout(hblPlayer) vblClearable.addLayout(vblInfos) vblClearable.addWidget(self.tabwTabs)
def changeArtist(self, _artistId, _isNew=False): self.artistId = _artistId self.songTableContentValues = None uni.startThreadAction() Dialogs.showState(translate("AmarokArtistDetails", "Getting Values From Amarok"), 0, 1) if Amarok.checkAmarok(): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: self.artistName = Commands.getArtistName(self.artistId) self.songTableContentValues = Operations.getAllMusicFileValuesWithNames("", self.artistId) Dialogs.showState(translate("MusicDetails", "Values Are Being Processed"), 1, 1) uni.finishThreadAction() if self.songTableContentValues is None: self.close() self.setWindowTitle(str(self.artistName)) if self.pnlClearable is not None: clearAllChildren(self.pnlClearable, True) self.pnlClearable = MWidget() self.vblMain.insertWidget(0, self.pnlClearable, 20) vblClearable = MVBoxLayout(self.pnlClearable) self.infoLabels["currentArtist"] = MLabel(self.labels[0]) self.infoLabels["correctedArtist"] = MLabel(self.labels[1]) self.infoValues["currentArtist"] = MLineEdit(str(self.artistName)) self.infoValues["correctedArtist"] = MLineEdit(str(Organizer.emend(self.artistName))) self.twSongs = MTableWidget() self.twSongs.clear() self.twSongs.setColumnCount(len(self.songTableColumns)) self.twSongs.setHorizontalHeaderLabels(self.songTableColumns) self.twSongs.setRowCount(len(self.songTableContentValues)) for rowNo in range(self.twSongs.rowCount()): item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["filePath"])) self.twSongs.setItem(rowNo, 0, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["artist"])) self.twSongs.setItem(rowNo, 1, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["title"])) self.twSongs.setItem(rowNo, 2, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["album"])) self.twSongs.setItem(rowNo, 3, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["albumArtist"])) self.twSongs.setItem(rowNo, 4, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["trackNumber"])) self.twSongs.setItem(rowNo, 5, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["year"])) self.twSongs.setItem(rowNo, 6, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["genre"])) self.twSongs.setItem(rowNo, 7, item) item = MTableWidgetItem(str(self.songTableContentValues[rowNo]["comment"])) self.twSongs.setItem(rowNo, 8, item) for x in range(self.twSongs.columnCount()): self.twSongs.item(rowNo, x).setFlags(Mt.ItemIsSelectable | Mt.ItemIsEnabled) HBOXs = [] HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["currentArtist"]) HBOXs[-1].addWidget(self.infoValues["currentArtist"]) HBOXs.append(MHBoxLayout()) HBOXs[-1].addWidget(self.infoLabels["correctedArtist"]) HBOXs[-1].addWidget(self.infoValues["correctedArtist"]) vblInfos = MVBoxLayout() for hbox in HBOXs: vblInfos.addLayout(hbox) vblInfos.addWidget(self.twSongs) vblClearable.addLayout(vblInfos)
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] startRowNo, rowStep = 0, 1 uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState( translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True) for rowNo in range(startRowNo, self.rowCount(), rowStep): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: pathOfParentDirectory = str( self.values[rowNo]["pathOfParentDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if self.isChangeableItem( rowNo, "sourceCover") or self.isChangeableItem( rowNo, "destinationCover"): sourcePath = self.values[rowNo]["sourceCover"] destinationPath = self.values[rowNo][ "destinationCover"] if self.isChangeableItem(rowNo, "sourceCover"): sourcePath = str( self.item(rowNo, 3).text()).strip() if self.isChangeableItem( rowNo, "destinationCover"): destinationPath = str( self.item(rowNo, 4).text()).strip() if (str(self.item(rowNo, 2).text()) != sourcePath or sourcePath != destinationPath or str(self.item(rowNo, 2).text()) != destinationPath ) or (str(self.item(rowNo, 2).text()) != self.values[rowNo]["currentCover"] and (str(self.item(rowNo, 2).text()) != sourcePath and str(self.item(rowNo, 2).text()) != destinationPath)): if str(self.item(rowNo, 3).text()).strip() != "": sourcePath = fu.getRealPath( sourcePath, self.values[rowNo]["path"]) sourcePath = fu.checkSource( sourcePath, "file") if sourcePath is not None: if destinationPath != "": destinationPath = fu.getRealPath( destinationPath, self.values[rowNo]["path"]) if sourcePath != destinationPath: destinationPath = fu.moveOrChange( sourcePath, destinationPath) else: destinationPath = sourcePath fu.setIconToDirectory( self.values[rowNo]["path"], destinationPath) self.changedValueNumber += 1 else: fu.setIconToDirectory( self.values[rowNo]["path"], "") self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseNameOfDirectory", pathOfParentDirectory): pathOfParentDirectory = str( self.item(rowNo, 0).text()) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath(pathOfParentDirectory, baseName) oldFilePath = fu.getRealPath( self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange( oldFilePath, newFilePath, "directory") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue( "isClearEmptyDirectoriesWhenFileMove" ): fu.checkEmptyDirectories( oldDirName, True, True, uni.getBoolValue( "isAutoCleanSubFolderWhenFileMove" )) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState( translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if len(oldAndNewPathValues) > 0: from Amarok import Operations Operations.changePaths(oldAndNewPathValues) return True
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] if uni.isActiveAmarok and uni.getBoolValue("isSubFolderTableValuesChangeInAmarokDB"): import Amarok if Amarok.checkAmarok(True, False) is False: return False uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/SubFolders", "Writing File Informations"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: baseNameOfDirectory = str(self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 newDirectoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory) self.setNewDirectory(newDirectoryPath) if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath(str(self.values[rowNo]["path"]).replace( fu.joinPath(str(self.values[rowNo]["baseNameOfDirectory"]), str(self.values[rowNo]["baseName"])), ""), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue("isAutoMakeIconToDirectoryWhenFileMove")): fu.checkIcon(oldDirName) fu.checkIcon(fu.getDirName(oldAndNewPaths["newPath"])) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/SubFolders", "Writing File Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if (uni.isActiveAmarok and uni.getBoolValue("isSubFolderTableValuesChangeInAmarokDB") and len(oldAndNewPathValues) > 0): import Amarok from Amarok import Operations Operations.changePaths(oldAndNewPathValues, "file") return True
def writeContents(self): self.changedValueNumber = 0 oldAndNewPathValues = [] changingTags = [] isNewDirectoriesSame = True isMovedToNewDirectory = False currentDirectoryPath = "" newDirectoryPath = "" if uni.isActiveAmarok and uni.getBoolValue("isMusicTableValuesChangeInAmarokDB"): import Amarok if Amarok.checkAmarok(True, False) is False: return False uni.startThreadAction() allItemNumber = len(self.values) Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags"), 0, allItemNumber, True) for rowNo in range(self.rowCount()): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: changingTag = {"path": self.values[rowNo]["path"]} if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True): if self.isRowHidden(rowNo): fu.removeFileOrDir(self.values[rowNo]["path"]) self.changedValueNumber += 1 else: baseNameOfDirectory = str( self.values[rowNo]["baseNameOfDirectory"]) baseName = str(self.values[rowNo]["baseName"]) tagger = Taggers.getTagger() tagger.loadFileForWrite(self.values[rowNo]["path"]) isCheckLike = (tagger.isNeedUpdate or (uni.isActiveAmarok and uni.getBoolValue("isMusicTableValuesChangeInAmarokDB"))) if self.isChangeableItem(rowNo, "artist", self.values[rowNo]["artist"], True, isCheckLike): value = str(self.item(rowNo, 2).text()) tagger.setArtist(value) changingTag["artist"] = value Records.add(str(translate("MusicTable", "Artist")), str(self.values[rowNo]["artist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "title", self.values[rowNo]["title"], True, isCheckLike): value = str(self.item(rowNo, 3).text()) tagger.setTitle(value) changingTag["title"] = value Records.add(str(translate("MusicTable", "Title")), str(self.values[rowNo]["title"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "album", self.values[rowNo]["album"], True, isCheckLike): value = str(self.item(rowNo, 4).text()) tagger.setAlbum(value) changingTag["album"] = value Records.add(str(translate("MusicTable", "Album")), str(self.values[rowNo]["album"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "albumArtist", self.values[rowNo]["albumArtist"], True, isCheckLike): value = str(self.item(rowNo, 5).text()) tagger.setAlbumArtist(value) changingTag["albumArtist"] = value Records.add(str(translate("MusicTable", "Album Artist")), str(self.values[rowNo]["albumArtist"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "trackNum", self.values[rowNo]["trackNum"], True, isCheckLike): value = str(self.item(rowNo, 6).text()) tagger.setTrackNum(value) changingTag["trackNum"] = value Records.add(str(translate("MusicTable", "Track No")), str(self.values[rowNo]["trackNum"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "year", self.values[rowNo]["year"], True, isCheckLike): value = str(self.item(rowNo, 7).text()) tagger.setDate(value) changingTag["year"] = value Records.add(str(translate("MusicTable", "Year")), str(self.values[rowNo]["year"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "genre", self.values[rowNo]["genre"], True, isCheckLike): value = str(self.item(rowNo, 8).text()) tagger.setGenre(value) changingTag["genre"] = value Records.add(str(translate("MusicTable", "Genre")), str(self.values[rowNo]["genre"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstComment", self.values[rowNo]["firstComment"], True, isCheckLike): value = str(self.item(rowNo, 9).text()) tagger.setFirstComment(value) changingTag["firstComment"] = value Records.add(str(translate("MusicTable", "Comment")), str(self.values[rowNo]["firstComment"]), value) self.changedValueNumber += 1 if self.isChangeableItem(rowNo, "firstLyrics", self.values[rowNo]["firstLyrics"], True, isCheckLike): value = str(self.item(rowNo, 10).text()) tagger.setFirstLyrics(value) changingTag["firstLyrics"] = value Records.add(str(translate("MusicTable", "Lyrics")), str(self.values[rowNo]["firstLyrics"]), value) self.changedValueNumber += 1 if len(changingTag) > 1: changingTags.append(changingTag) tagger.update() if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory): baseNameOfDirectory = str(self.item(rowNo, 0).text()) self.changedValueNumber += 1 isMovedToNewDirectory = True currentDirectoryPath = fu.getDirName( self.values[rowNo]["path"]) newDirectoryPath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory) self.setNewDirectory(newDirectoryPath) if rowNo > 0: if str(self.item(rowNo - 1, 0).text()) != baseNameOfDirectory: isNewDirectoriesSame = False if self.isChangeableItem(rowNo, "baseName", baseName, False): baseName = str(self.item(rowNo, 1).text()) self.changedValueNumber += 1 newFilePath = fu.joinPath( fu.getDirName(fu.getDirName(self.values[rowNo]["path"])), baseNameOfDirectory, baseName) oldFilePath = fu.getRealPath(self.values[rowNo]["path"]) newFilePath = fu.getRealPath(newFilePath) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "file") if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) oldDirName = fu.getDirName(oldFilePath) if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(oldDirName, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Musics", "Writing Music Tags And Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if self.rowCount() == len(oldAndNewPathValues) and isMovedToNewDirectory and isNewDirectoriesSame: otherFileNames = fu.readDirectory(currentDirectoryPath, "fileAndDirectory", True) if len(otherFileNames) > 0: answer = Dialogs.ask(translate("FileUtils/Musics", "There Are More Files"), str(translate("FileUtils/Musics", "\"%s\" : there are more files in this directory.<br>Are you want to move all found files into new directory?<br>New Directory : \"%s\"")) % ( Organizer.getLink(currentDirectoryPath), Organizer.getLink(newDirectoryPath))) if answer == Dialogs.Yes: uni.startThreadAction() allItemNumber = len(otherFileNames) for rowNo, fileName in enumerate(otherFileNames): isContinueThreadAction = uni.isContinueThreadAction() if isContinueThreadAction: try: oldFilePath = fu.getRealPath(fu.joinPath(currentDirectoryPath, fileName)) newFilePath = fu.getRealPath(fu.joinPath(newDirectoryPath, fileName)) if oldFilePath != newFilePath: oldAndNewPaths = {} oldAndNewPaths["oldPath"] = oldFilePath oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, fu.getObjectType(oldFilePath)) if oldFilePath != oldAndNewPaths["newPath"]: oldAndNewPathValues.append(oldAndNewPaths) except: ReportBug.ReportBug() else: allItemNumber = rowNo + 1 Dialogs.showState(translate("FileUtils/Covers", "Writing Directory And File Informations"), rowNo + 1, allItemNumber, True) if isContinueThreadAction is False: break uni.finishThreadAction() if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"): fu.checkEmptyDirectories(currentDirectoryPath, True, True, uni.getBoolValue("isAutoCleanSubFolderWhenFileMove")) if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and uni.getBoolValue("isAutoMakeIconToDirectoryWhenFileMove")): fu.checkIcon(newDirectoryPath) if uni.isActiveAmarok and uni.getBoolValue("isMusicTableValuesChangeInAmarokDB"): import Amarok from Amarok import Operations Operations.changeTags(changingTags) if len(oldAndNewPathValues) > 0: Operations.changePaths(oldAndNewPathValues, "file") return True