コード例 #1
0
ファイル: test_file.py プロジェクト: drautb/haystack
 def test_it_should_tell_the_truth_about_MP4_files(self):
     test_file = File('/path/to/file.MP4')
     self.assertFalse(test_file.is_image())
     self.assertTrue(test_file.is_video())
     self.assertEqual(test_file.filename(), '/path/to/file.MP4')
     self.assertEqual(test_file.ext(), '.mp4')
     self.assertEqual(test_file.media_type(), 'MP4')
     self.assertEqual(test_file.date_taken_tag(), 'QuickTime:CreateDate')
     self.assertEqual(test_file.rotation_tag(), 'Composite:Rotation')
コード例 #2
0
ファイル: test_file.py プロジェクト: drautb/haystack
 def test_it_should_tell_the_truth_about_MTS_files(self):
     test_file = File('/path/to/file.MTS')
     self.assertFalse(test_file.is_image())
     self.assertTrue(test_file.is_video())
     self.assertEqual(test_file.filename(), '/path/to/file.MTS')
     self.assertEqual(test_file.ext(), '.mts')
     self.assertEqual(test_file.media_type(), 'MTS')
     self.assertEqual(test_file.date_taken_tag(), 'H264:DateTimeOriginal')
     self.assertEqual(test_file.rotation_tag(), 'Composite:Rotation')
コード例 #3
0
ファイル: test_file.py プロジェクト: drautb/haystack
 def test_it_should_tell_the_truth_about_JPEG_files(self):
     test_file = File('/path/to/file.JPEG')
     self.assertTrue(test_file.is_image())
     self.assertFalse(test_file.is_video())
     self.assertEqual(test_file.filename(), '/path/to/file.JPEG')
     self.assertEqual(test_file.ext(), '.jpeg')
     self.assertEqual(test_file.media_type(), 'JPEG')
     self.assertEqual(test_file.date_taken_tag(), 'EXIF:DateTimeOriginal')
     self.assertEqual(test_file.rotation_tag(), 'EXIF:Orientation')
コード例 #4
0
    def generate_thumbnail(self, path_to_file, path_to_thumbnail):
        thumbnail_dir = os.path.dirname(path_to_thumbnail)
        if not os.path.isdir(thumbnail_dir):
            self.util.mkdirp(thumbnail_dir)

        thumbnail_size = self.config.thumbnail_size()
        f = File(path_to_file)

        if f.is_image():
            original_image = Image.open(path_to_file)
            original_image.thumbnail((thumbnail_size, thumbnail_size), Image.ANTIALIAS)
            original_image.save(path_to_thumbnail)
        elif f.is_video():
            ffmpeg_cmd = ['ffmpeg', '-y', '-i', path_to_file, '-vframes', '1', '-ss', '0', '-vf',
                          'scale=\'if(gte(iw,ih),' + str(thumbnail_size) + ',-1)\':\'if(gte(iw,ih),-1,' +
                          str(thumbnail_size) + ')\'', path_to_thumbnail]
            self.executor.execute(ffmpeg_cmd)
        else:
            raise RuntimeError('Unrecognized file extension!')
コード例 #5
0
ファイル: preprocessor.py プロジェクト: drautb/haystack
    def preprocess(self, path_to_file):
        f = File(path_to_file)
        if not f.is_image():
            logging.info('File is not an image, skipping preprocessing. path_to_file=%s', path_to_file)
            return

        image = Image.open(path_to_file)
        if EXIF_KEY not in image.info:
            logging.warn('Image does not have EXIF information, skipping preprocessing. path_to_file=%s', path_to_file)
            return

        exif_data = image.info['exif']
        rotation = self.metadata_helper.get_rotation(path_to_file)

        logging.info('Preprocessing file. path_to_file=%s rotation=%d', path_to_file, rotation)

        if rotation == 2:
            image = image.transpose(Image.FLIP_LEFT_RIGHT)
        elif rotation == 3:
            image = image.transpose(Image.ROTATE_180)
        elif rotation == 4:
            image = image.transpose(Image.FLIP_TOP_BOTTOM)
        elif rotation == 5:
            image = image.transpose(Image.FLIP_LEFT_RIGHT)
            image = image.transpose(Image.ROTATE_90)
        elif rotation == 6:
            image = image.transpose(Image.ROTATE_270)
        elif rotation == 7:
            image = image.transpose(Image.ROTATE_90)
            image = image.transpose(Image.FLIP_LEFT_RIGHT)
        elif rotation == 8:
            image = image.transpose(Image.ROTATE_90)

        image.save(path_to_file, exif=exif_data)

        logging.info('File has been processed, setting orientation to 1. path_to_file=%s', path_to_file)
        self.metadata_helper.set_rotation(path_to_file, 1)