Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions Converter/converter.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from converter_values import * # import required files
from converter_values import options, CATEGORIES

def main():
print(options["help"]) # prints help menu
res = input("Response: ")

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: <Category> <Unit> <Value> <TargetUnits>")

except Exception as e:
print("Error:", e)
Expand All @@ -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()



13 changes: 11 additions & 2 deletions Converter/converter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
inch : in
kilometer : km
meter : m
micrometer ; um
micrometer : um
mile : mi
millimeter : mm
nanometer : nm
Expand All @@ -21,7 +21,7 @@
sq inch : in2
sq km : km2
sq m : m2
sq mile : mi
sq mile : mi2
sq yard : yd2

VOLUME : V ----------------------------------------------------------------
Expand Down Expand Up @@ -115,3 +115,12 @@
"min":1440 ,
"sec":86400 }

CATEGORIES = {
"L": L,
"A": A,
"V": V,
"M": M,
"T": T
}


70 changes: 55 additions & 15 deletions Download Audio/Download Audio.py
Original file line number Diff line number Diff line change
@@ -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)
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()
10 changes: 7 additions & 3 deletions Download Audio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!--Remove the below lines and add yours -->
- 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
Expand Down
Binary file not shown.