-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsong_dl.py
34 lines (32 loc) · 1.06 KB
/
song_dl.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
33
34
from __future__ import unicode_literals
import youtube_dl
import datetime
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
with open(songs_dir+'/logger.txt','a') as log:
log.write('{} ERROR:{}\n'.format(str(datetime.datetime.now()),msg))
def my_hook(d):
if d['status'] == 'finished':
with open(songs_dir+'/logger.txt','a') as log:
log.write('{} INFO:Video File for {} is downloaded\n'.format(str(datetime.datetime.now()),d['filename']))
songs_dir = '' #Your songs directory goes here
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'download_archive':songs_dir+'/content.txt',
'logger': MyLogger(),
'outtmpl':songs_dir+'/%(title)s.%(ext)s',
'progress_hooks': [my_hook]
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([
# INSERT YOUR PLAYLIST(S) HERE IN COMMA-SEPERATED FORM
])