示例#1
0
    def _napiFormatConversion(self, fromFormat, toFormat):
        media = None
        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subs = self.subtitlesAssets.prepareRandomMedia(sandbox,
                    fromFormat)

            # program napiprojekt mock
            self.napiMock.programXmlRequest(
                    media,
                    napi.subtitles.CompressedSubtitles.fromFile(
                        media['asset'],
                        subs['path']))

            fs = napi.fs.Filesystem(media)

            # get the subs
            self.napiScan('-f', toFormat, media['path'])

            # check assertions
            req = self.napiMock.getRequest()
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            # confirm the format
            self.assertTrue(fs.subtitlesExists())
            for s in fs.getSubtitlesPaths():
                self.subotageExecute('-gi', '-i', s)
                self.assertTrue(self.output.stdoutContains(
                    re.compile(r'IN_FORMAT -> {}'.format(toFormat))))
示例#2
0
    def test_ifSkippingWorksWithFormatConversionAndAbbreviations(self):
        """
        Brief:
        Check skipping with conversion requested and
        abbreviations specified

        Procedure:
        1. Prepare media and subs files
        2. Program napi mock
        3. Perform a request for subtitles for media file with conversion.
        Request should result in ORIG_ file present in the filesystem
        4. Request subs for media with abbreviation AB and conversion
        abbreviation specified as CAB and a request to convert the format.
        Additionally this request should have the skip flag set.

        Expected Results:

        1. The subtitles shouldn't be downloaded, original available file
        should be converted
        2. After conversion both files should exist in the filesystem
        (original one with prefix prepended)
        3. Converted file should have both abbreviation and conversion
        abbreviation inserted into the file name
        """
        media = None
        fromFormat = 'microdvd'
        toFormat = 'subrip'
        abbreviation = 'AB'
        convAbbrev = 'CAB'

        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file and subs
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subs = self.subtitlesAssets.prepareRandomMedia(sandbox,
                    fromFormat)

            # program napiprojekt mock - it should be called only once
            self.napiMock.programXmlRequest(
                    media,
                    napi.subtitles.CompressedSubtitles.fromFile(
                        media['asset'],
                        subs['path']),
                    None,
                    None,
                    1)

            # get the subs
            self.napiScan('--stats',
                    '-f', toFormat,
                    '-a', abbreviation,
                    '--conv-abbrev', convAbbrev,
                    media['path'])

            # check assertions
            req = self.napiMock.getRequest()
            self.assertTrue(req)
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(self.output.stdoutContains(
                re.compile(r'napisy pobrano pomyslnie')))

            # check statistics and the file itself
            stats = self.output.parseNapiStats()
            fs = napi.fs.Filesystem(media)
            self.assertEquals(1, stats['ok'])
            self.assertEquals(1, stats['conv'])
            self.assertEquals(1, stats['total'])
            self.assertEquals(0, stats['unav'])

            # make another request
            self.napiScan('--stats',
                    '-s',
                    '-f', toFormat,
                    '-a', abbreviation,
                    '--conv-abbrev', convAbbrev,
                    media['path'])

            stats = self.output.parseNapiStats()
            self.assertEquals(0, stats['ok'])
            self.assertEquals(1, stats['skip'])
            self.assertEquals(1, stats['total'])
            self.assertEquals(0, stats['unav'])

            subsFiles = fs.getSubtitlesPaths('ORIG', None,
                    abbreviation, convAbbrev)

            abbrevExt = abbreviation + '.txt'
            convAbbrevExt = '.'.join((abbreviation, convAbbrev, 'srt'))

            self.assertTrue(any(
                [ True if abbrevExt in s else False
                    for s in subsFiles ]))

            self.assertTrue(any(
                [ True if convAbbrevExt in s else False
                    for s in subsFiles ]))
示例#3
0
    def test_ifSkippingWorksWithFormatConversionAndAbbreviations(self):
        """
        Brief:
        Check skipping with conversion requested and
        abbreviations specified

        Procedure:
        1. Prepare media and subs files
        2. Program napi mock
        3. Perform a request for subtitles for media file with conversion.
        Request should result in ORIG_ file present in the filesystem
        4. Request subs for media with abbreviation AB and conversion
        abbreviation specified as CAB and a request to convert the format.
        Additionally this request should have the skip flag set.

        Expected Results:

        1. The subtitles shouldn't be downloaded, original available file
        should be converted
        2. After conversion both files should exist in the filesystem
        (original one with prefix prepended)
        3. Converted file should have both abbreviation and conversion
        abbreviation inserted into the file name
        """
        media = None
        fromFormat = 'microdvd'
        toFormat = 'subrip'
        abbreviation = 'AB'
        convAbbrev = 'CAB'

        with napi.sandbox.Sandbox() as sandbox:
            # generate a media file and subs
            media = self.videoAssets.prepareRandomMedia(sandbox)
            subs = self.subtitlesAssets.prepareRandomMedia(sandbox, fromFormat)

            # program napiprojekt mock - it should be called only once
            self.napiMock.programXmlRequest(
                media,
                napi.subtitles.CompressedSubtitles.fromFile(
                    media['asset'], subs['path']), None, None, 1)

            # get the subs
            self.napiScan('--stats', '-f', toFormat, '-a', abbreviation,
                          '--conv-abbrev', convAbbrev, media['path'])

            # check assertions
            req = self.napiMock.getRequest()
            self.assertTrue(req)
            self.assertEquals(req.method, "POST")
            self.assertEquals(req.url, '/api/api-napiprojekt3.php')
            self.assertTrue(
                self.output.stdoutContains(
                    re.compile(r'napisy pobrano pomyslnie')))

            # check statistics and the file itself
            stats = self.output.parseNapiStats()
            fs = napi.fs.Filesystem(media)
            self.assertEquals(1, stats['ok'])
            self.assertEquals(1, stats['conv'])
            self.assertEquals(1, stats['total'])
            self.assertEquals(0, stats['unav'])

            # make another request
            self.napiScan('--stats', '-s', '-f', toFormat, '-a', abbreviation,
                          '--conv-abbrev', convAbbrev, media['path'])

            stats = self.output.parseNapiStats()
            self.assertEquals(0, stats['ok'])
            self.assertEquals(1, stats['skip'])
            self.assertEquals(1, stats['total'])
            self.assertEquals(0, stats['unav'])

            subsFiles = fs.getSubtitlesPaths('ORIG', None, abbreviation,
                                             convAbbrev)

            abbrevExt = abbreviation + '.txt'
            convAbbrevExt = '.'.join((abbreviation, convAbbrev, 'srt'))

            self.assertTrue(
                any([True if abbrevExt in s else False for s in subsFiles]))

            self.assertTrue(
                any([True if convAbbrevExt in s else False
                     for s in subsFiles]))