Beispiel #1
0
    def createDataFromFile(self, filePath, inputEncoding = None, defaultFps = None):
        """Fetch a given filePath and parse its contents.

        May raise the following exceptions:
        * RuntimeError - generic exception telling that parsing was unsuccessfull
        * IOError - failed to open a file at given filePath

        @return SubtitleData filled with non-empty, default datafields. Client should modify them
                and then perform an add/update operation"""

        file_ = File(filePath)
        if inputEncoding is None:
            inputEncoding = file_.detectEncoding()
        inputEncoding = inputEncoding.lower()

        videoInfo = VideoInfo(defaultFps) if defaultFps is not None else file_.detectFps()

        subtitles = self._parseFile(file_, inputEncoding, videoInfo.fps)

        data = SubtitleData()
        data.subtitles = subtitles
        data.fps = videoInfo.fps
        data.inputEncoding = inputEncoding
        data.outputEncoding = inputEncoding
        data.outputFormat = self._parser.parsedFormat()
        data.videoPath = videoInfo.videoPath
        return data
Beispiel #2
0
    def createSubData(self, subFile, outputFormat):
        data = SubtitleData()
        data.fps = self.getFps(subFile)
        data.outputFormat = outputFormat
        data.inputEncoding = self.getInputEncoding(subFile)
        data.outputEncoding = self.getOutputEncoding(data.inputEncoding)

        self.printData(subFile.path, data)

        try:
            data.subtitles = self.parseFile(subFile, data.inputEncoding, data.fps)
        except SubException as msg:
            log.error(str(msg))
            return None

        # shouldn't throw as all common checks are performed by getters
        data.verifyAll()
        return data