Skip to content

Commit 999d5e2

Browse files
authored
Simple video to audio converter
Converting videos to audio files might seem like an odd decision, but it can come in handy in specific cases. It is most often used to record the soundtrack of videos or to extract other audio tracks from videos where you are only interested in the sound. So, with Python, it is super easy as this!
1 parent 97ae802 commit 999d5e2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

video_to_audio.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pytube import YouTube
2+
import pytube
3+
import os
4+
5+
def main():
6+
video_url = input('Enter YouTube video URL: ')
7+
8+
if os.name == 'nt':
9+
path = os.getcwd() + '\\'
10+
else:
11+
path = os.getcwd() + '/'
12+
13+
name = pytube.extract.video_id(video_url)
14+
YouTube(video_url).streams.filter(only_audio=True).first().download(filename=name)
15+
location = path + name + '.mp4'
16+
renametomp3 = path + name + '.mp3'
17+
18+
if os.name == 'nt':
19+
os.system('ren {0} {1}'. format(location, renametomp3))
20+
else:
21+
os.system('mv {0} {1}'. format(location, renametomp3))
22+
23+
if __name__ == '__main__':
24+
main()
25+
26+
# Coded with 💙 by Mr. Unity Buddy

0 commit comments

Comments
 (0)