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.
How to return the file name in embedded python script #6400
Comments
|
Currently it's not provided, but you could use: def download(url):
def hooks(data):
if data['status'] == 'finished':
filename = data['filename']
# url is the url used when calling download()
print(url)
options = {
'restrictfilenames': True,
'simulate': False,
'progress_hooks': [hooks],
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([url]) |
Im importing youtube-dl in a python script. When the video finishes downloading I want to save the filename to my database. In the hooks I dont know how to access any of the parameters/variables that were passed into the the original 'download' function. I need the url parameter so I can query and update my database.
def hooks(data):
if data['status'] == 'finished':
filename = data['filename']
#how can i access the url parameter from the download function?
def download(url):
options = {
'restrictfilenames': True,
'simulate': False,
'progress_hooks': [hooks],
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([url])