Example #1
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)
Example #2
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)
Example #3
0
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)
Example #4
0
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)
Example #5
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)
Example #6
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)
Example #7
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)