录播工具改进:下载完毕后用ffmpeg过一遍再上传,避免视频文件错误
This commit is contained in:
parent
b8b793e292
commit
530522f51c
10
bilibili.py
10
bilibili.py
@ -12,8 +12,6 @@ import hashlib
|
|||||||
import requests
|
import requests
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
from config import config
|
|
||||||
|
|
||||||
|
|
||||||
class VideoPart:
|
class VideoPart:
|
||||||
def __init__(self, path, title='', desc=''):
|
def __init__(self, path, title='', desc=''):
|
||||||
@ -325,12 +323,8 @@ class Bilibili:
|
|||||||
"videos": self.videos}
|
"videos": self.videos}
|
||||||
)
|
)
|
||||||
print(r.text)
|
print(r.text)
|
||||||
if config["mv"]:
|
self.files.clear()
|
||||||
for _p in self.files:
|
self.videos.clear()
|
||||||
shutil.move(_p.path, config["mtd"])
|
|
||||||
elif config["del"]:
|
|
||||||
for _p in self.files:
|
|
||||||
os.remove(_p.path)
|
|
||||||
|
|
||||||
def appendUpload(self,
|
def appendUpload(self,
|
||||||
aid,
|
aid,
|
||||||
|
@ -12,6 +12,7 @@ q = queue.Queue()
|
|||||||
base_uri = ""
|
base_uri = ""
|
||||||
isUpload = False
|
isUpload = False
|
||||||
uq = queue.Queue()
|
uq = queue.Queue()
|
||||||
|
eq = queue.Queue()
|
||||||
|
|
||||||
|
|
||||||
class downloader(XiGuaLiveApi):
|
class downloader(XiGuaLiveApi):
|
||||||
@ -20,6 +21,7 @@ class downloader(XiGuaLiveApi):
|
|||||||
|
|
||||||
def updRoomInfo(self):
|
def updRoomInfo(self):
|
||||||
super(downloader, self).updRoomInfo()
|
super(downloader, self).updRoomInfo()
|
||||||
|
if self.isLive:
|
||||||
self.updPlayList()
|
self.updPlayList()
|
||||||
|
|
||||||
def updPlayList(self):
|
def updPlayList(self):
|
||||||
@ -96,6 +98,7 @@ def download(path=datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")):
|
|||||||
n = False
|
n = False
|
||||||
isUpload = False
|
isUpload = False
|
||||||
i = q.get()
|
i = q.get()
|
||||||
|
f = open(path, "ab")
|
||||||
while True:
|
while True:
|
||||||
if isinstance(i, bool):
|
if isinstance(i, bool):
|
||||||
print("{} : Download Daemon Receive Command {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
print("{} : Download Daemon Receive Command {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
||||||
@ -105,17 +108,29 @@ def download(path=datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")):
|
|||||||
_p = requests.get("{}{}".format(base_uri, i))
|
_p = requests.get("{}{}".format(base_uri, i))
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
f = open(path, "ab")
|
|
||||||
f.write(_p.content)
|
f.write(_p.content)
|
||||||
f.close()
|
|
||||||
n = True
|
n = True
|
||||||
i = q.get()
|
i = q.get()
|
||||||
|
f.close()
|
||||||
if n:
|
if n:
|
||||||
isUpload = True
|
isUpload = True
|
||||||
uq.put(path)
|
eq.put(path)
|
||||||
print("{} : Download Daemon Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
print("{} : Download Daemon Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||||
|
|
||||||
|
|
||||||
|
def encode():
|
||||||
|
while True:
|
||||||
|
i = eq.get()
|
||||||
|
os.system("ffmpeg -y -i {} -vcodec copy -acodec copy -vbsf h264_mp4toannexb {}".format(
|
||||||
|
i, i[:13] + ".mp4"
|
||||||
|
))
|
||||||
|
uq.put(i[:13] + ".mp4")
|
||||||
|
if config["mv"]:
|
||||||
|
shutil.move(i, config["mtd"])
|
||||||
|
elif config["del"]:
|
||||||
|
os.remove(i)
|
||||||
|
|
||||||
|
|
||||||
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
||||||
print("{} : Upload Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
print("{} : Upload Daemon Starting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M")))
|
||||||
i = uq.get()
|
i = uq.get()
|
||||||
@ -127,6 +142,12 @@ def upload(date=datetime.strftime(datetime.now(), "%Y_%m_%d")):
|
|||||||
print("自动投稿中,请稍后")
|
print("自动投稿中,请稍后")
|
||||||
b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"],
|
b.finishUpload(config["t_t"].format(date), 17, config["tag"], config["des"],
|
||||||
source=config["src"], no_reprint=0)
|
source=config["src"], no_reprint=0)
|
||||||
|
if config["mv"]:
|
||||||
|
for _p in b.files:
|
||||||
|
shutil.move(_p.path, config["mtd"])
|
||||||
|
elif config["del"]:
|
||||||
|
for _p in b.files:
|
||||||
|
os.remove(_p.path)
|
||||||
break
|
break
|
||||||
print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
print("{} : Upload {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), i))
|
||||||
try:
|
try:
|
||||||
@ -142,10 +163,7 @@ b.login(config["b_u"], config["b_p"])
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
name = "永恒de草薙"
|
name = "永恒de草薙"
|
||||||
# room = 75366565294
|
# name = "mini游戏解说"
|
||||||
# room = 83940182312 #Dae
|
|
||||||
# room = 5947850784 #⑦
|
|
||||||
# room = 58649240617 #戏
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
name = sys.argv[1]
|
name = sys.argv[1]
|
||||||
print("西瓜直播录播助手 by JerryYan")
|
print("西瓜直播录播助手 by JerryYan")
|
||||||
@ -159,6 +177,9 @@ if __name__ == "__main__":
|
|||||||
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")
|
_preT = datetime.strftime(datetime.now(), "%Y%m%d_%H%M.ts")
|
||||||
t = threading.Thread(target=download, args=(_preT,))
|
t = threading.Thread(target=download, args=(_preT,))
|
||||||
ut = threading.Thread(target=upload, args=(d,))
|
ut = threading.Thread(target=upload, args=(d,))
|
||||||
|
et = threading.Thread(target=encode)
|
||||||
|
et.setDaemon(True)
|
||||||
|
et.start()
|
||||||
while True:
|
while True:
|
||||||
if api.isLive:
|
if api.isLive:
|
||||||
if d is None:
|
if d is None:
|
||||||
|
Reference in New Issue
Block a user