You've already forked XiguaLiveDanmakuHelper
							
							对下载线程是否断开进行更频繁的检查,尽量减小更新房间信息更新的请求
This commit is contained in:
		| @@ -13,6 +13,7 @@ isUpload = False | |||||||
| uq = queue.Queue() | uq = queue.Queue() | ||||||
| eq = queue.Queue() | eq = queue.Queue() | ||||||
|  |  | ||||||
|  |  | ||||||
| class downloader(XiGuaLiveApi): | class downloader(XiGuaLiveApi): | ||||||
|     files = [] |     files = [] | ||||||
|     playlist: str = None |     playlist: str = None | ||||||
| @@ -33,8 +34,7 @@ class downloader(XiGuaLiveApi): | |||||||
|                     self.playlist = False |                     self.playlist = False | ||||||
|                 else: |                 else: | ||||||
|                     self.playlist = self._rawRoomInfo["stream_url"]["flv_pull_url"] |                     self.playlist = self._rawRoomInfo["stream_url"]["flv_pull_url"] | ||||||
|                     self.playlist = self.playlist.replace("_uhd","").replace("_sd","").replace("_ld","") |                     self.playlist = self.playlist.replace("_uhd", "").replace("_sd", "").replace("_ld", "") | ||||||
|  |  | ||||||
|  |  | ||||||
|     def onLike(self, user): |     def onLike(self, user): | ||||||
|         pass |         pass | ||||||
| @@ -68,43 +68,45 @@ class downloader(XiGuaLiveApi): | |||||||
|  |  | ||||||
|  |  | ||||||
| def download(url): | def download(url): | ||||||
|     global isUpload |  | ||||||
|     isUpload = False |  | ||||||
|     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: | ||||||
|         isUpload = True |  | ||||||
|         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 | ||||||
|     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, "ab") | ||||||
|     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: | ||||||
|                 f.write(t) |                 f.write(t) | ||||||
|             if os.path.getsize(path) > 1024*1024*1024*1.5: |             if os.path.getsize(path) > 1024 * 1024 * 1024 * 1.5: | ||||||
|                 break |                 break | ||||||
|         print("{} : Download Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"))) |         print("{} : Download Quiting".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"))) | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|         print("{} : Download Quiting With Exception {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"),e.__str__())) |         print("{} : Download Quiting With Exception {}".format(datetime.strftime(datetime.now(), "%y%m%d %H%M"), | ||||||
|  |                                                                e.__str__())) | ||||||
|     f.close() |     f.close() | ||||||
|     isUpload = True |  | ||||||
|     if os.path.getsize(path) == 0: |     if os.path.getsize(path) == 0: | ||||||
|         os.remove(path) |         os.remove(path) | ||||||
|         return False |         return False | ||||||
|     eq.put(path) |     eq.put(path) | ||||||
|     download(url) |     download(url) | ||||||
|  |  | ||||||
|  |  | ||||||
| def encode(): | def encode(): | ||||||
|  |     global isUpload | ||||||
|     while True: |     while True: | ||||||
|  |         isUpload = False | ||||||
|         i = eq.get() |         i = eq.get() | ||||||
|         if(os.path.exists(i)): |         if os.path.exists(i): | ||||||
|             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 | ||||||
|  |  | ||||||
|  |  | ||||||
| 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"))) | ||||||
| @@ -152,7 +154,7 @@ if __name__ == "__main__": | |||||||
|     et = threading.Thread(target=encode, args=()) |     et = threading.Thread(target=encode, args=()) | ||||||
|     et.setDaemon(True) |     et.setDaemon(True) | ||||||
|     et.start() |     et.start() | ||||||
|  |     _count = 0 | ||||||
|     while True: |     while True: | ||||||
|         if api.isLive: |         if api.isLive: | ||||||
|             if d is None: |             if d is None: | ||||||
| @@ -166,12 +168,14 @@ if __name__ == "__main__": | |||||||
|                 ut = threading.Thread(target=upload, args=(d,)) |                 ut = threading.Thread(target=upload, args=(d,)) | ||||||
|                 ut.setDaemon(True) |                 ut.setDaemon(True) | ||||||
|                 ut.start() |                 ut.start() | ||||||
|  |             time.sleep(20) | ||||||
|  |             if _count % 6 == 0: | ||||||
|                 try: |                 try: | ||||||
|                     api.updRoomInfo() |                     api.updRoomInfo() | ||||||
|                 except: |                 except: | ||||||
|                 time.sleep(30) |                     time.sleep(10) | ||||||
|                     continue |                     continue | ||||||
|             time.sleep(120) |                 _count += 1 | ||||||
|         else: |         else: | ||||||
|             if d is not None: |             if d is not None: | ||||||
|                 d = None |                 d = None | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user