Esempio n. 1
0
def main(*args, **kwargs):
    biliapi = bili()
    if path:
        with open(path,'r',encoding='utf-8-sig') as fp:
            userData = load(fp)
        if userData["SESSDATA"] and \
           biliapi.login_by_cookie({"SESSDATA": userData["SESSDATA"]}):
            ...
        elif userData["access_token"] and \
            userData["refresh_token"] and \
            biliapi.login_by_access_token(userData["access_token"], userData["refresh_token"], True):
            userData["SESSDATA"] = biliapi.SESSDATA
            userData["bili_jct"] = biliapi.bili_jct
            userData["access_token"] = biliapi.access_token
            userData["refresh_token"] = biliapi.refresh_token
            with open(path,'w',encoding='utf-8') as fp:
                dump(userData, fp, ensure_ascii=False, indent=4)
        elif userData["username"] and \
            userData["password"] and \
            biliapi.login_by_password(userData["username"], userData["password"]):
            userData["SESSDATA"] = biliapi.SESSDATA
            userData["bili_jct"] = biliapi.bili_jct
            userData["access_token"] = biliapi.access_token
            userData["refresh_token"] = biliapi.refresh_token
            with open(path,'w',encoding='utf-8') as fp:
                dump(userData, fp, ensure_ascii=False, indent=4)
        else:
            print("当前处于未登录状态")
    else:
        print("当前处于未登录状态")

    video_parser = VideoParser(biliapi=biliapi)
    if kwargs["tasklist"]:
        tasks = get_arg_tasks(video_parser, kwargs["tasklist"])
    else:
        tasks = get_input_tasks(video_parser)

    del video_parser
    del biliapi

    if kwargs["ass"]:
        download_danmu(tasks, kwargs["path"])

    downloader = Downloader()
    downloader_put_tasks(downloader, tasks, kwargs["path"])
    downloader.startAll()
    display(downloader)
    print("下载结束")
Esempio n. 2
0
def listLott(cookie, endTime, startTime):
    "返回动态中从startTime到endTime之间的所有抽奖信息,endTime>startTime且endTime最好不要离当前时间太远"

    def lottInfo(lott):
        a = (("first_prize", "second_prize", "third_prize"),
             ("first_prize_cmt", "second_prize_cmt", "third_prize_cmt"),
             ("first_prize_pic", "second_prize_pic", "third_prize_pic"))
        array = []
        for i in range(3):
            if lott[a[0][i]]:
                xx = []
                xx.append(lott[a[1][i]])
                xx.append(str(lott[a[0][i]]))
                if lott[a[2][i]]:
                    xx.append(lott[a[2][i]])
                array.append(xx)
            else:
                break
        return array

    try:
        biliapi = bili()
        biliapi.login_by_cookie(cookie)
    except Exception as e:
        print(f'登录验证id为{data["DedeUserID"]}的账户失败,原因为{str(e)},跳过后续所有操作')
        return
    lottinfo = []
    datas = biliapi.getDynamic()
    for x in datas:
        stime = x["desc"]["timestamp"]
        if (stime > endTime):
            continue
        if (stime < startTime):
            break
        if 'extension' in x and 'lott' in x["extension"]:  #若抽奖标签存在
            uname = x["desc"]["user_profile"]["info"]["uname"]  #动态的主人的用户名
            dyid = x["desc"]["dynamic_id"]  #动态id
            lott = biliapi.getLotteryNotice(dyid)["data"]
            etime = lott["lottery_time"]
            lottinfo.append({
                "name": uname,
                "stime": stime,
                "etime": etime,
                "dyid": dyid,
                "lott": lottInfo(lott)
            })
    return lottinfo
