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

Get filename (Python API) #13750

Closed
levinuss opened this issue Jul 27, 2017 · 2 comments
Closed

Get filename (Python API) #13750

levinuss opened this issue Jul 27, 2017 · 2 comments

Comments

@levinuss
Copy link

@levinuss levinuss commented Jul 27, 2017

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2017.07.23. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2017.07.23

Before submitting an issue make sure you have:

  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Question

Hi,
I am working with the barely documented youtube-dl Pyhton API. What I want to do is get the final name of the file also using the provided outtmpl option. My code looks like this:

...
def get_title(url, template):
        ytdl_opts = {
            'simulate': 'True',
            'forcefilename': 'True',
            'outtmpl': '{}'.format(template),
            'logger': MyLogger()   #Exists above 
        }
        with youtube_dl.YoutubeDL(ytdl_opts) as ytdl:
            result = ytdl.extract_info("{}".format(url))
            title = result.get("title", None)
            return title

As you possibly know the title field from extract_info does only return the raw title of the video, not the 'editied' version with outtmpl. The logger gets the filename because the forcefilename option is speciefied. But I want to return the filename. Is there a way to do this? For now I have solved it by executing the command-line youtube-dl form pyhton. A way to do it with the API would be very cool.
Thanks,
Levin

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jul 29, 2017

ytdl.prepare_filename(result).

@dstftw dstftw closed this Jul 29, 2017
@ytdl-org ytdl-org deleted a comment from siddht4 Jul 29, 2017
@ytdl-org ytdl-org deleted a comment from levinuss Jul 29, 2017
@ytdl-org ytdl-org deleted a comment from siddht4 Jul 29, 2017
@Tointoin
Copy link

@Tointoin Tointoin commented Feb 21, 2019

When I use ytdl.prepare_filename(result), I get the temporary filename.webm with the .webm format. Is it possible to get directly the filename with the right format extension ?

my code :

            ydl_opts = {
                'format': 'bestaudio',
                'outtmpl': unicode('/my/path/%(title)s-%(id)s.%(ext)s'),
                'postprocessors': [{'key':'FFmpegExtractAudio'}],
                'restrictfilenames':True,
                'forcefilename':True,
            } 

            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                info = ydl.extract_info(uri, download=True)
                filename = ydl.prepare_filename(info)
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
3 participants
You can’t perform that action at this time.