def processVideo(data): #Expecting: type, oldExt, url, channel, message global messageQue if VERBOSE_OUTPUT: fixPrint("ProcessVideo DATA:", data) millis = str(int(round(time.time() * 1000))) uniqueID = f"{''.join([str(random.randint(0, 9)) for i in range(10)])}_{millis}" if not os.path.isdir(tmpDir): os.makedirs(tmpDir) if data['type'] == 'edit': newFile = cleanPath(f"{tmpDir}/{uniqueID}.{data['oldExt']}") try: with open(newFile, "wb") as f: f.write(requests.get(data['url'], allow_redirects = True).content) except: messageQue += [{"channel": data["channel"], "type": "error", "message": "There was an error while downloading your file."}] return VEB_RESULT = videoEdit(newFile, data['args'], durationUnder = 120, logErrors = True) if VERBOSE_OUTPUT: print("VEB_RESULT:", VEB_RESULT) if VEB_RESULT[0] == 0: if os.path.getsize(VEB_RESULT[1]) < 8 * 1024 ** 2: messageQue += [{"channel": data["channel"], "type": "file", "file": VEB_RESULT[1], "message": data["message"]}] else: messageQue += [{"channel": data["channel"], "type": "error", "message": f"Sorry, but the output file is too large."}] tryToDeleteFile(VEB_RESULT[1]) else: msg = "Something went wrong editing your file, sorry." if len(VEB_RESULT) < 2 else ("Error: " + VEB_RESULT[1]) messageQue += [{"channel": data["channel"], "type": "error", "message": msg}] elif data['type'] == 'download': fixPrint(f"Download - {data['url']}") if download(fileName := f"{tmpDir}/{uniqueID}.mp4", data['url'], duration = 110):
def processVideo(data, s): global messageQue millis = str(int(round(time.time() * 1000))) uniqueID = f"{''.join([str(random.randint(0, 9)) for i in range(10)])}_{millis}" if not os.path.isdir(tmpDir): os.makedirs(tmpDir) if data['type'] == 'edit': newFile = cleanPath(f"{tmpDir}/{uniqueID}.{data['oldExt']}") try: with open(newFile, "wb") as f: f.write( requests.get(data['url'], allow_redirects=True).content) except: messageQue += [{ "channel": data["channel"], "type": "error", "message": "There was an error while downloading your file." }] return VEB_RESULT = videoEdit(newFile, data['args'], durationUnder=120, logErrors=True) if VEB_RESULT[0] == 0: if os.path.getsize(VEB_RESULT[1]) < 8 * 1024**2: messageQue += [{ "channel": data["channel"], "type": "file", "file": VEB_RESULT[1], "message": data["message"] }] else: messageQue += [{ "channel": data["channel"], "type": "error", "message": f"Output file is > {8 * 1024 ** 2} Bytes, a solution will be found soon." }] tryToDeleteFile(VEB_RESULT[1]) # SWHAP({'type': 'file', 'file': open(VEB_RESULT[1], "rb").read()}, s) else: msg = "Something went wrong editing your file, sorry." if len( VEB_RESULT) < 2 else ("Error: " + VEB_RESULT[1]) messageQue += [{ "channel": data["channel"], "type": "error", "message": msg }] elif data['type'] == 'download': print(f"Download - {data['url']}") if download(fileName := f"{tmpDir}/{uniqueID}.mp4", data['url'], duration=110):
async def queMessages(): global messageQue while True: while len(messageQue) > 0: try: msg = messageQue.pop() if VERBOSE_OUTPUT: fixPrint("QueMessages:", msg) channel = await bot.fetch_channel(msg['channel']) if not channel: fixPrint("Error getting channel", msg['channel']) if msg['type'] == "file": tryToDeleteFile(msg['file']) continue if msg['type'] == "file": try: await channel.send(msg['message'] + f' [{NAME}]', files = [discord.File(msg['file'])]) except Exception as e: fixPrint("Couldn't send file.", e) tryToDeleteFile(msg['file']) elif msg['type'] == "error": await channel.send(msg['message'] + f' [{NAME}]') except Exception as e: print("Error in queMessages()!:", e) await asyncio.sleep(0.1) await asyncio.sleep(0.5)
async def queMessages(): global messageQue while True: while len(messageQue) > 0: msg = messageQue.pop() channel = await bot.fetch_channel(msg['channel']) if not channel: print("Error getting channel", msg['channel']) if msg['type'] == "file": tryToDeleteFile(msg['file']) continue if msg['type'] == "file": try: await channel.send(msg['message'] + f' [{UNIQUE_ID}]', files=[discord.File(msg['file'])]) except Exception as e: print("Couldn't send file.", e) tryToDeleteFile(msg['file']) elif msg['type'] == "error": await channel.send(msg['message'] + f' [{UNIQUE_ID}]')
messageQue += [{ "channel": data["channel"], "type": "file", "message": data['message'], "file": fileName }] else: messageQue += [{ "channel": data["channel"], "type": "error", "message": "Sorry, something went wrong downloading your video." }] tryToDeleteFile(fileName) async def videoEditBotClient(): global VERBOSE_OUTPUT, botKey, w while True: try: try: w = await websockets.connect(f"ws://{IP_ADDR}:{PORT}") except Exception as e: raise Exception(f"Error connecting to server; {e}") fixPrint("Connected to server.") try: while True: data = await w.recv() try: