예제 #1
0
    def save(self,
             path,
             encoding=u'utf-8',
             fmt=None,
             fps=None,
             overwrite=False):
        if fmt == None and path.endswith('.txt'):
            fmt = 'microdvd'

        if not overwrite and os.path.exists(path):
            logger.info('file "%s" exists, generating new path', path)
            path = genUniquePath(path)

        logger.info('saving subtitles to "%s", %s', path,
                    utils.fmtstr(enc=encoding, fmt=fmt, fps=fps))
        try:
            super().save(path, encoding=encoding, format_=fmt, fps=fps)
        except pysubs2.exceptions.UnknownFileExtensionError as err:
            if fmt != None:
                raise error.Error('Can\'t save subtitles file' + '\n' + str(err)) \
                        .add('path', path) \
                        .add('encodings', encoding) \
                        .addn('format', fmt) \
                        .addn('fps', fps)
            else:
                super().save(path,
                             encoding=encoding,
                             format_='microdvd',
                             fps=fps)
예제 #2
0
    def save(self, path, encoding=u'utf-8', fmt=None, fps=None, overwrite=False):
        if not overwrite and os.path.exists(path):
            logger.info('file "%s" exists, generating new path', path)
            path = genUniquePath(path)

        logger.info('saving subtitles to "%s", %s', path,
                utils.fmtstr(enc=encoding, fmt=fmt, fps=fps))

        try:
            if fmt is None:
                ext = os.path.splitext(path)[1].lower()
                fmts = [ x['type'] for x in filetypes.subtitleTypes if x['ext'] == ext ]
                if len(fmts):
                    fmt = fmts[0]
            if fmt is None:
                raise Exception(_('Unknown file extension'))

            with open(path, 'w', encoding=encoding, errors='replace') as fp:
                super().to_file(fp, format_=fmt, fps=fps)

        except Exception as e:
            raise error.Error(_('Can\'t save subtitle file') + '. ' + str(e)) \
                    .add('path', path) \
                    .add('encoding', encoding) \
                    .addn('format', fmt) \
                    .addn('fps', fps)

        return path
예제 #3
0
    def save(self,
             path,
             encoding=u'utf-8',
             fmt=None,
             fps=None,
             overwrite=False):
        if not overwrite and os.path.exists(path):
            logger.info('file "%s" exists, generating new path', path)
            path = genUniquePath(path)

        logger.info('saving subtitles to "%s", %s', path,
                    utils.fmtstr(enc=encoding, fmt=fmt, fps=fps))
        try:
            super().save(path, encoding=encoding, format_=fmt, fps=fps)
        except Exception as e:
            if type(e) is pysubs2.exceptions.UnknownFileExtensionError:
                descr = _('Unknown file extension') + ': {!s}'.format(e)
            else:
                descr = str(e)
            raise error.Error(_('Can\'t save subtitle file') + '. ' + descr) \
                    .add('path', path) \
                    .add('encoding', encoding) \
                    .addn('format', fmt) \
                    .addn('fps', fps)

        return path
예제 #4
0
def loadSpeechModel(lang):
    logger.info('loading speech recognition model for language %s', lang)

    asset = assets.getAsset('speech', [lang])
    if asset.isLocal():
        logger.debug('model ready: %s', asset.getLocal())
        return asset.getLocal()

    raise error.Error(_('There is no speech recognition model for language {}')
            .format(lang)).add('language', lang)
예제 #5
0
def getSpeechAudioFormat(speechModel):
    try:
        sampleFormat = getattr(gizmo.AVSampleFormat,
                speechModel.get('sampleformat', 'S16'))

        sampleRate = speechModel.get('samplerate', 16000)
        if type(sampleRate) == str:
            sampleRate = int(sampleRate)

        return gizmo.AudioFormat(sampleFormat, sampleRate, 1)
    except:
        raise error.Error(_('Invalid speech audio format'))
예제 #6
0
 def showStreamSelectionWindow(self, items, types):
     if not items:
         raise error.Error(_('Select files first'))
     files = [item.file for item in items]
     with StreamSelectionWin(self, files, types) as dlg:
         if dlg.ShowModal() == wx.ID_OK:
             for item, selection in zip(items, dlg.getSelection()):
                 if selection != None:
                     item.selectStream(selection)
             self.onSelection()
             self.updateTasks()
             self.m_items.Refresh()
예제 #7
0
    def save(self, path, encoding=u'utf-8', fmt=None, fps=None):
        if fmt == None and path.endswith('.txt'):
            fmt = 'microdvd'

        logger.info('save subtitles, enc=%r format=%r fps=%r path=%s',
                    encoding, fmt, fps, path)
        try:
            super().save(path, encoding=encoding, format_=fmt, fps=fps)
        except pysubs2.exceptions.UnknownFileExtensionError as err:
            if fmt != None:
                raise error.Error('Can\'t save subtitles file' + '\n' + str(err)) \
                        .add('path', path) \
                        .add('encodings', encoding) \
                        .addn('format', fmt) \
                        .addn('fps', fps)
            else:
                super().save(path,
                             encoding=encoding,
                             format_='microdvd',
                             fps=fps)
예제 #8
0
    def validate(self, localOnly=False):
        """Check if all assets on the list are available.

        Parameters
        ----------
        localOnly: bool, optional
            If `True` this method will check if all assets are installed
            locally, otherwise it will check if assets are available either
            locally or on asset server.

        Raises
        ------
        Error
            At least one asset is not available.
        """
        if localOnly:
            assets = self.notInstalled()
        else:
            assets = self.missing()

        if assets:
            msg = []
            speech = [asset for asset in assets if asset.type == 'speech']
            dicts = [asset for asset in assets if asset.type == 'dict']

            if speech:
                langs = ', '.join(
                    [languages.getName(a.params[0]) for a in speech])
                msg += [ _('Synchronization with {} audio is currently not supported.') \
                        .format(langs) ]
            if dicts:
                langs = [
                    ' - '.join([languages.getName(p) for p in a.params])
                    for a in dicts
                ]
                msg += [ _('Synchronization between languages {} is currently not supported.') \
                        .format(', '.join(langs)) ]

            msg += ['', _('missing assets:')]
            msg += [' - ' + asset.getPrettyName() for asset in assets]
            raise error.Error('\n'.join(msg))
예제 #9
0
 def removeItems(self, items):
     if not items:
         raise error.Error(_('Select files first'))
     self.m_items.removeItems(items)
     self.m_items.Refresh()