Exemple #1
0
    def run(self):
        waveext, aacext = '.wav', '.m4a'
        for item in self.QUEUE:
            current = self.QUEUE.index(item)
            # For non-WAVE files, use Unix `mplayer ` to encode them to WAVE, 
            # then encode using Nero AAC codec and tag the media info. 
            wx.CallAfter(self.CALLER.updateProgress, current)
            if not q.extof(item) == waveext:
                tempFname = os.path.join(
                    self.TEMPDIR, 
                    q.randomstr(20) + waveext
                    )
                if self.convert2Wave(item, dest = tempFname) == 0:
                    destFname = q.dropext(item, baseonly = False) + aacext
                    self.convert2Aac(tempFname, dest = destFname)
                    # This is really important! If tempdir is set to 
                    # `/dev/shm ` and temp file is not deleted, 
                    # sooner or later the user's memory would explode.
                    os.remove(tempFname)
                    # Unix `mediainfo ` program cannot handle file with 
                    # '?' in its name, so we'll have to get a copy of that 
                    # file and rename the copy, or this program will probably 
                    # hang up here.
                    if q.containwiredchar(item):
                        tempFile4tag = os.path.join(
                            self.TEMPDIR, 
                            q.reformfilename(
                                item, 
                                strict = True, 
                                baseonly = True
                                )
                            )
                        shutil.copy(item, tempFile4tag)
                        minfo = mediainfo.query(tempFile4tag)
                        os.remove(tempFile4tag)
                    else:
                        minfo = mediainfo.query(item)
                    self.tagAac(
                        destFname, 
                        mediainfo = minfo
                        )

                    # Delete original file if DELORIGIN set to `True `
                    if self.DELORIGIN and q.fileexists(destFname):
                        os.remove(item)
                else:
                    print 'Error occurred during convert2Wave.'
            # For WAVE files, encode directly using Nero AAC codec, and since 
            # WAVE files don't have media info with them, there's no need to 
            # tag them. 
            else:
                destFname = q.dropext(item, baseonly = False) + aacext
                self.convert2Aac(tempFname, dest = destFname)

                # Delete original file if DELORIGIN set to `True `
                if self.DELORIGIN and q.fileexists(destFname):
                    os.remove(item)

            self.DONE.append(item)
        wx.CallAfter(self.CALLER.OnConversionDone)
