Skip to content

Commit f442db9

Browse files
committedSep 30, 2019
Added Script to convert Video to MP3
1 parent 47ad861 commit f442db9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
import urllib.request
3+
import urllib.error
4+
import re
5+
import sys
6+
import time
7+
import os
8+
9+
def video_to_audio(fileName):
10+
try:
11+
file,file_extension=os.path.splitext(fileName)
12+
video_to_wav = 'ffmpeg -i '+file+file_extension+' '+file+'.wav'
13+
final_audio ='lame '+file+'.wav'+' '+file+'.mp3'
14+
os.system(video_to_wav)
15+
os.system(final_audio)
16+
os.remove(file+'.wav')
17+
print("sucessfully converted ",fileName, " into audio!")
18+
except OSError as err:
19+
print(err.reason)
20+
exit(1)
21+
22+
def main():
23+
if len(sys.argv) <1 or len(sys.argv) > 2:
24+
print('command usage: python3 video_to_audio.py FileName')
25+
exit(1)
26+
else:
27+
filePath = sys.argv[1]
28+
# check if the specified file exists or not
29+
try:
30+
if os.path.exists(filePath):
31+
print("file found!")
32+
except OSError as err:
33+
print(err.reason)
34+
exit(1)
35+
# convert video to audio
36+
video_to_audio(filePath)
37+
time.sleep(1)
38+
# install ffmpeg and/or lame if you get an error saying that the program is currently not installed
39+
40+
if __name__ == '__main__':
41+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.