diff --git a/Converter/converter.py b/Converter/converter.py index c21fb90b..8c2ca6ea 100644 --- a/Converter/converter.py +++ b/Converter/converter.py @@ -1,4 +1,4 @@ -from converter_values import * # import required files +from converter_values import options, CATEGORIES def main(): print(options["help"]) # prints help menu @@ -6,14 +6,14 @@ def main(): while res.lower() != "q": # program loop try: - res = res.strip().split(" ") + tokens = res.strip().split(" ") - if len(res) == 1: - display_help(res[0]) # display help menu - elif len(res) == 4: - perform_conversion(res) # perform unit conversion + if len(tokens) == 1: + display_help(tokens[0]) # display help menu + elif len(tokens) == 4: + perform_conversion(tokens) # perform unit conversion else: - print("Invalid command") + print("Invalid command. Format: ") except Exception as e: print("Error:", e) @@ -22,15 +22,44 @@ def main(): def display_help(command): """Display help menu.""" - print(options[command]) + if command in options: + print(options[command]) + else: + print(f"Unknown command '{command}'. Type 'help' or 'symbols'.") def perform_conversion(res): - """Perform unit conversion.""" - for i in res[3].split(','): - value = round(eval("{} * {}['{}'] / {}['{}']".format(res[2], res[0], i, res[0], res[1])), 6) # calculating - print("{} \t : {}".format(i, value)) # displaying + """Perform unit conversion cleanly without unsafe eval.""" + category_code = res[0].upper() + src_unit = res[1] + + if category_code not in CATEGORIES: + print(f"Invalid category '{res[0]}'. Valid categories: {', '.join(CATEGORIES.keys())}") + return + + unit_dict = CATEGORIES[category_code] + + if src_unit not in unit_dict: + print(f"Invalid source unit '{src_unit}' for category '{category_code}'.") + return + + try: + raw_val = float(res[2]) + except ValueError: + print(f"Invalid numeric value '{res[2]}'.") + return + + target_units = [u.strip() for u in res[3].split(',')] + for target in target_units: + if target not in unit_dict: + print(f"Invalid target unit '{target}' for category '{category_code}'.") + continue + + # Calculation: val * unit_dict[target] / unit_dict[src_unit] + calc_value = round((raw_val * unit_dict[target]) / unit_dict[src_unit], 6) + print("{} \t : {}".format(target, calc_value)) if __name__ == "__main__": main() + diff --git a/Converter/converter_values.py b/Converter/converter_values.py index 3cc9c104..976619eb 100644 --- a/Converter/converter_values.py +++ b/Converter/converter_values.py @@ -7,7 +7,7 @@ inch : in kilometer : km meter : m -micrometer ; um +micrometer : um mile : mi millimeter : mm nanometer : nm @@ -21,7 +21,7 @@ sq inch : in2 sq km : km2 sq m : m2 -sq mile : mi +sq mile : mi2 sq yard : yd2 VOLUME : V ---------------------------------------------------------------- @@ -115,3 +115,12 @@ "min":1440 , "sec":86400 } +CATEGORIES = { + "L": L, + "A": A, + "V": V, + "M": M, + "T": T +} + + diff --git a/Download Audio/Download Audio.py b/Download Audio/Download Audio.py index 16826717..c0be2997 100644 --- a/Download Audio/Download Audio.py +++ b/Download Audio/Download Audio.py @@ -1,23 +1,63 @@ import os import pytube -from moviepy.editor import * +from moviepy.editor import AudioFileClip -# Define the YouTube video URL -youtube_url = "https://www.youtube.com/watch?v=E6eKvji_BoE" +def main(): + print("=== YouTube Audio Downloader ===") + + # Get YouTube URL from user + youtube_url = input("Enter YouTube video URL: ").strip() + if not youtube_url: + print("Error: URL cannot be empty.") + return -# Create a PyTube object and get the audio stream -yt = pytube.YouTube(youtube_url) -audio_stream = yt.streams.filter(only_audio=True).first() + # Get output directory + output_dir = input("Enter save directory path (press Enter for current directory): ").strip() + if not output_dir: + output_dir = "." + + if not os.path.exists(output_dir): + try: + os.makedirs(output_dir) + print(f"Created directory: {output_dir}") + except Exception as e: + print(f"Error creating directory '{output_dir}': {e}") + return -# Download the audio stream as a temporary file -temp_file = audio_stream.download() + # Get file name + file_name = input("Enter output filename (e.g. audio.mp3 or press Enter for default 'audio.mp3'): ").strip() + if not file_name: + file_name = "audio.mp3" + elif not file_name.endswith(".mp3"): + file_name += ".mp3" -# Convert the audio stream to an MP3 file using MoviePy -audio_clip = AudioFileClip(temp_file) -mp3_file = os.path.join("Give Your own path", "Name.mp3") -audio_clip.write_audiofile(mp3_file) + target_path = os.path.join(output_dir, file_name) -# Clean up the temporary file -os.remove(temp_file) + try: + print("Fetching video streams...") + yt = pytube.YouTube(youtube_url) + audio_stream = yt.streams.filter(only_audio=True).first() -print("Audio extracted and saved as MP3 file to", mp3_file) \ No newline at end of file + if not audio_stream: + print("Error: No audio stream found for this video.") + return + + print("Downloading audio stream...") + temp_file = audio_stream.download() + + print("Converting audio to MP3...") + audio_clip = AudioFileClip(temp_file) + audio_clip.write_audiofile(target_path) + audio_clip.close() + + # Clean up temporary file + if os.path.exists(temp_file): + os.remove(temp_file) + + print(f"\nSuccess! Audio saved as MP3 file to: {os.path.abspath(target_path)}") + + except Exception as e: + print(f"\nAn error occurred while processing the video: {e}") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Download Audio/README.md b/Download Audio/README.md index 7f4a56b8..1c92acff 100644 --- a/Download Audio/README.md +++ b/Download Audio/README.md @@ -24,9 +24,13 @@ This script is written in Python language. So make sure you have python installe 3. write "pip install pytube" ## 🌟 How to run -- Open the Download Audio.py script -- Add your own youtube video url instead of the default one in line 6. -- In Line 17, in the path section write your own path and in name section write the name You want your file to have. +- Run the `Download Audio.py` script: + ```bash + python "Download Audio.py" + ``` +- Enter the YouTube URL when prompted. +- Enter the destination folder path (or press Enter to save in the current directory). +- Enter your desired filename (or press Enter for default `audio.mp3`). ## 🤖 Author diff --git a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 b/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 deleted file mode 100644 index f5611fcf..00000000 Binary files a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 and /dev/null differ