def main(): curlCmd = 'curl -s -A KPeerClient "$url" -o "$output"' wgetCmd = 'wget -q -U KPeerClient --tries 1 "$url" -O "$output"' vlcPath, webCmdDefault = getDefaultLocations(curlCmd, wgetCmd) vlcCmdDefault = vlcPath + ' --file-caching $cache $debug - vlc://quit' options, args = parseOptions(vlcCmdDefault, webCmdDefault) # Printing out parameters logging.debug('Email: %s', options.email) logging.debug('Password: %s', options.password) logging.debug('Mode: %s', options.mode) logging.debug('Quality: %s', options.quality) logging.debug('VlcCmd: %s', options.vlcCmd) logging.debug('WebCmd: %s', options.webCmd) # Stopping if email and password are defaults found in *.sh/command/cmd if options.email == '*****@*****.**' and options.password == 'PASSWORD': errMsg = 'Enter your GOMtv email and password into your *.sh, *.command, or *.cmd file.' errMsg = errMsg + '\nThis script will not work correctly without a valid account.' logging.error(errMsg) sys.exit(1) g = GOMPlayer(options.email, options.password) # Seeing if we're running the latest version of GOMstreamer g.checkForUpdate() if options.mode == 'scheduled-play': # Delaying execution until necessary delay(options.kt) # Sign in g.signIn() # Get all streams options.quality, urls = g.getStreams(options.quality,options.streamChoice) numberOfStreams = len(urls) # Put variables into VLC command vlcCmd = Template(options.vlcCmd).substitute( {'cache': options.cache, 'debug' : ('', '--verbose=2')[debug]}) # Create shell commands cmds = [] for i in range(numberOfStreams): url = urls[i]['url'] webCmd = Template(options.webCmd).substitute( {'url' : url, 'output' : '-'}) # Add verbose output for VLC if we are debugging if debug: webCmd = webCmd + ' -v' # When playing, pipe wget/curl into VLC # We have already substituted $output with correct target. cmds.append(webCmd + ' | ' + vlcCmd) if numberOfStreams > 1: logging.info('Stream URLs: %s' % urls) logging.info('Commands: %s' % cmds) else: logging.info('Stream URL: %s' % urls[0]) logging.info('Command: %s' % cmds[0]) if options.mode == 'play': if numberOfStreams > 1: print 'Playing streams...' else: print 'Playing stream...' elif options.mode == 'dumpURLs': for url in urls: print url else: print 'Playing stream...' if options.mode == 'dumpURLs': sys.exit(0) # Executing command procs = [] try: for i in range(numberOfStreams): procs.append(subprocess.Popen(cmds[i], shell = True)) for i in range(numberOfStreams): procs[i].wait() except KeyboardInterrupt: # Swallow it, we are terminating anyway and don't want a stack trace. for i in range(numberOfStreams): procs[i].kill() except OSError: # If wget/curl fails to grab the stream, give up for i in range(numberOfStreams): procs[i].kill() finally: sys.exit(0)