def export(links): pan = Pan() for link in links: info = pan.get_dlink(link) if not info.filename and not info.dlink: raise GetFilenameError("无法获取下载地址或文件名!") export_single(info.filename, info.dlink)
def download(args): limit = global_config.limit output_dir = global_config.dir parser = argparse.ArgumentParser(description="download command arg parser") parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.") parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.") parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="") if not args: parser.print_help() exit(1) namespace, links = parser.parse_known_args(args) secret = namespace.secret if namespace.limit: limit = namespace.limit if namespace.output_dir: output_dir = namespace.output_dir # if is wap links = [link.replace("wap/link", "share/link") for link in links] # add 'http://' links = map(add_http, links) for url in links: res = parse_url(url) # normal if res.get('type') == 1: pan = Pan() info = pan.get_dlink(url, secret) cookies = 'BDUSS={0}'.format(pan.bduss) download_command(info.filename, info.dlink, cookies=cookies, limit=limit, output_dir=output_dir) # album elif res.get('type') == 2: raise NotImplementedError('This function has not implemented.') # home elif res.get('type') == 3: raise NotImplementedError('This function has not implemented.') elif res.get('type') == 0: logger.debug(url, extra={"type": "wrong link", "method": "None"}) continue else: continue sys.exit(0)
def download(args): limit = global_config.limit output_dir = global_config.dir parser = argparse.ArgumentParser(description="download command arg parser") parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.") parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.") parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="") if not args: parser.print_help() exit(1) namespace, links = parser.parse_known_args(args) secret = namespace.secret if namespace.limit: limit = namespace.limit if namespace.output_dir: output_dir = namespace.output_dir # if is wap links = [link.replace("wap/link", "share/link") for link in links] # add 'http://' links = map(add_http, links) for url in links: res = parse_url(url) # normal if res.get('type') == 1: pan = Pan() info = pan.get_dlink(url, secret) cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' download_command(info.filename, info.dlink, cookies=cookies, limit=limit, output_dir=output_dir) elif res.get('type') == 4: pan = Pan() fsid = res.get('fsid') newUrl = res.get('url') info = pan.get_dlink(newUrl, secret, fsid) cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' download_command(info.filename, info.dlink, cookies=cookies, limit=limit, output_dir=output_dir) # album elif res.get('type') == 2: raise NotImplementedError('This function has not implemented.') # home elif res.get('type') == 3: raise NotImplementedError('This function has not implemented.') elif res.get('type') == 0: logger.debug(url, extra={"type": "wrong link", "method": "None"}) continue else: continue sys.exit(0)
def show(links): if not len(links): bd_help('show') else: for url in links: pan = Pan() info = pan.get_dlink(url) print(u"{0}\n{1}\n\n".format(info.filename, info.dlink).encode('utf-8')) sys.exit(0)
def export(links): for link in links: pan = Pan(link) count = 1 while count != 0: link, filename, count = pan.info if not filename and not link: raise GetFilenameError("无法获取下载地址或文件名!") export_single(filename, link)
def show(links): if not len(links): bd_help('show') else: for url in links: pan = Pan(url) count = 1 while count != 0: link, filename, count = pan.info print "%s\n%s\n\n" % (filename, link) sys.exit(0)
def show(links): if not len(links): bd_help('show') else: for url in links: pan = Pan(url) count = 1 while count != 0: link, filename, count = pan.info print("{0}\n{1}\n\n".format(filename, link)) sys.exit(0)
def download(args): limit = global_config.limit output_dir = global_config.dir parser = argparse.ArgumentParser(description="download command arg parser") parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.") parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.") parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="") parser.add_argument('-P', '--partial', action="count", help="Partial download.") if not args: parser.print_help() exit(1) namespace, links = parser.parse_known_args(args) secret = namespace.secret if namespace.limit: limit = namespace.limit if namespace.output_dir: output_dir = namespace.output_dir # if is wap links = [link.replace("wap/link", "share/link") for link in links] # add 'http://' links = map(add_http, links) for url in links: res = parse_url(url) # normal if res.get('type') == 1: pan = Pan() fis = pan.get_file_infos(url, secret) if namespace.partial: while True: fis = select_download(fis) if fis is not None: break for fi in fis: cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' savedir = fi.path.replace(fi.parent_path, '', 1)[1:] download_command(fi.filename, savedir, fi.dlink, cookies=cookies, limit=limit, output_dir=output_dir) elif res.get('type') == 4: pan = Pan() fsid = res.get('fsid') newUrl = res.get('url') infos = pan.get_file_infos(newUrl, secret, fsid) cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' for info in infos: download_command(info.filename, info.dlink, cookies=cookies, limit=limit, output_dir=output_dir) # album elif res.get('type') == 2: raise NotImplementedError('This function has not implemented.') # home elif res.get('type') == 3: raise NotImplementedError('This function has not implemented.') elif res.get('type') == 0: logger.debug(url, extra={"type": "wrong link", "method": "None"}) continue else: continue sys.exit(0)
def download(args): limit = global_config.limit output_dir = global_config.dir parser = argparse.ArgumentParser(description="download command arg parser") parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.") parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.") parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="") if not args: parser.print_help() exit(1) namespace, links = parser.parse_known_args(args) secret = namespace.secret if namespace.limit: limit = namespace.limit if namespace.output_dir: output_dir = namespace.output_dir # if is wap links = [link.replace("wap/link", "share/link") for link in links] links = map(add_http, links) # add 'http://' for url in links: res = parse_url(url) # normal if res.get('type') == 1: pan = Pan(url, secret=secret) count = 1 while count != 0: link, filename, count = pan.info download_command(filename, link, limit=limit, output_dir=output_dir) # album elif res.get('type') == 2: album_id = res.get('album_id') uk = res.get('uk') album = Album(album_id, uk) count = 1 while count != 0: link, filename, count = album.info download_command(filename, link, limit=limit, output_dir=output_dir) # home elif res.get('type') == 3: raise NotImplementedError('This function has not implemented.') elif res.get('type') == 0: logging.debug(url) continue else: continue sys.exit(0)
def download(args): limit = global_config.limit output_dir = global_config.dir parser = argparse.ArgumentParser(description="download command arg parser") parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.") parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.") parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="") parser.add_argument('-P', '--partial', action="count", help="Partial download.") parser.add_argument('-E', '--extension', action="store", dest='extension', help="Download only specified by the extension. e.g. aw3") if not args: parser.print_help() exit(1) namespace, links = parser.parse_known_args(args) secret = namespace.secret if namespace.limit: limit = namespace.limit if namespace.output_dir: output_dir = namespace.output_dir extension = namespace.extension # if is wap links = [link.replace("wap/link", "share/link") for link in links] # add 'http://' links = map(add_http, links) for url in links: res = parse_url(url) # normal if res.get('type') == 1: pan = Pan() fis = pan.get_file_infos(url, secret) if namespace.partial: while True: fis = select_download(fis) if fis is not None: break for fi in fis: if extension and not matchExtension(fi.filename, extension): print('{filename} is igonred'.format(filename=fi.filename)) continue cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' savedir = fi.path.replace(fi.parent_path, '', 1)[1:] download_command(fi.filename, savedir, fi.dlink, cookies=cookies, limit=limit, output_dir=output_dir) elif res.get('type') == 4: pan = Pan() fsid = res.get('fsid') newUrl = res.get('url') infos = pan.get_file_infos(newUrl, secret, fsid) cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' for info in infos: if extension and not matchExtension(info.filename, extension): print('{filename} is ignored'.format(filename=info.filename)) continue download_command(info.filename, info.dlink, cookies=cookies, limit=limit, output_dir=output_dir) # album elif res.get('type') == 2: raise NotImplementedError('This function has not implemented.') # home elif res.get('type') == 3: raise NotImplementedError('This function has not implemented.') elif res.get('type') == 0: logger.debug(url, extra={"type": "wrong link", "method": "None"}) continue else: continue sys.exit(0)
def download(args): limit = global_config.limit output_dir = global_config.dir dl_all = global_config.dl_all link_file = global_config.link_file parser = argparse.ArgumentParser(description="download command arg parser") parser.add_argument('-L', '--limit', action="store", dest='limit', help="Max download speed limit.") parser.add_argument('-D', '--dir', action="store", dest='output_dir', help="Download task to dir.") parser.add_argument('-F', '--file', action="store", dest='link_file', help="Get list from file.") parser.add_argument('-S', '--secret', action="store", dest='secret', help="Retrieval password.", default="") parser.add_argument('-A', '--all', action="store_true", dest='dl_all', help="Download all files without asking.", default=False) if not args: parser.print_help() exit(1) namespace, links = parser.parse_known_args(args) secret = namespace.secret if namespace.limit: limit = namespace.limit if namespace.output_dir: output_dir = namespace.output_dir if namespace.link_file: # while using batch mode, automatically download all files. dl_all = True link_file = namespace.link_file if namespace.dl_all: dl_all = namespace.dl_all # get file lists from file. links = get_links_from_file(link_file, "\n") print(links) # if is wap links = [link.replace("wap/link", "share/link") for link in links] # add 'http://' links = map(add_http, links) for url in links: res = parse_url(url) # normal if res.get('type') == 1: pan = Pan() fis = pan.get_file_infos(url, secret) while True: if dl_all: break fis = select_download(fis) if fis is not None: break print(fis) for fi in fis: cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' savedir = fi.path.replace(fi.parent_path, '', 1)[1:] download_command(fi.filename, savedir, fi.dlink, cookies=cookies, limit=limit, output_dir=output_dir) elif res.get('type') == 4: pan = Pan() fsid = res.get('fsid') newUrl = res.get('url') info = pan.get_dlink(newUrl, secret, fsid) cookies = 'BDUSS={0}'.format(pan.bduss) if pan.bduss else '' if cookies and pan.pcsett: cookies += ';pcsett={0}'.format(pan.pcsett) if cookies: cookies += '"' download_command(info.filename, info.dlink, cookies=cookies, limit=limit, output_dir=output_dir) # album elif res.get('type') == 2: raise NotImplementedError('This function has not implemented.') # home elif res.get('type') == 3: raise NotImplementedError('This function has not implemented.') elif res.get('type') == 0: logger.debug(url, extra={"type": "wrong link", "method": "None"}) continue else: continue sys.exit(0)