File tree 1 file changed +41
-0
lines changed
Downloaders/src/Video-to-MP3 Converter
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments