Ejemplo n.º 1
0
    def test_process(self):
        # Run example process with output
        processor = FileProcessor('Se7en.mkv', 'seven.mkv', 'roku')
        res = processor.process()
        self.assertEqual(res, {'streams': 4, 'output': 'seven.mkv'})

        # Run example process without output, output should be same as input
        processor.output = None
        res = processor.process()
        self.assertEqual(res, {'streams': 4, 'output': 'Se7en.mkv'})
Ejemplo n.º 2
0
    def test_merge(self, ecmd):
        processor = FileProcessor('input.mkv', 'output.mkv', 'roku')

        # Merge streams without conversion, should return empty list
        streams = [{'input': 'input.mkv', 'index': 0},
                   {'input': 'input.mkv', 'index': 1},
                   {'input': 'input.mkv', 'index': 2},
                   {'input': 'input.mkv', 'index': 3},
                   {'input': 'input.mkv', 'index': 4}]
        inputs = processor.merge(streams)
        self.assertEqual(inputs, [])
        self.assertFalse(ecmd.called)

        # Merge streams with 3 conversions, should return those three
        streams = [{'input': 'input.mkv', 'index': 0},
                   {'input': 'audio-1.mp3', 'index': 0, 'language': 'jap'},
                   {'input': 'input.mkv', 'index': 2, 'language': 'eng'},
                   {'input': 'subtitle-3.srt', 'index': 0, 'language': 'eng'},
                   {'input': 'subtitle-4.srt', 'index': 0, 'language': 'spa'}]
        res = processor.merge(streams)
        self.assertEqual(res, ['audio-1.mp3', 'subtitle-3.srt', 'subtitle-4.srt'])
        cmd = ['ffmpeg', '-i', 'input.mkv', '-i', 'audio-1.mp3', '-i', 'subtitle-3.srt',
               '-i', 'subtitle-4.srt', '-map', '0:0', '-map', '1:0', '-map', '0:2',
               '-map', '2:0', '-map', '3:0', '-metadata:s:1', 'language=jap',
               '-metadata:s:2', 'language=eng', '-metadata:s:3', 'language=eng',
               '-metadata:s:4', 'language=spa', '-c', 'copy', 'output.mkv']
        ecmd.assert_called_once_with(cmd)
        ecmd.reset_mock()

        # Do the same without output, should do the same but use tmp.mkv as output
        processor.output = None
        cmd[-1] = 'tmp.mkv'
        res = processor.merge(streams)
        self.assertEqual(res, ['audio-1.mp3', 'subtitle-3.srt', 'subtitle-4.srt'])
        self.assertEqual(processor.error, None)
        ecmd.assert_called_once_with(cmd)
        ecmd.reset_mock()

        # Simulate failure, should add output to cleanup and update error
        ecmd.side_effect = ValueError('Something failed')
        res = processor.merge(streams)
        self.assertEqual(res, ['audio-1.mp3', 'subtitle-3.srt', 'subtitle-4.srt', 'tmp.mkv'])
        self.assertEqual(type(processor.error), ValueError)