def test_AudioFile(self): mp3_fpath = join(tests_dir, 'test_data/music/test_us_and_them_short.mp3') audio = pydoni.AudioFile(mp3_fpath) # Method: compress() mp3_output = pydoni.append_filename_suffix(mp3_fpath, '-COMPRESSED') if isfile(mp3_output): remove(mp3_output) audio.compress(output_fpath=mp3_output) self.assertTrue(isfile(mp3_output)) if isfile(mp3_output): remove(mp3_output) # Method: join() and get_duration() and export() (embedded within get_duration()) mp3_fpath1 = join(tests_dir, 'test_data/music/test_us_and_them_short_first_half.m4a') mp3_fpath2 = join(tests_dir, 'test_data/music/test_us_and_them_short_second_half.m4a') audio = pydoni.AudioFile(mp3_fpath1) expected_output_fpath = pydoni.append_filename_suffix(mp3_fpath1, '-JOINED') if isfile(expected_output_fpath): remove(expected_output_fpath) audio.join(additional_audio_files=mp3_fpath2, output_fpath=expected_output_fpath) self.assertTrue(isfile(expected_output_fpath)) audio = pydoni.AudioFile(expected_output_fpath) duration = audio.get_duration() expected_duration = 85 self.assertEqual(int(duration), expected_duration) if isfile(expected_output_fpath): remove(expected_output_fpath) # Method: convert() m4a_fpath = join(tests_dir, 'test_data/music/test_us_and_them_short.m4a') mp3_output = splitext(m4a_fpath)[0] + '-CONVERTED.mp3' if isfile(mp3_output): remove(mp3_output) audio = pydoni.AudioFile(m4a_fpath) audio.convert(output_fpath=mp3_output, output_format='mp3') self.assertTrue(isfile(mp3_output)) if isfile(mp3_output): remove(mp3_output)
def join_files(fpath, output_fpath, verbose, notify): """ Concatenate multiple audio files with FFmpeg. """ args, result = pydoni.__pydonicli_declare_args__(locals()), dict() assert len(fpath) > 1, 'Must pass more than one file to join!' vb = Verbose(verbose) fpaths = list(fpath) vb.info( f'Joining {len(fpaths)-1} additional audio files onto base file "{fpaths[0]}"...' ) if output_fpath is None: output_fpath = pydoni.append_filename_suffix(fpaths[0], '-JOINED') audio = pydoni.AudioFile(audio_fpath=fpaths[0]) ffmpeg_output = audio.join(additional_audio_files=fpaths[1:], output_fpath=output_fpath) vb.info(f'Output audiofile created "{output_fpath}"') if notify: pydoni.macos_notify(title='Audiofile Join Complete!') outfile_size_in_bytes = stat(output_fpath).st_size result = dict(joined_files=fpaths, output_fpath=output_fpath, outfile_size_in_bytes=outfile_size_in_bytes, ffmpeg_output=ffmpeg_output) pydoni.__pydonicli_register__( dict(args=args, result=result, command_name='audio.join_files'))
def test_make_meme(self): img_fpath = join(tests_dir, "test_data/img/test_whats_the_scuttlebutt.png") expected_img = pydoni.append_filename_suffix(img_fpath, '-MEME') pydoni.make_meme(img_fpath=img_fpath, output_fpath=expected_img, msg="What's the scuttlebutt?", msg_color='white', msg_pos='bottom', msg_outline_color='black', msg_outline_width=3, font_path='/System/Library/Fonts/HelveticaNeue.ttc', font_size=200, repel_from_edge=.05) if isfile(expected_img): remove(expected_img)
def test_audio_compress(self): mp3_fpath = join(tests_dir, 'test_data/music/test_us_and_them_short.mp3') # Suffix must match suffix set by default in pydoni.Audio.compress source code # when `output_fpath` is None expected_output_fpath = pydoni.append_filename_suffix( mp3_fpath, '-COMPRESSED') if isfile(expected_output_fpath): remove(expected_output_fpath) args = ['--fpath', mp3_fpath, '--verbose'] result = runner.invoke(compress, args) self.assertEqual(result.exit_code, 0) self.assertTrue(isfile(expected_output_fpath)) if isfile(expected_output_fpath): remove(expected_output_fpath)
def test_audio_join_files(self): mp3_fpath1 = join( tests_dir, 'test_data/music/test_us_and_them_short_first_half.m4a') mp3_fpath2 = join( tests_dir, 'test_data/music/test_us_and_them_short_second_half.m4a') expected_output_fpath = pydoni.append_filename_suffix( mp3_fpath1, '-JOINED') if isfile(expected_output_fpath): remove(expected_output_fpath) args = [ '--fpath', mp3_fpath1, '--fpath', mp3_fpath2, '--output-fpath', expected_output_fpath, '--verbose' ] result = runner.invoke(join_files, args) self.assertEqual(result.exit_code, 0) self.assertTrue(isfile(expected_output_fpath)) if isfile(expected_output_fpath): remove(expected_output_fpath)
def test_append_filename_suffix(self): txt_fpath = expanduser('~/Desktop/test_file.txt') expectation = expanduser('~/Desktop/test_file-1.txt') # Doesn't actually create or expect a file on Desktop self.assertEqual(pydoni.append_filename_suffix(fpath=txt_fpath, suffix='-1'), expectation)