Exemple #2
0
    def OnConversionStart(self, event):
        '''
        Start conversion.
        '''
        if len(self.QUEUE) == 0:
            dlg = wx.MessageDialog(None, _('No file selected.'),
                                   _('Nothing to do'), wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
        else:
            # Avoid adding files or starting another conversion,
            # cause the background thread does not care whether the
            # file queue has changed.
            q.disabletools(['toolopen', 'toolconvert'],
                           parent=self.GetToolBar())
            C = wx.GetApp().CONFIG

            # Find absolute path of encoder and tagger executables if they
            # were set in config file, otherwise use default values.
            encpath = C.Read(i.APP_CONFIG_ENC_PATH_KEY, '')
            tagpath = C.Read(i.APP_CONFIG_TAG_PATH_KEY, '')
            if encpath and q.fileexists(os.path.abspath(encpath)):
                encpath = os.path.abspath(encpath)
            else:
                encpath = i.NERO_ENC_DEFAULT_PATH
            if tagpath and q.fileexists(os.path.abspath(tagpath)):
                tagpath = os.path.abspath(tagpath)
            else:
                tagpath = i.NERO_TAG_DEFAULT_PATH

            # Create background thread to do the actual work.
            self.CONVERTER = converter.Converter(
                caller=self,
                queue=self.QUEUE,
                tempdir=C.Read(i.APP_CONFIG_TEMPDIR_KEY,
                               tempfile.gettempdir()),
                bitrate=C.ReadInt(i.APP_CONFIG_BITRATE_KEY,
                                  i.AAC_DEFAULT_BITRATE),
                delorigin=C.ReadBool(i.APP_CONFIG_DELORIGIN_KEY,
                                     i.APP_DEFAULT_DELORIGIN),
                encoder=encpath,
                tagger=tagpath)

            # Show progress dialog and do the actual conversion.
            self.PROGRESS = wx.ProgressDialog(
                _('Conversion progress'),
                _('Processing files: %d in total') % len(self.QUEUE),
                len(self.QUEUE),
                style=wx.PD_AUTO_HIDE)
            self.CONVERTER.start()
Exemple #3
0
    def run(self):
        waveext, aacext = '.wav', '.m4a'
        for item in self.QUEUE:
            current = self.QUEUE.index(item)
            # For non-WAVE files, use Unix `mplayer ` to encode them to WAVE,
            # then encode using Nero AAC codec and tag the media info.
            wx.CallAfter(self.CALLER.updateProgress, current)
            if not q.extof(item) == waveext:
                tempFname = os.path.join(self.TEMPDIR,
                                         q.randomstr(20) + waveext)
                if self.convert2Wave(item, dest=tempFname) == 0:
                    destFname = q.dropext(item, baseonly=False) + aacext
                    self.convert2Aac(tempFname, dest=destFname)
                    # This is really important! If tempdir is set to
                    # `/dev/shm ` and temp file is not deleted,
                    # sooner or later the user's memory would explode.
                    os.remove(tempFname)
                    # Unix `mediainfo ` program cannot handle file with
                    # '?' in its name, so we'll have to get a copy of that
                    # file and rename the copy, or this program will probably
                    # hang up here.
                    if q.containwiredchar(item):
                        tempFile4tag = os.path.join(
                            self.TEMPDIR,
                            q.reformfilename(item, strict=True, baseonly=True))
                        shutil.copy(item, tempFile4tag)
                        minfo = mediainfo.query(tempFile4tag)
                        os.remove(tempFile4tag)
                    else:
                        minfo = mediainfo.query(item)
                    self.tagAac(destFname, mediainfo=minfo)

                    # Delete original file if DELORIGIN set to `True `
                    if self.DELORIGIN and q.fileexists(destFname):
                        os.remove(item)
                else:
                    print 'Error occurred during convert2Wave.'
            # For WAVE files, encode directly using Nero AAC codec, and since
            # WAVE files don't have media info with them, there's no need to
            # tag them.
            else:
                destFname = q.dropext(item, baseonly=False) + aacext
                self.convert2Aac(tempFname, dest=destFname)

                # Delete original file if DELORIGIN set to `True `
                if self.DELORIGIN and q.fileexists(destFname):
                    os.remove(item)

            self.DONE.append(item)
        wx.CallAfter(self.CALLER.OnConversionDone)
Exemple #4
0
    def OnConversionStart(self, event):
        '''
        Start conversion.
        '''
        if len(self.QUEUE) == 0:
            dlg = wx.MessageDialog(
                None, 
                _('No file selected.'), 
                _('Nothing to do'), 
                wx.OK | wx.ICON_ERROR
                )
            dlg.ShowModal()
            dlg.Destroy()
        else:
            # Avoid adding files or starting another conversion, 
            # cause the background thread does not care whether the 
            # file queue has changed.
            q.disabletools(
                ['toolopen', 'toolconvert'], 
                parent = self.GetToolBar()
                )
            C = wx.GetApp().CONFIG

            # Find absolute path of encoder and tagger executables if they 
            # were set in config file, otherwise use default values.
            encpath = C.Read(i.APP_CONFIG_ENC_PATH_KEY, '')
            tagpath = C.Read(i.APP_CONFIG_TAG_PATH_KEY, '')
            if encpath and q.fileexists(os.path.abspath(encpath)):
                encpath = os.path.abspath(encpath)
            else:
                encpath = i.NERO_ENC_DEFAULT_PATH
            if tagpath and q.fileexists(os.path.abspath(tagpath)):
                tagpath = os.path.abspath(tagpath)
            else:
                tagpath = i.NERO_TAG_DEFAULT_PATH

            # Create background thread to do the actual work.
            self.CONVERTER = converter.Converter(
                caller = self, 
                queue = self.QUEUE, 
                tempdir = C.Read(
                    i.APP_CONFIG_TEMPDIR_KEY, 
                    tempfile.gettempdir()
                    ), 
                bitrate = C.ReadInt(
                    i.APP_CONFIG_BITRATE_KEY, 
                    i.AAC_DEFAULT_BITRATE
                    ), 
                delorigin = C.ReadBool(
                    i.APP_CONFIG_DELORIGIN_KEY, 
                    i.APP_DEFAULT_DELORIGIN
                    ), 
                encoder = encpath, 
                tagger = tagpath
                )

            # Show progress dialog and do the actual conversion.
            self.PROGRESS = wx.ProgressDialog(
                _('Conversion progress'), 
                _('Processing files: %d in total') % len(self.QUEUE), 
                len(self.QUEUE), 
                style = wx.PD_AUTO_HIDE
                )
            self.CONVERTER.start()