Exemple #1
0
    def applyFor(self, filePath, data):
        subtitleFile = File(filePath)

        # fps
        if self._subProperties.autoFps:
            videoInfo = subtitleFile.detectFps(default=self._subProperties.fps)
            data.subtitles.changeFps(videoInfo.fps)
            data.fps = videoInfo.fps
            data.videoPath = videoInfo.videoPath
        else:
            data.subtitles.changeFps(self._subProperties.fps)
            data.fps = self._subProperties.fps
            data.videoPath = None

        # input encoding
        inputEncoding = self._subProperties.inputEncoding
        if self._subProperties.autoInputEncoding:
            inputEncoding = subtitleFile.detectEncoding().lower()
        if data.inputEncoding != inputEncoding:
            data.encode(inputEncoding)

        # output encoding
        if self._subProperties.changeEncoding:
            data.outputEncoding = self._subProperties.outputEncoding
        else:
            data.outputEncoding = self._subProperties.inputEncoding

        # subtitle format
        data.outputFormat = self._subProperties.outputFormat

        return data
Exemple #2
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