forked from keshavoct98/DANCING-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
24 lines (19 loc) · 888 Bytes
/
get_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from pytube import YouTube
import moviepy.editor as mp
# Reading video links from "video_links.txt" file
with open('data/video_links.txt') as f:
links = f.readlines()
links = [x.strip() for x in links]
'''Downloads videos from given links in "mp4" format and "480p" resolution.
Audio is extracted by converting downloaded videos to "wav" format.
All videos, audios are stored in "data" folder.'''
for i in range(0, len(links)):
yt_obj = YouTube(links[i])
print('\nAudio-'+str(i))
audio = yt_obj.streams.filter().first()
audio.download(filename=str(i), output_path='data/')
video = mp.VideoFileClip('data/'+str(i)+'.mp4')
video.audio.write_audiofile('data/'+str(i)+'.wav')
print('\nVideo-'+str(i))
video = yt_obj.streams.filter(resolution='480p', mime_type="video/mp4").first()
video.download(filename=str(i), output_path='data/')