Пример #1
0
def main(args=None):
    p=argparse.ArgumentParser()
    p.add_argument("url", help="Torrent file, link to file or magnet link")
    p.add_argument("-d", "--directory", default="./", help="directory to save download files")
    p.add_argument("-p", "--player", default="mplayer", choices=["mplayer","vlc", "mpv"], help="Video player")
    p.add_argument("--player-path", default=None, help="Video player path")
    p.add_argument("--port", type=int, default=5001, help="Port for http server")
    p.add_argument("--debug-log", default='',help="File for debug logging")
    p.add_argument("--stdin", action='store_true', help='sends video to player via stdin (no seek then)')
    p.add_argument("--print-pieces", action="store_true", help="Prints map of downloaded pieces and ends (X is downloaded piece, O is not downloaded)")
    p.add_argument("-s", "--subtitles", action=LangAction, help="language for subtitle 3 letter code eng,cze ... (will try to get subtitles from opensubtitles.org)")
    p.add_argument("--stream", action="store_true", help="just file streaming, but will not start player")
    p.add_argument("--no-resume", action="store_true",help="Do not resume from last known position")
    p.add_argument("-q", "--quiet", action="store_true", help="Quiet - did not print progress to stdout")
    p.add_argument('--delete-on-finish', action="store_true", help="Delete downloaded file when program finishes")
    p.add_argument('--clear-older', type=int, default=0, help="Deletes files older then x days from download directory, if set will slowdown start of client")
    p.add_argument('--bt-download-limit', type=int, default=0, help='Download limit for torrents kB/s')
    p.add_argument('--bt-upload-limit', type=int, default=0, help='Upload limit for torrents kB/s')
    p.add_argument('--listen-port-min', type=int, default=6881, help='Bitorrent input port range - minimum port')
    p.add_argument('--listen-port-max', type=int, default=6891, help='Bitorrent input port range - maximum port')
    p.add_argument('--choose-subtitles',  action="store_true", help="Always manually choose subtitles (otherwise will try to use best match in many cases)" )
    p.add_argument('--trace', action='store_true', help='More detailed debug logging')
    p.add_argument('--choose-file', action='store_true', help='Manually choose if there are more video files in torrent (otherwise chooses biggest automatically)')
    args=p.parse_args(args)
    if args.debug_log:
        logger.setLevel(logging.DEBUG)
        h=logging.handlers.RotatingFileHandler(args.debug_log)
        logger.addHandler(h)
    else:
        logger.setLevel(logging.CRITICAL)
        logger.addHandler(logging.StreamHandler())
        
    if args.clear_older:
        days=args.clear_older
        items=os.listdir(args.directory)
        now=time.time()
        for item in items:
            if item!=Cache.CACHE_DIR:
                full_path=os.path.join(args.directory,item)
                if now-os.path.getctime(full_path)>days*24*3600:
                    logger.debug('Deleting path %s',full_path)
                    if os.path.isdir(full_path):
                        shutil.rmtree(full_path,ignore_errors=True)
                    else:
                        os.unlink(full_path)
    
    if args.print_pieces:
        print_pieces(args) 
    elif re.match('https?://localhost', args.url):  
        class TestResolver(Resolver):
            SPEED_LIMIT=300
            THREADS=2
        stream(args, HTClient,TestResolver)
    else: 
        rclass=plugins.find_matching_plugin(args.url)
        if rclass:
            stream(args,HTClient, rclass)
        else:
            stream(args, BTClient)
Пример #2
0
 def test_ulozto(self):
     url='http://www.ulozto.cz/xEtqWa87/jachyme-hod-ho-do-stroje-1974-mp4'
     cls=find_matching_plugin(url)
     try:
         import adecaptcha
         self.assertTrue(cls)
         loader=HTTPLoader(url, 0, cls)
     except ImportError:
         print >>sys.stderr, 'WARNIG - adecaptcha not install ulozto plugin will not be available'
Пример #3
0
 def test_ulozto(self):
     url = 'http://www.ulozto.cz/xEtqWa87/jachyme-hod-ho-do-stroje-1974-mp4'
     cls = find_matching_plugin(url)
     try:
         import adecaptcha
         self.assertTrue(cls)
         loader = HTTPLoader(url, 0, cls)
         loader.init()
     except ImportError:
         print >> sys.stderr, 'WARNIG - adecaptcha not install ulozto plugin will not be available'