Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to return the file name in embedded python script #6400

Closed
crhuber opened this issue Jul 29, 2015 · 1 comment
Closed

How to return the file name in embedded python script #6400

crhuber opened this issue Jul 29, 2015 · 1 comment

Comments

@crhuber
Copy link

@crhuber crhuber commented Jul 29, 2015

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])

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Jul 29, 2015

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])
@crhuber crhuber closed this Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.