def onEos(self, pElement, pMessage): super().onEos(pElement, pMessage) if self.sOperation == 'replay-gain': self.nOperation = 1 self.sOperation = 'encode' for sKey in ['track-number', 'track-count', 'album-disc-number', 'album-disc-count', 'date', 'image']: if sKey in self.dTags: if self.dTags[sKey]: if sKey == 'track-number': self.dTags[sKey] = GObject.Value(GObject.TYPE_UINT, int(self.dTags[sKey])) elif sKey == 'track-count': self.dTags[sKey] = GObject.Value(GObject.TYPE_UINT, int(self.dTags[sKey])) elif sKey == 'album-disc-number': self.dTags[sKey] = GObject.Value(GObject.TYPE_UINT, int(self.dTags[sKey])) elif sKey == 'album-disc-count': self.dTags[sKey] = GObject.Value(GObject.TYPE_UINT, int(self.dTags[sKey])) elif sKey == 'date': self.dTags['extended-comment'] = 'DATE=' + self.dTags[sKey] self.dTags[sKey] = GLib.Date.new_dmy(1, 1, int(self.dTags[sKey])) elif sKey == 'image': with open(self.dTags[sKey], 'rb') as pFile: self.dTags[sKey] = pFile.read() self.dTags[sKey] = GstTag.tag_image_data_to_image_sample(self.dTags[sKey], GstTag.TagImageType.FRONT_COVER) else: del self.dTags[sKey] self.dTags['replaygain-reference-level'] = 89.0 if self.sEncoder == 'flac': self.init('filesrc location="' + escape(self.sPathIn) + '" ! decodebin ! audioconvert ! audio/x-raw, channels=(int)' + self.sChannels + ' ! flacenc name=enc quality=8 ! filesink location="' + escape(self.sPathTmp) + '"', self.dTags) self.play() else: self.pProc = subprocess.Popen('neroAacEnc -if "' + escape(self.sPathIn) + '" -of "' + escape(self.sPathTmp) + '" -q 1.0 ', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines = True) self.sOperation = 'nero-encode' elif self.sOperation == 'encode' or self.sOperation == 'nero-tag': if self.sOperation == 'nero-tag': shutil.move(self.sPathTmp.replace('m4a', 'tmp.m4a'), self.sPathTmp) pMp4 = MP4(self.sPathTmp) pMp4['----:com.apple.iTunes:replaygain_track_gain'] = str(round(self.dTags['replaygain-track-gain'], 2)).encode() pMp4['----:com.apple.iTunes:replaygain_track_peak'] = str(round(self.dTags['replaygain-track-peak'], 6)).encode() pMp4.save() shutil.move(self.sPathTmp, self.sPathOut) self.nState = GstState.DONE GLib.idle_add(self.pCallback, self.pParam)