Пример #1
0
def get_image_from_audio(audio, node=None, preset_id=None, max_num_of_points=None):
    ext = file_formats.PNG
    cmap_options = {'name': 'BuPu', 'vmin': 0.3, 'vmax': 0.7, 'color': 'black'}
    with tempfile.NamedTemporaryFile(suffix=".{}".format(ext)) as tempf:
        tempf.close()
        create_waveform_image(audio.file_on_disk.name, tempf.name, max_num_of_points=max_num_of_points, colormap_options=cmap_options)
        with open(tempf.name, 'rb') as tf:
            return create_file_from_contents(tf.read(), ext=ext, node=node, preset_id=preset_id)
Пример #2
0
def get_image_from_audio(audio, node=None, preset_id=None, max_num_of_points=None):
    ext = file_formats.PNG
    cmap_options={'name': 'BuPu', 'vmin': 0.3, 'vmax': 0.7, 'color': 'black'}
    with tempfile.NamedTemporaryFile(suffix=".{}".format(ext)) as tempf:
        tempf.close()
        create_waveform_image(audio.file_on_disk.name, tempf.name, max_num_of_points=max_num_of_points, colormap_options=cmap_options)
        with open(tempf.name, 'rb') as tf:
            return create_file_from_contents(tf.read(), ext=ext, node=node, preset_id=preset_id)
Пример #3
0
def get_image_from_audio(audio, node=None, preset_id=None, max_num_of_points=None):
    ext = file_formats.PNG
    cmap_options = {'name': 'BuPu', 'vmin': 0.3, 'vmax': 0.7, 'color': 'black'}
    with tempfile.NamedTemporaryFile(suffix=".{}".format(ext)) as tempf, \
            tempfile.NamedTemporaryFile(suffix=".{}".format(audio.file_format.extension)) as localtempf:
        # localtempf is where we store the file in case it's in object storage
        shutil.copyfileobj(audio.file_on_disk, localtempf)
        tempf.close()
        localtempf.flush()
        create_waveform_image(localtempf.name, tempf.name, max_num_of_points=max_num_of_points, colormap_options=cmap_options)
        with open(tempf.name, 'rb') as tf:
            return create_file_from_contents(tf.read(), ext=ext, node=node, preset_id=preset_id, uploaded_by=audio.uploaded_by)
Пример #4
0
def get_image_from_audio(audio, node=None, preset_id=None, max_num_of_points=None):
    ext = file_formats.PNG
    cmap_options = {'name': 'BuPu', 'vmin': 0.3, 'vmax': 0.7, 'color': 'black'}
    with tempfile.NamedTemporaryFile(suffix=".{}".format(ext)) as tempf, \
            tempfile.NamedTemporaryFile(suffix=".{}".format(audio.file_format.extension)) as localtempf:
        # localtempf is where we store the file in case it's in object storage
        shutil.copyfileobj(audio.file_on_disk, localtempf)
        tempf.close()
        localtempf.flush()
        create_waveform_image(localtempf.name, tempf.name, max_num_of_points=max_num_of_points, colormap_options=cmap_options)
        with open(tempf.name, 'rb') as tf:
            return create_file_from_contents(tf.read(), ext=ext, node=node, preset_id=preset_id, uploaded_by=audio.uploaded_by)
    def test_generates_thumbnail(self, tmpdir):
        input_file = os.path.join(files_dir, 'Wilhelm_Scream.mp3')

        assert os.path.exists(input_file)

        thumbnail_name = 'Wilhelm_Screen_thumbnail.png'

        output_path = tmpdir.join(thumbnail_name)
        output_file = output_path.strpath
        images.create_waveform_image(input_file,
                                     output_file,
                                     colormap_options=studio_cmap_options)

        assert os.path.exists(output_file)
Пример #6
0
 def extractor_fun(self, fpath_in, thumbpath_out, **kwargs):
     create_waveform_image(fpath_in, thumbpath_out, **kwargs)
Пример #7
0
 def test_raises_for_invalid_mp3(self, tmpdir, bad_audio_file):
     input_file = bad_audio_file.name
     output_file = tmpdir.join('thumbnail.png').strpath
     with pytest.raises(images.ThumbnailGenerationError):
         images.create_waveform_image(input_file, output_file, colormap_options=studio_cmap_options)
Пример #8
0
 def test_raises_for_missing_file(self, tmpdir):
     input_file = os.path.join(files_dir, 'file_that_does_not_exist.mp3')
     assert not os.path.exists(input_file)
     output_file = tmpdir.join('thumbnail.png').strpath
     with pytest.raises(images.ThumbnailGenerationError):
         images.create_waveform_image(input_file, output_file, colormap_options=studio_cmap_options)
Пример #9
0
 def test_generates_16_9_thumbnail(self, tmpdir):
     input_file = os.path.join(files_dir, 'Wilhelm_Scream.mp3')
     assert os.path.exists(input_file)
     output_file = tmpdir.join('Wilhelm_Screen_thumbnail.png').strpath
     images.create_waveform_image(input_file, output_file, colormap_options=studio_cmap_options)
     self.check_16_9_format(output_file)