Esempio n. 3
0
def main(*args, **kwargs):
    interactive_mode = not (kwargs["manga"] or kwargs["pdf"])
    biliapi = bili()
    if interactive_mode or kwargs["manga"]:
        if path:
            with open(path, 'r', encoding='utf-8-sig') as fp:
                userData = load(fp)
            if userData["SESSDATA"] and \
               biliapi.login_by_cookie({"SESSDATA": userData["SESSDATA"]}):
                ...
            elif userData["access_token"] and \
                userData["refresh_token"] and \
                biliapi.login_by_access_token(userData["access_token"], userData["refresh_token"], True):
                userData["SESSDATA"] = biliapi.SESSDATA
                userData["bili_jct"] = biliapi.bili_jct
                userData["access_token"] = biliapi.access_token
                userData["refresh_token"] = biliapi.refresh_token
                with open(path, 'w', encoding='utf-8') as fp:
                    dump(userData, fp, ensure_ascii=False, indent=4)
            elif userData["username"] and \
                userData["password"] and \
                biliapi.login_by_password(userData["username"], userData["password"]):
                userData["SESSDATA"] = biliapi.SESSDATA
                userData["bili_jct"] = biliapi.bili_jct
                userData["access_token"] = biliapi.access_token
                userData["refresh_token"] = biliapi.refresh_token
                with open(path, 'w', encoding='utf-8') as fp:
                    dump(userData, fp, ensure_ascii=False, indent=4)
            else:
                print("当前处于未登录状态")
        else:
            print("当前处于未登录状态")

    manga = MangaDownloader(biliapi)
    if interactive_mode:
        download_interactive(manga)
    else:
        if kwargs["manga"]:
            manga.setComicId(kwargs["manga"])
            download_task(manga, kwargs)
            kwargs["path"] = os.path.join(kwargs["path"], manga.getTitle())
        if kwargs["pdf"]:
            print("正在合并下载图片为pdf")
            manga_to_PDF(kwargs["path"], kwargs["split"], kwargs["width"],
                         kwargs["height"])
            print("合并完成")
Esempio n. 4
0
def bili_topic_repost(data, list, time):
    '''转发指定时间段内的话题'''
    alr = []  #记录已经转发的动态用于去重
    try:
        biliapi = bili()
        bili.login_by_cookie(data)
    except Exception as e:
        print(f'登录验证id为{data["DedeUserID"]}的账户失败,原因为{str(e)},跳过后续所有操作')
        return

    if not biliapi.islogin:
        print(f'id为{data["DedeUserID"]}的账户登录失效,跳过后续所有操作')
        return

    for tpn in list:
        topic = biliapi.getTopicList(tpn)
        for x in topic:
            stime = x["desc"]["timestamp"]
            if (stime > time[1]):
                continue
            if (stime < time[0]):
                break
            dyid = x["desc"]["dynamic_id"]
            if dyid in alr:
                continue
            try:
                if islike and x["desc"]["is_liked"] == 0:
                    if biliapi.followed(x["desc"]["uid"])['code'] != 0:
                        print("关注异常")
                biliapi.repost(dyid)
                print(
                    f'id为{data["DedeUserID"]}的账户转发抽奖(用户名:{x["desc"]["user_profile"]["info"]["uname"]},动态id:{dyid})成功'
                )
            except Exception as e:
                print(f'此次转发抽奖失败,原因为{str(e)}')
            else:
                alr.append(dyid)
Esempio n. 5
0
def main(*args, **kwargs):
    with open(path, 'r', encoding='utf-8-sig') as fp:
        userData = load(fp)

    biliapi = bili()
    video_uploader = VideoUploader(biliapi)
    isLogin = False
    if userData["access_token"] and \
        biliapi.login_by_access_token(userData["access_token"], userData["refresh_token"]):
        ...
    elif userData["username"] and \
        userData["password"] and \
        biliapi.login_by_password(userData["username"], userData["password"]):
        userData["access_token"] = biliapi.access_token
        userData["refresh_token"] = biliapi.refresh_token
        with open(path, 'w', encoding='utf-8') as fp:
            dump(userData, fp, ensure_ascii=False, indent=4)
    else:
        print("账户登录失败")
        exit(6)

    if not kwargs["path"]:
        raise ValueError('未提供视频文件路径')
    if kwargs["cover"] and not os.path.exists(kwargs["cover"]):
        raise FileNotFoundError(kwargs["cover"])

    if kwargs["tid"]:
        video_uploader.setTid(kwargs["tid"])
    if kwargs["title"]:
        video_uploader.setTitle(kwargs["title"])
    if kwargs["desc"]:
        video_uploader.setDesc(kwargs["title"])
    if kwargs["nonOriginal"]:
        video_uploader.setCopyright(2)
    else:
        video_uploader.setCopyright(1)
    if kwargs["source"]:
        video_uploader.setSource(kwargs["source"])
    if kwargs["dtime"]:
        video_uploader.setDtime(kwargs["dtime"])

    print('正在上传中.....')
    for v in kwargs["path"]:
        fname, fename = os.path.split(v)
        video_info = video_uploader.uploadFileOneThread(v)
        video_uploader.add(video_info)
        print(f'上传"{fename}"成功')

    if kwargs["cover"]:
        video_uploader.setCover(kwargs["cover"])

    if kwargs["tags"]:
        video_uploader.setTag(kwargs["tags"])
    else:
        video_uploader.setTag(video_uploader.getTags()[0:1])

    result = video_uploader.submit()
    if result["code"] == 0:
        print(f'提交成功,av{result["data"]["aid"]},{result["data"]["bvid"]}')
    else:
        print(f'提交失败,原因为{result["message"]}')