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 can I determine the directory that the video will be saved to (or was saved to) via a python script? #16224

Closed
FunkyLoveCow opened this issue Apr 19, 2018 · 1 comment

Comments

@FunkyLoveCow
Copy link

@FunkyLoveCow FunkyLoveCow commented Apr 19, 2018

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like this: [x])
  • Use the Preview tab to see what your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2018.04.16. 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 2018.04.16

Before submitting an issue make sure you have:

  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones
  • Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

How can I determine the directory that the video will be saved to (or was saved to) via a python script?

I am attempting to download multiple video files, but also want to save some of the meta data that is provided by extract_info to a separate file which is stored with the video file. My script to download looks like this:

import youtube_dl

ydl_opts = {
        'retrictfilenames': True,
        'outtmpl': "%(title)s-%(id)s/%(title)s-%(id)s-%(resolution)s.%(ext)s"
    }

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    link = 'https://www.youtube.com/watch?v=BaW_jenozKc'
    ydl.download([link])
    meta = ydl.extract_info(link, download=False)

At this point, I'd like to write specific values from meta to a file in the %(title)s-%(id)s directory specified in ydl_opts. I'd do this with something like the following immediately after the meta = ydl.extract_info(...) line above:

with open("<DIRECTORY>/metadata.txt", "w") as f:
    # write values

How do I specify the value of <DIRECTORY> to be in the with open line? I just need the know how to access the value that ydl_opts['outtmpl'] becomes. I can parse the directory out on my own.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Apr 19, 2018

ydl.params['outtmpl'] = '"%(title)s-%(id)s/metadata.txt'
with open(ydl.prepare_filename(info) ...
   ...
@dstftw dstftw closed this Apr 19, 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.