Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Add ability to log errors to a file #26323
Comments
|
Could you a bit elaborate on what kind of script you use? I mean, what language the script is written in, how you invoke youtube-dl etc. |
|
@0l-l0, the script is a Windows batch script simply out of convenience because it was the quickest way for me to do what I needed to do. The script looks like this:
|
|
How about I/O redirections? Don't they do the trick? @echo off
youtube-dl -i --no-continue --add-metadata --write-description ^
-o "%%(extractor)s/%%(uploader)s/%%(uploader)s - %%(upload_date)s - %%(title)s.%%(ext)s" ^
-a links.txt >your_log_file.log 2>&1 |
|
That could work so long as the terminal output is logged and also printed to the terminal for monitoring. |
|
That's where embedded youtube-dl can help. I sketched this little python script based on your settings and the youtube-dl manual. In this case the log will be written to the file import logging
import youtube_dl
class TeeLogger(object):
def debug(self, msg):
print(msg)
logging.debug(msg)
def warning(self, msg):
print(msg)
logging.warning(msg)
def error(self, msg):
print(msg)
logging.error(msg)
def get_url_list(filename):
batch_file = open(filename, 'r')
url_list = []
for line in batch_file:
l = line.strip()
if l and not l.startswith(('#', ';', ']')):
url_list.append(l)
return url_list
ydl_opts = {
'addmetadata': True,
'continuedl': False,
'ignoreerrors': True,
'logger': TeeLogger(),
'outtmpl': '%(extractor)s/%(uploader)s/%(uploader)s - %(upload_date)s - %(title)s.%(ext)s',
'writedescription': True,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
logging.basicConfig(filename='youtube_dl.log', level=logging.NOTSET, format='')
try:
ydl.download(get_url_list('links.txt'))
except:
logging.exception('')
raise |
|
An even shorter one without reinventing the wheel: import logging
import youtube_dl
class TeeLogger(object):
def debug(self, msg):
print(msg)
logging.debug(msg)
def warning(self, msg):
print(msg)
logging.warning(msg)
def error(self, msg):
print(msg)
logging.error(msg)
ydl_opts = {
'addmetadata': True,
'continuedl': False,
'ignoreerrors': True,
'logger': TeeLogger(),
'outtmpl': '%(extractor)s/%(uploader)s/%(uploader)s - %(upload_date)s - %(title)s.%(ext)s',
'writedescription': True,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
logging.basicConfig(filename='youtube_dl.log', level=logging.NOTSET, format='')
try:
batch_file = open('links.txt', 'r')
ydl.download(youtube_dl.read_batch_urls(batch_file))
except:
logging.exception('')
raise |
|
Of course, if you don't wanna use Python for this but you have PowerShell installed, you can use the Tee-Object utility. |
|
@0l-l0, thanks for the scripts. It helps a lot. |
Checklist
Description
Could a feature be added so that errors encountered while downloading (failed downloads, ETC.) are logged to a file for perusal later? This would greatly help, as I have a script that downloads a large number of URLs and it's difficult to find if any failed.