Esempio n. 1
0
def main(*args, **kwargs):
    with open(path, 'r', encoding='utf-8-sig') as fp:
        userData = load(fp)

    video_uploader = VideoUploader()
    isLogin = False
    if userData["access_token"] and \
        video_uploader.login_by_access_token(userData["access_token"], userData["refresh_token"]):
        ...
    elif userData["username"] and \
        userData["password"] and \
        video_uploader.login_by_password(userData["username"], userData["password"]):
        userData["access_token"] = video_uploader.access_token
        userData["refresh_token"] = video_uploader.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"]}')
Esempio n. 2
0
tags = (input("请输入B站视频标签(必填,多个用英文逗号隔开):")).split(',')
tid = input("请输入B站视频分区编号(直接回车默认为生活->其他分区):")
if not tid:
    tid = 174

print("开始解析youtube视频")
video = YouTube(url)
for x in video.streams:
    print(x)
itag = input("请输入要下载的itag(直接回车默认为22):")
if itag:
    filename = video.streams.get_by_itag(int(itag)).download()
else:
    filename = video.streams.get_by_itag(22).download()

bilivideo = VideoUploader(configData["users"][0]["cookieDatas"]) #创建B站视频发布任务
print(f'开始将{filename}上传至B站,请耐心等待')
vd = bilivideo.uploadFileOneThread(filename) #上传视频
if not vd:
    print("上传失败")
    exit(0)

print(f'上传完成,即将发布,请等待最多30s')
vd["title"] = title
bilivideo.add(vd)  #添加视频
#bilivideo.setTitle(title)
bilivideo.setCopyright(2)
#bilivideo.setDesc(f'转载于:{url}') #添加简介
bilivideo.setSource(url) #添加转载地址说明
if tid:
    bilivideo.setTid(int(tid)) #设置视频分区,默认为 生活,其他分区
Esempio n. 3
0
def main(*args, **kwargs):
    try:
        if os.path.exists('./config.json'):
            with open('./config.json', 'r', encoding='utf-8') as fp:
                configData: dict = json.loads(
                    re.sub(r'\/\*[\s\S]*?\*\/', '', fp.read()))
        elif os.path.exists('./config/config.json'):
            with open('./config/config.json', 'r', encoding='utf-8') as fp:
                configData: dict = json.loads(
                    re.sub(r'\/\*[\s\S]*?\*\/', '', fp.read()))
        elif os.path.exists('/etc/BiliExp/config.json'):
            with open('/etc/BiliExp/config.json', 'r', encoding='utf-8') as fp:
                configData: dict = json.loads(
                    re.sub(r'\/\*[\s\S]*?\*\/', '', fp.read()))
        else:
            raise FileNotFoundError('未找到账户配置文件')
    except Exception as e:
        print(f'配置加载异常,原因为{str(e)},退出程序')
        sys.exit(6)

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

    video_uploader = VideoUploader(configData["users"][0]["cookieDatas"])
    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('正在上传中.....')
    if kwargs["singleThread"]:
        video_info = video_uploader.uploadFileOneThread(kwargs["path"])
    else:
        video_info = video_uploader.uploadFile(kwargs["path"])

    if not video_info:
        print('上传失败')
        exit()

    video_uploader.add(video_info)

    if kwargs["cover"]:
        video_uploader.setCover(kwargs["cover"])
    else:
        print('未设置封面,等待官方生成封面...')
        i = 12
        pics = []
        while i:
            time.sleep(10)  #B站需要足够的时间来生成封面
            try:
                pics = video_uploader.recovers(
                    video_info)  #获取视频截图,刚上传的视频可能获取不到
            except:
                ...
            if pics:
                video_uploader.setCover(pics[0])  #设置视频封面
                break
            i -= 1

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

    result = video_uploader.submit()
    if result["code"] == 0:
        print(f'提交成功,av{result["data"]["aid"]},{result["data"]["bvid"]}')
    else:
        print(f'提交失败,原因为{result["message"]}')
Esempio n. 4
0
tags = (input("请输入B站视频标签(必填,多个用英文逗号隔开):")).split(',')
tid = input("请输入B站视频分区编号(直接回车默认为生活->其他分区):")
if not tid:
    tid = 174

print("开始解析youtube视频")
video = YouTube(url)
for x in video.streams:
    print(x)
itag = input("请输入要下载的itag(直接回车默认为22):")
if itag:
    filename = video.streams.get_by_itag(int(itag)).download()
else:
    filename = video.streams.get_by_itag(22).download()

bilivideo = VideoUploader(configData["users"][0]["cookieDatas"])  #创建B站视频发布任务
print(f'开始将{filename}上传至B站,请耐心等待')
vd = bilivideo.uploadFileOneThread(filename)  #上传视频
if not vd:
    print("上传失败")
    exit(0)

print(f'上传完成,即将发布,请等待最多30s')
vd["title"] = title
bilivideo.add(vd)  #添加视频
#bilivideo.setTitle(title)
bilivideo.setCopyright(2)
#bilivideo.setDesc(f'转载于:{url}') #添加简介
bilivideo.setSource(url)  #添加转载地址说明
if tid:
    bilivideo.setTid(int(tid))  #设置视频分区,默认为 生活,其他分区