|
| 1 | +import nest_asyncio |
| 2 | +nest_asyncio.apply() |
| 3 | + |
1 | 4 | from datetime import datetime |
2 | 5 | import subprocess |
3 | 6 | import discord |
|
9 | 12 |
|
10 | 13 | from discord.ext import commands |
11 | 14 |
|
12 | | -from bilibili_api import sync, video_uploader, Credential |
| 15 | +from biliup.plugins.bili_webup import BiliBili, Data |
| 16 | + |
13 | 17 |
|
14 | 18 | from twitchAPI import Twitch |
15 | 19 |
|
16 | 20 | from Cogs.settings import (VERSION, TWITCH_APP_ID, |
17 | | - TWITCH_APP_SECRET, BILI_JCT, BILI_SESSDATA) |
| 21 | + TWITCH_APP_SECRET, BILI_JCT, BILI_SESSDATA, BILI_ACCESS_TOKEN, BILI_DEDEUSERID, BILI_DEDEUSERID_CKMD5) |
18 | 22 |
|
19 | 23 | twitch = Twitch(TWITCH_APP_ID, TWITCH_APP_SECRET) |
20 | 24 |
|
21 | | -credential = Credential(sessdata=BILI_SESSDATA, bili_jct=BILI_JCT) |
22 | | - |
23 | | - |
24 | 25 | class dl_logger(object): |
25 | 26 | def debug(self, msg): |
26 | 27 | print(f'Debug: {msg}') |
@@ -198,56 +199,46 @@ async def t(self, ctx, *args): |
198 | 199 | await msg.edit(embed=embed) |
199 | 200 | return |
200 | 201 |
|
201 | | - description = f"{title}\n{description if video_info.match_name is not None else ''}\n{'这是一个B站特供剪辑版,该视频已自动过滤敏感内容。' if video_info.sstime is not None else ''}\n\n比赛详情:{video_info.forum if video_info.forum is not None else '暂无'}\nMP Link:{video_info.mplink if video_info.mplink is not None else '暂无'}\n比赛时间:{datetime.fromtimestamp(timestamp)} (UTC)\n\nAuto upload by Twitsu v{VERSION}\ngithub.com/HarukaKinen/Twitsu" |
202 | | - |
203 | 202 | try: |
204 | | - meta = { |
205 | | - "copyright": 2, |
206 | | - "source": video_info.video, |
207 | | - "desc": description, |
208 | | - "desc_format_id": 0, |
209 | | - "dynamic": "", |
210 | | - "interactive": 0, |
211 | | - "open_elec": 1, |
212 | | - "no_reprint": 1, |
213 | | - "subtitles": { |
214 | | - "lan": "", |
215 | | - "open": 0 |
216 | | - }, |
217 | | - "tag": f"{game_mode[video_info.mode]}, 比赛录像, {video_info.match_name if video_info.match_name is not None else ''}", |
218 | | - "tid": 136, |
219 | | - "title": f"[{game_mode[video_info.mode]}] {video_info.match_name} {video_info.match_stage}: ({video_info.team1}) vs ({video_info.team2})" if video_info.match_name is not None else title, |
220 | | - "up_close_danmaku": False, |
221 | | - "up_close_reply": False |
222 | | - } |
223 | | - |
224 | | - page = video_uploader.VideoUploaderPage( |
225 | | - path=video_info.path, title=title[0:80], description=description) |
226 | | - uploader = video_uploader.VideoUploader( |
227 | | - [page], meta, credential) |
228 | | - |
229 | | - @uploader.on("__ALL__") |
230 | | - async def event(data): |
231 | | - print(data) |
232 | | - |
233 | 203 | embed.set_footer(text="Uploading video...") |
234 | | - await msg.edit(embed=embed) |
235 | | - await uploader.start() |
| 204 | + |
| 205 | + video = Data() |
| 206 | + |
| 207 | + video.title = f"[{game_mode[video_info.mode]}] {video_info.match_name} {video_info.match_stage}: ({video_info.team1}) vs ({video_info.team2})" if video_info.match_name is not None else title |
| 208 | + |
| 209 | + video.desc = f"{description if video_info.match_name is not None else ''}\n原标题:{title}\n{'这是一个B站特供剪辑版,该视频已自动过滤敏感内容。' if video_info.sstime is not None else ''}\n\n比赛详情:{video_info.forum if video_info.forum is not None else '暂无'}\nMP Link:{video_info.mplink if video_info.mplink is not None else '暂无'}\n比赛时间:{datetime.fromtimestamp(timestamp)} (UTC)\n\nAuto upload by Twitsu v{VERSION}\ngithub.com/HarukaKinen/Twitsu" |
| 210 | + |
| 211 | + tagList = [] |
| 212 | + tagList.append("比赛录像") |
| 213 | + tagList.append(game_mode[video_info.mode]) |
| 214 | + if video_info.match_name is not None: |
| 215 | + tagList.append(video_info.match_name) |
| 216 | + video.set_tag(tagList) |
| 217 | + |
| 218 | + video.source = video_info.video |
| 219 | + video.tid = 136 |
| 220 | + |
| 221 | + with BiliBili(video) as bili: |
| 222 | + bili.login("bili.cookie", { |
| 223 | + 'cookies': { |
| 224 | + 'SESSDATA': BILI_SESSDATA, |
| 225 | + 'bili_jct': BILI_JCT, |
| 226 | + 'DedeUserID__ckMd5': BILI_DEDEUSERID_CKMD5, |
| 227 | + 'DedeUserID': BILI_DEDEUSERID |
| 228 | + }, 'access_token': BILI_ACCESS_TOKEN}) |
| 229 | + |
| 230 | + video_part = bili.upload_file( |
| 231 | + video_info.path, lines='AUTO', tasks=3) # 上传视频,默认线路AUTO自动选择,线程数量3。 |
| 232 | + video.append(video_part) |
| 233 | + ret = bili.submit() |
| 234 | + print(ret) |
236 | 235 |
|
237 | 236 | embed.set_footer(text="Upload video successfully") |
238 | 237 | await msg.edit(embed=embed) |
239 | 238 | except Exception as e: |
240 | 239 | error_msg = e.__str__() |
241 | | - if error_msg.find("21070") != -1: |
242 | | - try: |
243 | | - asyncio.sleep(30) |
244 | | - await uploader.start() |
245 | | - except Exception as e: |
246 | | - embed.set_footer( |
247 | | - text=f"2nd attempt upload video failed: {error_msg}") |
248 | | - else: |
249 | | - embed.set_footer( |
250 | | - text=f"Upload video failed: {error_msg}") |
| 240 | + embed.set_footer( |
| 241 | + text=f"Upload video failed: {error_msg}") |
251 | 242 | await msg.edit(embed=embed) |
252 | 243 | return |
253 | 244 |
|
|
0 commit comments