Skip to content

Added Script to convert Video to MP3 #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2019
Merged
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
41 changes: 41 additions & 0 deletions Downloaders/src/Video-to-MP3 Converter/video-to-mp3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import urllib.request
import urllib.error
import re
import sys
import time
import os

def video_to_audio(fileName):
try:
file,file_extension=os.path.splitext(fileName)
video_to_wav = 'ffmpeg -i '+file+file_extension+' '+file+'.wav'
final_audio ='lame '+file+'.wav'+' '+file+'.mp3'
os.system(video_to_wav)
os.system(final_audio)
os.remove(file+'.wav')
print("sucessfully converted ",fileName, " into audio!")
except OSError as err:
print(err.reason)
exit(1)

def main():
if len(sys.argv) <1 or len(sys.argv) > 2:
print('command usage: python3 video_to_audio.py FileName')
exit(1)
else:
filePath = sys.argv[1]
# check if the specified file exists or not
try:
if os.path.exists(filePath):
print("file found!")
except OSError as err:
print(err.reason)
exit(1)
# convert video to audio
video_to_audio(filePath)
time.sleep(1)
# install ffmpeg and/or lame if you get an error saying that the program is currently not installed

if __name__ == '__main__':
main()