diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2020-07-07 20:27:58 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 20:27:58 +0530 |
commit | 4edd4d1bd27180dbe8179b08c2f5e2930bd0d440 (patch) | |
tree | 1157294180ebe84486750fa39c54fa1a26023417 /main.py | |
parent | 6624f8fb1aa7cf4d67c8b5256158515c06f55686 (diff) | |
parent | 52694cd7ad9bbd5c514de448d46ac3c7ef0aef9e (diff) |
Merge pull request #5 from navanchauhan/deepsource-transform-8bc97824
Format code with Black
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 126 |
1 files changed, 71 insertions, 55 deletions
@@ -16,15 +16,19 @@ import time version = 2.0 style = False -text = '| V A P O R W A V E || G E N E R A T O R |' - -parser = argparse.ArgumentParser(description = text) -parser.add_argument("-M", "--music", help="generate v a p o r w a v e music", action="store_true") -parser.add_argument("-P", "--picture", help="generate VHS Style image", action="store_true") -parser.add_argument("-V","--video", help="VHS Style Video", action="store_true") +text = "| V A P O R W A V E || G E N E R A T O R |" + +parser = argparse.ArgumentParser(description=text) +parser.add_argument( + "-M", "--music", help="generate v a p o r w a v e music", action="store_true" +) +parser.add_argument( + "-P", "--picture", help="generate VHS Style image", action="store_true" +) +parser.add_argument("-V", "--video", help="VHS Style Video", action="store_true") parser.add_argument("-v", "--version", help="show program version", action="store_true") parser.add_argument("-i", "--input") -parser.add_argument("-o","--output", help="Output for specifying output video") +parser.add_argument("-o", "--output", help="Output for specifying output video") args = parser.parse_args() @@ -34,26 +38,34 @@ picture = False video = False if args.version: - print("vaporwave generator 旺育栄", version) - exit + print("vaporwave generator 旺育栄", version) + exit if args.music: - music = True + music = True elif args.picture: picture = True elif args.video: video = True if args.input: - query = args.input + query = args.input if args.output: outfile = args.output else: parser.print_help() exit -MAX_DURATION = 600 # In-case the program finds a compilation -youtube_urls = ('youtube.com', 'https://www.youtube.com/', 'http://www.youtube.com/', 'http://youtu.be/', 'https://youtu.be/', 'youtu.be') +MAX_DURATION = 600 # In-case the program finds a compilation +youtube_urls = ( + "youtube.com", + "https://www.youtube.com/", + "http://www.youtube.com/", + "http://youtu.be/", + "https://youtu.be/", + "youtu.be", +) -def download_file(query,request_id=1): + +def download_file(query, request_id=1): """Returns audio to the vapor command handler Searches YouTube for 'query', finds first match that has @@ -63,16 +75,18 @@ def download_file(query,request_id=1): Query can be YouTube link. """ ydl_opts = { - 'quiet': 'True', - 'format': 'bestaudio/best', - 'outtmpl': str(request_id) +'.%(ext)s', - 'prefer_ffmpeg': 'True', - 'noplaylist': 'True', - 'postprocessors': [{ - 'key': 'FFmpegExtractAudio', - 'preferredcodec': 'wav', - 'preferredquality': '192', - }], + "quiet": "True", + "format": "bestaudio/best", + "outtmpl": str(request_id) + ".%(ext)s", + "prefer_ffmpeg": "True", + "noplaylist": "True", + "postprocessors": [ + { + "key": "FFmpegExtractAudio", + "preferredcodec": "wav", + "preferredquality": "192", + } + ], } original_path = str(request_id) + ".wav" @@ -81,9 +95,13 @@ def download_file(query,request_id=1): # check if query is youtube url if not query.lower().startswith((youtube_urls)): # search for youtube videos matching query - query_string = urllib.parse.urlencode({"search_query" : query}) - html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string) - search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode()) + query_string = urllib.parse.urlencode({"search_query": query}) + html_content = urllib.request.urlopen( + "http://www.youtube.com/results?" + query_string + ) + search_results = re.findall( + r"href=\"\/watch\?v=(.{11})", html_content.read().decode() + ) info = False # find video that fits max duration @@ -91,30 +109,30 @@ def download_file(query,request_id=1): for url in search_results: # check for video duration try: - info = youtube_dl.YoutubeDL(ydl_opts).extract_info(url,download = False) + info = youtube_dl.YoutubeDL(ydl_opts).extract_info(url, download=False) except Exception as e: logger.error(e) - raise ValueError('Could not get information about video.') - full_title = info['title'] - if (info['duration'] < MAX_DURATION and info['duration'] >= 5): + raise ValueError("Could not get information about video.") + full_title = info["title"] + if info["duration"] < MAX_DURATION and info["duration"] >= 5: # get first video that fits the limit duration logger.info("Got video: " + str(full_title)) - file_title = info['title'] + file_title = info["title"] break - + # if we ran out of urls, return error - if (not info): - raise ValueError('Could not find a video.') + if not info: + raise ValueError("Could not find a video.") # query was a youtube link else: logger.info("Query was a YouTube URL.") url = query - info = youtube_dl.YoutubeDL(ydl_opts).extract_info(url,download = False) - file_title = info['title'] + info = youtube_dl.YoutubeDL(ydl_opts).extract_info(url, download=False) + file_title = info["title"] # check if video fits limit duration - if (info['duration'] < 5 or info['duration'] > MAX_DURATION): - raise ValueError('Video is too short. Need 5 seconds or more.') + if info["duration"] < 5 or info["duration"] > MAX_DURATION: + raise ValueError("Video is too short. Need 5 seconds or more.") # download video and extract audio logger.info("Downloading video...") @@ -123,36 +141,35 @@ def download_file(query,request_id=1): ydl.download([url]) except Exception as e: logger.error(e) - raise ValueError('Could not download ' + str(full_title) + '.') + raise ValueError("Could not download " + str(full_title) + ".") return original_path, file_title def gen_vapor(filePath, title): - # Delete stuff if there is anything left over. - os.system("rm -r download/") - os.system("rm -r beats/") + # Delete stuff if there is anything left over. + os.system("rm -r download/") + os.system("rm -r beats/") # Make the proper folders for intermediate steps - os.system("mkdir download/") - os.system("mkdir beats/") + os.system("mkdir download/") + os.system("mkdir beats/") + # Download the youtube query's first result. Might be wrong but YOLO + # YTDownloader.download_wav_to_samp2(query) - # Download the youtube query's first result. Might be wrong but YOLO - #YTDownloader.download_wav_to_samp2(query) - - # For every song in download folder(just one for now) - """ + # For every song in download folder(just one for now) + """ for fs in os.listdir("download/"): # Slow down the song. VaporSong.vaporize_song(query,"download/"+fs) pass # When we are finished, delete the old folders. """ - VaporSong.vaporize_song(filePath, title) + VaporSong.vaporize_song(filePath, title) - os.system("rm -r download/") - os.system("rm -r beats/") + os.system("rm -r download/") + os.system("rm -r beats/") """ @@ -167,7 +184,6 @@ if music: name, title = download_file(query) gen_vapor(name, title) elif picture: - generateVHSStyle(query,"out.jpg") + generateVHSStyle(query, "out.jpg") elif video: VHS_Vid(query, outfile) -
\ No newline at end of file |