def convert2mkv(path): out_path = path + ".mkv" if os.path.exists(out_path): return out_path try: from util import Animation anim = Animation() ffmpeg.input(path).output(out_path, codec="copy", loglevel=0).run() anim.complete() print( f"[{colored('+','green')}] Successfully converted {colored(path2title(out_path),'green')} to MKV format" ) return out_path except Exception as e: print( f"[{colored('-','red')}] An error occured while converting {colored(path2title(out_path),'green')} to MKV: ", e, ) raise e
def extract(path, quality="medium"): """ Extractor function utilizing ffmpeg to extract audio from a given video file """ try: file = ffmpeg.input(path) output_path = path[:-3] + "ogg" if os.path.exists(output_path): print( f"[{colored('#','yellow')}] Audio file {colored(path2title(output_path),'green')} already exists" ) return output_path print( f"\n[{colored('+','green')}] Extracting audio for file %s" % (colored(path2title(path), "green")), end="", ) from util import Animation anim = Animation() file.audio.output( output_path, acodec="libvorbis", audio_bitrate=BITRATE * get_multiplier(quality), loglevel=0, ).run() anim.complete() print( f"[{colored('+','green')}] Extraction completed for file %s" % (colored(path2title(output_path), "green")) ) except Exception as ex: print( f"[{colored('-','red')}] There was an error extracting the audio for path {colored(path2title(output_path),'green')}: ", ex, ) sys.exit(-1) return output_path
def convert2mkv(path): out_path = path + ".mkv" if os.path.exists(out_path): return out_path try: from util import Animation anim = Animation() cmd = [ffmpeg, "-i", path, "-codec", "copy", out_path] subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate() anim.complete() print( f"[{colored('+','green')}] Successfully converted {colored(path2title(out_path),'green')} to MKV format" ) return out_path except Exception as e: print( f"[{colored('-','red')}] An error occured while converting {colored(path2title(out_path),'green')} to MKV: ", e, ) raise e
def extract(path): """ Extractor function utilizing ffmpeg to extract audio from a given video file """ clear_files = [] path, = get_videos(path, clear_files) clear_files = (None if len(clear_files) == 0 else clear_files[0]) if path is None: return None, None try: output_path = path[:-3] + "mp3" cmd = [ffmpeg, "-i", path, "-vn", "-acodec", "mp3", output_path] if os.path.exists(output_path): print( f"[{colored('#','yellow')}] Audio file {colored(path2title(output_path),'green')} already exists" ) return output_path, clear_files print( f"\n[{colored('+','green')}] Extracting audio for file %s" % (colored(path2title(path), "green")), end="", ) from util import Animation anim = Animation() subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate() anim.complete() print(f"[{colored('+','green')}] Extraction completed for file %s" % (colored(path2title(output_path), "green"))) except Exception as ex: print( f"[{colored('-','red')}] There was an error extracting the audio for path {colored(path2title(output_path),'green')}: ", ex, ) sys.exit(-1) return output_path, clear_files
def spawn_server(): SERVER_PATH = "../../CommonAudioVideoServer/" if not os.path.exists(SERVER_PATH): print( f"[{colored('-','red')}] Invalid Server Path, Try {colored(reinstalling,'red')} the package" ) sys.exit(-1) if not os.path.exists(SERVER_PATH + "node_modules"): print(f"[{colored('+','green')}] Configuring the server ..") anim = Animation() subprocess.Popen( "npm install".split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=os.getcwd() + "/" + SERVER_PATH, ).wait() anim.complete() print(f"[{colored('+','green')}] Server configuration complete ..") if args.rebuild: print(f"[{colored('+','green')}] Building server ..") anim = Animation() subprocess.Popen( "npm run compile".split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=os.getcwd() + "/" + SERVER_PATH, ).wait() anim.complete() print(f"[{colored('+','green')}] Server build successfull ..") print(f"[{colored('+','green')}] Initializing Server ..") anim = Animation() proc = subprocess.Popen( "npm start".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=os.getcwd() + "/" + SERVER_PATH, ) for line in iter(proc.stdout.readline, ""): if b"npm ERR!" in line: print(colored(line, "red")) print( f"[{colored('-','red')}] An error has occured while starting the server\nRestarting the server" ) os.system("killall node") os.system("killall npm") sys.exit(-1) if b"Press CTRL-C to stop" in line: anim.complete() break