-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
32 lines (25 loc) · 815 Bytes
/
utils.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
25
26
27
28
29
30
31
32
import logging
import os
import youtube_dl
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger()
def download_video(url, filename):
def handle_video(d):
if d['status'] == 'finished':
logger.info(f'filename: {filename} - DOWNLOADED')
opt = {
'nooverwrites': True,
'outtmpl': filename,
'progress_hooks': [handle_video],
'quiet': True,
'postprocessors': [
{"key": "FFmpegVideoConvertor", "preferedformat": "mp4"}
]
}
with youtube_dl.YoutubeDL(opt) as ydl:
ydl.download([url])
return filename
def delete_video(filename):
os.remove(filename)
logger.info(f'filename: {filename} - REMOVED FROM DISK')