Пример #1
0
 def codec(self):
     """
     Get codec for file based on filename extension
     """
     from oodi.codecs.utils import detect_file_codec
     if self.format:
         codecs = self.configuration.codecs.codecs
         for codec in codecs:
             if codec.format == self.format:
                 return codec
         raise LibraryError('Unknown format: {}'.format(self.format))
     elif self.extension:
         codecs = self.configuration.codecs.find_codecs_for_extension(
             self.extension)
         if len(codecs) == 1:
             return codecs[0]
         else:
             tree = self.tree
             if tree is not None:
                 return tree.codec
             else:
                 self.format = detect_file_codec(self.path)
                 if self.format is not None:
                     codecs = self.configuration.codecs.codecs
                     for codec in codecs:
                         if codec.format == self.format:
                             return codec
                 raise LibraryError(
                     'Extension {} matches multiple codecs'.format(self))
     else:
         raise LibraryError('Filename has no extension:{}'.format(
             self.path))
Пример #2
0
    def test_encoder_flac(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.flac')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'flac')
Пример #3
0
    def test_encoder_alac(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.exceptions import LibraryError
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.m4a')

        # Raises LibraryError because .alac matches multiple codecs
        with self.assertRaises(LibraryError):
            track = Track(filename, self.configuration)
            output_file = track.encode(self.input_file, remove_input_file=False)

        # Specifying explicit format allows encoding
        track = Track(filename, configuration=self.configuration, format='alac')
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'alac')