更新:Api升级了
修复:下播超过1小时才会投稿视频
This commit is contained in:
parent
90f6e8e1cb
commit
f8d4be5385
2
api.py
2
api.py
@ -186,7 +186,7 @@ class XiGuaLiveApi:
|
|||||||
for i in d["data"]:
|
for i in d["data"]:
|
||||||
if i["block_type"] != 0:
|
if i["block_type"] != 0:
|
||||||
continue
|
continue
|
||||||
if len(i["cells"]) == 0:
|
if "cells" not in i or len(i["cells"]) == 0:
|
||||||
return
|
return
|
||||||
self.isValidRoom = True
|
self.isValidRoom = True
|
||||||
if "is_living" in i["cells"][0]["anchor"]["user_info"]:
|
if "is_living" in i["cells"][0]["anchor"]["user_info"]:
|
||||||
|
@ -10,7 +10,8 @@ from bilibili import *
|
|||||||
|
|
||||||
q = queue.Queue()
|
q = queue.Queue()
|
||||||
base_uri = ""
|
base_uri = ""
|
||||||
isUpload = False
|
isEncode = False
|
||||||
|
isDownload = False
|
||||||
uq = queue.Queue()
|
uq = queue.Queue()
|
||||||
eq = queue.Queue()
|
eq = queue.Queue()
|
||||||
|
|
||||||
@ -69,13 +70,15 @@ class downloader(XiGuaLiveApi):
|
|||||||
|
|
||||||
|
|
||||||
def download(url):
|
def download(url):
|
||||||
|
global isDownload
|
||||||
path = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.flv")
|
path = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.flv")
|
||||||
p = requests.get(url, stream=True)
|
p = requests.get(url, stream=True)
|
||||||
if p.status_code != 200:
|
if p.status_code != 200:
|
||||||
print("{} : Download Response 404 ,will stop looping".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
print("{} : Download Response 404 ,will stop looping".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||||
return True
|
return True
|
||||||
|
isDownload = True
|
||||||
print("{} : Download {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), path))
|
print("{} : Download {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), path))
|
||||||
f = open(path, "ab")
|
f = open(path, "wb")
|
||||||
try:
|
try:
|
||||||
for t in p.iter_content(chunk_size=64 * 1024):
|
for t in p.iter_content(chunk_size=64 * 1024):
|
||||||
if t:
|
if t:
|
||||||
@ -87,6 +90,7 @@ def download(url):
|
|||||||
print("{} : Download Quiting With Exception {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"),
|
print("{} : Download Quiting With Exception {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"),
|
||||||
e.__str__()))
|
e.__str__()))
|
||||||
f.close()
|
f.close()
|
||||||
|
isDownload = False
|
||||||
if os.path.getsize(path) == 0:
|
if os.path.getsize(path) == 0:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
return False
|
return False
|
||||||
@ -95,18 +99,18 @@ def download(url):
|
|||||||
|
|
||||||
|
|
||||||
def encode():
|
def encode():
|
||||||
global isUpload
|
global isEncode
|
||||||
while True:
|
while True:
|
||||||
i = eq.get()
|
i = eq.get()
|
||||||
if os.path.exists(i):
|
if os.path.exists(i):
|
||||||
isUpload = False
|
isEncode = True
|
||||||
os.system("ffmpeg -i {} -c:v copy -c:a copy -f mp4 {}".format(i, i[:13] + ".mp4"))
|
os.system("ffmpeg -i {} -c:v copy -c:a copy -f mp4 {}".format(i, i[:13] + ".mp4"))
|
||||||
uq.put(i[:13] + ".mp4")
|
uq.put(i[:13] + ".mp4")
|
||||||
if config["mv"]:
|
if config["mv"]:
|
||||||
shutil.move(i, config["mtd"])
|
shutil.move(i, config["mtd"])
|
||||||
elif config["del"]:
|
elif config["del"]:
|
||||||
os.remove(i)
|
os.remove(i)
|
||||||
isUpload = True
|
isEncode = False
|
||||||
|
|
||||||
|
|
||||||
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
||||||
@ -192,9 +196,10 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
if d is not None:
|
if d is not None:
|
||||||
d = None
|
d = None
|
||||||
if isUpload:
|
if not isEncode and not isDownload:
|
||||||
uq.put(True)
|
uq.put(True)
|
||||||
isUpload = False
|
isEncode = True
|
||||||
|
isDownload = True
|
||||||
del config
|
del config
|
||||||
from config import config
|
from config import config
|
||||||
# print("主播未开播,等待1分钟后重试")
|
# print("主播未开播,等待1分钟后重试")
|
||||||
|
Reference in New Issue
Block a user