Пример #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 __str__(self):
     return utils.fmtstr(
         '{}:{}/{}'.format(self.path, self.no, len(self.streams)),
         type=self.type,
         lang=self.lang,
         enc=self.enc,
         fps=self.fps,
         channels=self.channels if self.channels.type != 'auto' else None)
Пример #5
0
 def __str__(self):
     return utils.fmtstr(self.path,
                         enc=self.enc,
                         fps=self.fps,
                         overwrite=self.overwrite)
Пример #6
0
 def __str__(self):
     return utils.fmtstr(self.path, enc=self.enc, fps=self.fps)