You've already forked XiguaLiveDanmakuHelper
修改Bilibili.py,尝试下载好片段就上传,等待下播后结束上传
This commit is contained in:
@ -12,9 +12,9 @@ from bilibili import *
|
||||
q = queue.Queue()
|
||||
base_uri = ""
|
||||
isUpload = False
|
||||
OutFileName = []
|
||||
env = dotenv.main.DotEnv(".env")
|
||||
|
||||
uq = queue.Queue()
|
||||
d = datetime.strftime(datetime.now(),"%Y_%m_%d")
|
||||
|
||||
class downloader(XiGuaLiveApi):
|
||||
files = []
|
||||
@ -32,7 +32,6 @@ class downloader(XiGuaLiveApi):
|
||||
else:
|
||||
self.playlist = self._rawRoomInfo["playInfo"]["Main"]["1"]["Url"]["HlsUrl"]
|
||||
|
||||
|
||||
def onLike(self, user):
|
||||
pass
|
||||
def onAd(self, i):
|
||||
@ -65,31 +64,63 @@ class downloader(XiGuaLiveApi):
|
||||
for i in p.files:
|
||||
if i not in self.files:
|
||||
self.files.append(i)
|
||||
print("{} : Add Sequence {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"),
|
||||
len(self.files)))
|
||||
q.put(i)
|
||||
self.genNewName()
|
||||
def genNewName(self):
|
||||
if len(self.files) > 1500:
|
||||
q.put(False)
|
||||
if len(self.files) > 1000:
|
||||
q.put(True)
|
||||
self.files.clear()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def download(path=datetime.strftime(datetime.now(),"%Y%m%d_%H%M.ts")):
|
||||
print("Download Daemon Starting")
|
||||
OutFileName.append(path)
|
||||
print("{} : Download Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||
n = False
|
||||
i = q.get()
|
||||
while True:
|
||||
i = q.get()
|
||||
if isinstance(i, bool):
|
||||
print("Recive Command {}".format(i))
|
||||
print("{} : Download Daemon Receive Command {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
||||
break
|
||||
_p = requests.get("{}{}".format(base_uri,i))
|
||||
print("Download : {}".format(i))
|
||||
print("{} : Download {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
||||
try:
|
||||
_p = requests.get("{}{}".format(base_uri,i))
|
||||
except:
|
||||
continue
|
||||
f = open(path, "ab")
|
||||
f.write(_p.content)
|
||||
f.close()
|
||||
n=True
|
||||
i = q.get()
|
||||
if n:
|
||||
uq.put(path)
|
||||
print("{} : Download Daemon Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||
|
||||
|
||||
def upload(date = datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
||||
print("{} : Upload Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||
i = uq.get()
|
||||
while True:
|
||||
if isinstance(i, bool):
|
||||
if i is True:
|
||||
b.finishUpload("【永恒de草薙直播录播】直播于 {} 自动投递实际测试".format(date),
|
||||
17, ["永恒de草薙", "三国", "三国战记", "自动投递", "直播", "录播"],
|
||||
"自动投递实际测试\n原主播:永恒de草薙\n直播时间:晚上6点多到白天6点左右",
|
||||
source= "https://live.ixigua.com/userlive/97621754276", no_reprint= 0)
|
||||
print("{} : Upload Daemon Receive Command {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
||||
break
|
||||
print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
||||
try:
|
||||
b.preUpload(VideoPart(i, i))
|
||||
except:
|
||||
continue
|
||||
i = uq.get()
|
||||
print("{} : Upload Daemon Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||
|
||||
|
||||
b = Bilibili()
|
||||
b.login(env.get("b_u"), env.get("b_p"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
room = 97621754276 # 永恒
|
||||
# room = 75366565294
|
||||
@ -108,17 +139,22 @@ if __name__ == "__main__":
|
||||
input("房间不存在")
|
||||
sys.exit()
|
||||
print("=" * 30)
|
||||
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H.ts")
|
||||
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")
|
||||
t = threading.Thread(target=download, args=(_preT,))
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
ut = threading.Thread(target=upload, args=(d,))
|
||||
while True:
|
||||
if api.isLive:
|
||||
if d is None:
|
||||
d = datetime.strftime(datetime.now(), "%Y_%m_%d")
|
||||
if not t.is_alive():
|
||||
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H.ts")
|
||||
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")
|
||||
t = threading.Thread(target=download, args=(_preT,))
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
if not ut.is_alive():
|
||||
ut = threading.Thread(target=upload, args=(d,))
|
||||
ut.setDaemon(True)
|
||||
ut.start()
|
||||
api.preDownload()
|
||||
isUpload = True
|
||||
time.sleep(3)
|
||||
@ -126,22 +162,10 @@ if __name__ == "__main__":
|
||||
q.put(False)
|
||||
if isUpload:
|
||||
print("自动投稿中,请稍后")
|
||||
b = Bilibili()
|
||||
b.login(env.get("b_u"), env.get("b_p"))
|
||||
u = threading.Thread(target=b.upload,args=([VideoPart(n) for n in OutFileName],
|
||||
"【永恒de草薙直播的录播】(三国战记) live at {} 自动投递实际测试".format(OutFileName[0]),
|
||||
17, ["永恒de草薙", "三国", "三国战记", "自动投递", "直播", "录播"],
|
||||
"自动投递实际测试\n原主播:永恒de草薙\n直播时间:晚上6点多到白天6点左右",),
|
||||
kwargs={"source": "https://live.ixigua.com/userlive/97621754276", "no_reprint": 0})
|
||||
u.setDaemon(True)
|
||||
u.start()
|
||||
u.join()
|
||||
# reset all for long time running
|
||||
OutFileName = []
|
||||
api.files = []
|
||||
isUpload = False
|
||||
uq.put(True)
|
||||
else:
|
||||
pass
|
||||
# print("主播未开播,等待1分钟后重试")
|
||||
time.sleep(60)
|
||||
d=None
|
||||
api.updRoomInfo()
|
||||
|
Reference in New Issue
Block a user