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 do I get the name of final file in Python? #16658

Closed
NightMachinary opened this issue Jun 6, 2018 · 2 comments
Closed

How do I get the name of final file in Python? #16658

NightMachinary opened this issue Jun 6, 2018 · 2 comments
Labels

Comments

@NightMachinary
Copy link

@NightMachinary NightMachinary commented Jun 6, 2018

I am using this currently:

        def my_hook(d):
                        if d['status'] == 'finished':
                            d1 = d['filename']
                            ...
                    ydl_opts = {
                        'progress_hooks': [my_hook],
                        'outtmpl': 'dls/%(playlist_title)s_%(title)s_%(format)s_%(autonumber)s.%(ext)s'
                    }
                    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                        d2 = ydl.extract_info(url)

But d2 doesn't have any filename attributes and my_hook is called two times when audio and video files are downloaded separately and then merged, and it is actually not called for the final, merged file.

@NightMachinary
Copy link
Author

@NightMachinary NightMachinary commented Jun 6, 2018

I tried this as well:

                   file_name = 'dls/' + str(uuid.uuid4())
                    ydl_opts = {
                        'outtmpl': file_name
                    }
                    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                        d2 = ydl.extract_info(url)
                        file_name_with_ext = file_name + "." + d2['ext']
                        ...

It works sometimes, but when the file is merged into an mkv, d2['ext'] wrongly returns 'mp4'.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jun 8, 2018

@dstftw dstftw closed this Jun 8, 2018
@dstftw dstftw added the duplicate label Jun 8, 2018
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.