<s> import os <EOL> import shutil <EOL> import subprocess <EOL> import math <EOL> from butterflow . settings import default as settings <EOL> def extract_audio_with_spd ( src , dst , ss , to , spd = <NUM_LIT:1.0> ) : <EOL> fname = os . path . splitext ( os . path . basename ( dst ) ) [ <NUM_LIT:0> ] <EOL> tempfile1 = os . path . join ( settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' . format ( fname , settings [ '<STR_LIT>' ] ) . <EOL> lower ( ) ) <EOL> call = [ <EOL> settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , src , <EOL> '<STR_LIT>' , str ( ss / <NUM_LIT> ) , <EOL> '<STR_LIT>' , str ( to / <NUM_LIT> ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> if settings [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> call . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> call . extend ( [ <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> tempfile1 ] ) <EOL> if subprocess . call ( call ) == <NUM_LIT:1> : <EOL> raise RuntimeError <EOL> tempfile2 = os . path . join ( settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' . format ( fname , spd , <EOL> settings [ '<STR_LIT>' ] ) ) <EOL> atempo_chain = [ ] <EOL> for f in mk_product_chain ( spd , <NUM_LIT:0.5> , <NUM_LIT> ) : <EOL> atempo_chain . append ( '<STR_LIT>' . format ( f ) ) <EOL> call = [ <EOL> settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , tempfile1 , <EOL> '<STR_LIT>' , '<STR_LIT:U+002C>' . join ( atempo_chain ) ] <EOL> if settings [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> call . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> call . extend ( [ <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> tempfile2 ] ) <EOL> if subprocess . call ( call ) == <NUM_LIT:1> : <EOL> raise RuntimeError <EOL> os . remove ( tempfile1 ) <EOL> shutil . move ( tempfile2 , dst ) <EOL> def concat_av_files ( dst , files ) : <EOL> tempfile = os . path . join ( settings [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> with open ( tempfile , '<STR_LIT:w>' ) as f : <EOL> for file in files : <EOL> f . write ( '<STR_LIT>' . format ( file ) ) <EOL> call = [ <EOL> settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:0>' , <EOL> '<STR_LIT>' , tempfile , <EOL> '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> dst ] <EOL> if subprocess . call ( call ) == <NUM_LIT:1> : <EOL> raise RuntimeError <EOL> os . remove ( tempfile ) <EOL> def mux_av ( vid , audio , dst ) : <EOL> tempfile = '<STR_LIT>' . format ( os . path . splitext ( os . path . basename ( vid ) ) [ <NUM_LIT:0> ] , <EOL> os . path . splitext ( os . path . basename ( audio ) ) [ <NUM_LIT:0> ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> tempfile = os . path . join ( settings [ '<STR_LIT>' ] , tempfile ) <EOL> call = [ <EOL> settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , settings [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , vid , <EOL> '<STR_LIT>' , audio , <EOL> '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> tempfile ] <EOL> if subprocess . call ( call ) == <NUM_LIT:1> : <EOL> raise RuntimeError <EOL> shutil . move ( tempfile , dst ) <EOL> def mk_product_chain ( prd , min , max ) : <EOL> if prd >= min and prd <= max : <EOL> return [ prd ] <EOL> def solve ( prd , limit ) : <EOL> vals = [ ] <EOL> x = int ( math . log ( prd ) / math . log ( limit ) ) <EOL> for i in range ( x ) : <EOL> vals . append ( limit ) <EOL> y = float ( prd ) / math . pow ( limit , x ) <EOL> vals . append ( y ) <EOL> return vals <EOL> if prd < min : <EOL> return solve ( prd , min ) <EOL> else : <EOL> return solve ( prd , max ) </s>
