def do_play(self, line): "Try to play this video using mplayer (stream from stdin)" if platform.system() == 'Windows': print "!! No streaming support on Windows, sorry. Try 'get' instead." return d = self._getd(line) if d is None: print "!! Error calling play with argument: %s" % line return res = None if 'processor' in d and 'URL' in d: res = scraper.navix_get(d['processor'], d['URL'], verbose=0) elif 'URL' in d: res = urllib.urlopen(request(d['URL'])) if res: mplayer = Popen(['mplayer', '-cache-min', '5', '-noconsolecontrols', '-cache', '2048', '/dev/stdin'], stdin=PIPE) while True: bytes = res.read(16384) if not bytes: break try: mplayer.stdin.write(bytes) except: res.close() break mplayer.stdin.close() else: print "Missing some info required to play"
def do_geturl(self, line): "geturl <filename>;<url>;<processor url>: download a URL using the given processor URL" try: filename, url, proc = line.split(";", 2) except: print "Usage: geturl filename;url;processor" return try: res = scraper.navix_get(proc.strip(), url.strip(), verbose=0) download(res, filename.strip()) except: traceback.print_exc()
def do_get(self, line): "get <num> [to/as <filename>]: download the specified item" fname = None if re.search('\d+ (to|as) .+', line): line, fname = line.split(' to ', 1) d = self._getd(line) if d is None: print "!! Error calling get with argument: %s" % line return if 'URL' in d and 'name' in d: if fname: if '/' not in fname: fname = os.path.abspath(os.path.join(DOWNLOADPATH, fname)) else: fname = d['name'] # cleanup filename fname = fname.rsplit("/",1)[-1].replace(" ","_") + ".EXT" fname = re.sub(r"&|[;:()\/&\[\]*%#@!?]", "_", fname) fname = re.sub(r"__+","_", fname) fname = re.sub(r"\.\.+",".", fname) fname = fname.replace("_.", ".") fname = os.path.join(DOWNLOADPATH, fname) if os.path.exists(fname): byterange = "Range: bytes=%s-" % (os.path.getsize(fname)+1) else: byterange = None try: if 'processor' in d: res = scraper.navix_get(d['processor'], d['URL'], byterange=byterange, verbose=0) else: browser = scraper.Browser() if byterange: res = browser.get(d['URL'], Range=byterange) else: res = browser.get(d['URL']) if not res: print "Could not download %s" % (d) # guess extension if fname.endswith(".EXT"): ext = guess_extension(res) if ext: fname = fname[:-4] + ext # download the sucker print "Downloading %s" % (res.geturl()) download(res, fname) except: traceback.print_exc()