<s> import os . path <EOL> import subprocess <EOL> def get_usable_rtmpdump ( cmd ) : <EOL> try : <EOL> p = subprocess . Popen ( [ cmd ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> out , err = p . communicate ( ) <EOL> return cmd <EOL> except : <EOL> return None <EOL> RTMPDUMP = get_usable_rtmpdump ( '<STR_LIT>' ) <EOL> def has_rtmpdump_installed ( ) : <EOL> return RTMPDUMP is not None <EOL> def download_rtmpdump_stream ( url , title , ext , params = { } , output_dir = '<STR_LIT:.>' ) : <EOL> filename = '<STR_LIT>' % ( title , ext ) <EOL> filepath = os . path . join ( output_dir , filename ) <EOL> cmdline = [ RTMPDUMP , '<STR_LIT>' ] <EOL> cmdline . append ( url ) <EOL> cmdline . append ( '<STR_LIT>' ) <EOL> cmdline . append ( filepath ) <EOL> for key in params . keys ( ) : <EOL> cmdline . append ( key ) <EOL> if params [ key ] != None : <EOL> cmdline . append ( params [ key ] ) <EOL> print ( "<STR_LIT>" + "<STR_LIT:U+0020>" . join ( cmdline ) + "<STR_LIT:\n>" ) <EOL> subprocess . call ( cmdline ) <EOL> return <EOL> def play_rtmpdump_stream ( player , url , params = { } ) : <EOL> cmdline = "<STR_LIT>" % url <EOL> for key in params . keys ( ) : <EOL> cmdline += key + "<STR_LIT:U+0020>" + params [ key ] if params [ key ] != None else "<STR_LIT>" + "<STR_LIT:U+0020>" <EOL> cmdline += "<STR_LIT>" % player <EOL> print ( cmdline ) <EOL> os . system ( cmdline ) <EOL> return </s>
