def upload(video_path, title, source_link, thumbnail_path, description, uploader, upload_date): verify = Verify(config.cookie_sessdata, config.cookie_jct) try: video_file = video.video_upload(path=video_path, verify=verify) print("[Upload] Uploaded video file successfully.") except Exception as e: raise (Exception( f"[Upload] Failed to upload video file. Make sure the video file exists / the connection to bilibili is available / bili_jct is valid. Reason:{e.args}" )) return try: thumbnail_file = video.video_cover_upload(path=thumbnail_path, verify=verify) print("[Upload] Uploaded thubmnail successfully.") except Exception as e: raise (Exception( "[Upload] Failed to upload thubmnail. Make sure the thubmnail file exists / the connection to bilibili is available / bili_jct is valid" )) return description = "频道: {} 上传日期:{}\n".format(uploader, upload_date) + description data = { "copyright": 2, "source": source_link, "cover": thumbnail_file, "desc": description[0:1999 - len(source_link)], "desc_format_id": 0, "dynamic": "", "interactive": 0, "no_reprint": 1, "subtitles": { "lan": "语言", "open": 0 }, "tag": config.bilibili_tag, "tid": config.bilibili_tid, "title": title, "videos": [{ "desc": "", "filename": video_file, "title": "1" }] } print("[Upload] Submitting") try: result = video.video_submit(data, verify) print("[Upload] Submitted") except Exception as e: raise Exception(e.args.__str__())
def upload(topic, date, videoFile, imageFile, mid, sig, community): """上传视频到b站""" sessdata = os.getenv('SESSDATA', '') bili_jct = os.getenv('BILI_JCT', '') if not sessdata or not bili_jct: logger.error('both sessdata and bili_jct required, please check!') sys.exit(1) verify = Verify(sessdata, bili_jct) # 上传视频 filename = video.video_upload(videoFile, verify=verify) logger.info('meeting {}: B站上传视频'.format(mid)) # 上传封面 cover_url = video.video_cover_upload(imageFile, verify=verify) logger.info('meeting {}: B站上传封面'.format(mid)) # 提交投稿 data = { "copyright": 1, "cover": cover_url, "desc": "openEuler meeting record for {}".format(sig), "desc_format_id": 0, "dynamic": "", "interactive": 0, "no_reprint": 1, "subtitles": { "lan": "", "open": 0 }, "tag": "{}, community, recordings, 会议录像".format(community), "tid": 124, "title": topic + " (" + date + ")", "videos": [{ "desc": "recordings download from OBS", "filename": os.path.basename(filename), "title": "P1" }] } result = video.video_submit(data, verify=verify) logger.info('meeting {}: B站提交视频'.format(mid)) # 返回bv号和av号 logger.info('meeting {}: 视频提交成功!生成的bvid为{}'.format(mid, result['bvid'])) return result
def upload(): filename = video.video_upload(var_up_video_path.get(), verify=ver, on_progress=on_progress) # 上传封面 cover_url = video.video_cover_upload(var_up_cover_path.get(), verify=ver) data["cover"] = cover_url data["videos"][0]["filename"] = filename try: result = video.video_submit(data, verify=ver) except Exception as e: if hasattr(e, 'code'): update_progress(msg=str(e.code) + ":" + e.msg) tk.messagebox.showinfo(message=str(result))
def upload(video_path, title, source_link, thumbnail_path, description): try: verify = Verify(config.cookie_sessdata, config.cookie_jct) try: video_file = video.video_upload(video_path, verify=verify) print("[Upload] Uploaded video file successfully.") except Exception as e: print( "[Upload] Failed to upload video file. Make sure the video file exists" ) return try: thumbnail_file = video.video_cover_upload(thumbnail_path, verify=verify) print("[Upload] Uploaded thubmnail successfully.") except Exception as e: print( "[Upload] Failed to upload thubmnail. Make sure the thumbnail file exists" ) return data = { "copyright": 2, "source": source_link, "cover": thumbnail_file, "desc": "本视频由python搬运上传,有能力还请支持原作者.\n" + description, "desc_format_id": 0, "dynamic": "", "interactive": 0, "no_reprint": 1, "subtitles": { "lan": "语言", "open": 0 }, "tag": "标签改这里,多个标签使用英文半角逗号隔开", "tid": 17, "title": title, "videos": [{ "desc": "", "filename": video_file, "title": "1" }] } print("[Upload] Submitting") result = video.video_submit(data, verify) print(result) except Exception as e: print(e.args)
def upload_to_bilibili(videoFile, imageFile, topic): sessdata = os.getenv('SESSDATA', '') bili_jct = os.getenv('BILI_JCT', '') if not sessdata or not bili_jct: logger.error('both sessdata and bili_jct required, please check!') sys.exit(1) verify = Verify(sessdata, bili_jct) # 上传视频 filename = video.video_upload(videoFile, verify=verify) logger.info('视频上传B站') # 上传封面 cover_url = video.video_cover_upload(imageFile, verify=verify) logger.info('封面上传B站') # 提交投稿 data = { "copyright": 1, "cover": cover_url, "desc": "openEuler meetup", "desc_format_id": 0, "dynamic": "", "no_reprint": 1, "subtitles": { "lan": "", "open": 0 }, "tag": "openEuler, openeuler, meetup", "tid": 124, "title": topic, "videos": [ { "desc": "openEuler meetup Record", "filename": os.path.basename(filename), "title": "P1" } ] } result = video.video_submit(data, verify=verify) logger.info('视频提交成功') return result['bvid']
def upload_video(image_path, video_path, date_string, uploader_name, title, config, update_mode, task_id): verify = Verify(sessdata=config["sessdata"], csrf=config["bili_jct"]) video_date = dateutil.parser.isoparse(date_string) history_names = [ video_name for task_id, (bvid, video_name) in upload_task_dict.items() ] video_name = f"【{uploader_name}】{video_date.strftime('%Y年%m月%d日')} {title} 无弹幕先行版" i = 1 while video_name in history_names: i += 1 video_name = f"【{uploader_name}】{video_date.strftime('%Y年%m月%d日')} {title}{i} 无弹幕先行版" cover_url = video_cover_upload(image_path, verify=verify) def on_progress(update): print(update, file=sys.stderr) filename = video_upload(video_path, verify=verify, on_progress=on_progress) if not update_mode: data = { "copyright": 2, "source": config["source"], "cover": cover_url, "desc": config["description"] + f"\nhttps://tsxk.jya.ng/{video_path}", "desc_format_id": 0, "dynamic": "", "interactive": 0, "no_reprint": 0, "subtitles": { "lan": "", "open": 0 }, "tag": config["tags"], "tid": config["channel_id"], "title": video_name, "videos": [{ "desc": "", "filename": filename, "title": video_name }] } result = video_submit(data, verify) print(f"{video_name} uploaded: {result}", file=sys.stderr) upload_task_dict[task_id] = (result['bvid'], video_name) update_upload_task_dict() return result else: v = get_video_info(bvid=upload_task_dict[task_id], is_simple=False, is_member=True, verify=verify) print(f"updating... original_video: {v}", file=sys.stderr) data = { "copyright": v["archive"]['copyright'], "source": v["archive"]["source"], "cover": v["archive"]["cover"], "desc": v["archive"]["desc"], "desc_format_id": v["archive"]["desc_format_id"], "dynamic": v["archive"]["dynamic"], # "interactive": v["archive"]["interactive"], # "no_reprint": v["archive"]["no_reprint"], # "subtitle": v["subtitle"], "tag": v["archive"]["tag"], "tid": v["archive"]["tid"], "title": v["archive"]["title"].replace("无弹幕先行版", "弹幕高能版"), "videos": [{ "desc": video['desc'], "filename": filename if idx == 0 else video['filename'], "title": video['title'] } for idx, video in enumerate(v["videos"])], "handle_staff": False, 'bvid': v["archive"]["bvid"] } result = video_update(data, verify) print(f"{data['title']} updated: {result}", file=sys.stderr) return result
def upload(self, session_dict: {str: str}): def on_progress(update): print(update) filename = video_upload(self.video_path, verify=self.verify, on_progress=on_progress) if self.danmaku: suffix = "弹幕高能版" else: suffix = "无弹幕版" if self.session_id not in session_dict: cover_url = video_cover_upload(self.thumbnail_path, verify=self.verify) data = { "copyright": 2, "source": self.source, "cover": cover_url, "desc": self.description, "desc_format_id": 0, "dynamic": "", "interactive": 0, "no_reprint": 0, "subtitles": { "lan": "", "open": 0 }, "tag": self.tag, "tid": self.channel_id, "title": self.title + SPECIAL_SPACE + suffix, "videos": [{ "desc": "", "filename": filename, "title": suffix }] } result = video_submit(data, self.verify) print(f"{self.title} uploaded: {result}") return result['bvid'] else: old_bv = session_dict[self.session_id] v = get_video_info(bvid=old_bv, is_simple=False, is_member=True, verify=self.verify) old_title = v["archive"]["title"] if SPECIAL_SPACE in old_title: stripped_title = old_title.rpartition(SPECIAL_SPACE)[0] else: stripped_title = old_title new_title = stripped_title + SPECIAL_SPACE + suffix data = { "copyright": v["archive"]['copyright'], "source": v["archive"]["source"], "cover": v["archive"]["cover"], "desc": v["archive"]["desc"], "desc_format_id": v["archive"]["desc_format_id"], "dynamic": v["archive"]["dynamic"], "tag": v["archive"]["tag"], "tid": v["archive"]["tid"], "title": new_title, "videos": [{ "desc": "", "filename": filename, "title": suffix }], # [{ # "desc": video['desc'], # "filename": video['filename'], # "title": video['title'] # } for video in v["videos"]], "handle_staff": False, 'bvid': v["archive"]["bvid"] } result = video_update_app(data, self.verify, self.account.access_token) print(f"{data['title']} updated: {result}") return result['bvid']