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

Possible to use the '--referer' option in Python scripts? #13009

Closed
vaibhav101 opened this issue May 7, 2017 · 6 comments
Closed

Possible to use the '--referer' option in Python scripts? #13009

vaibhav101 opened this issue May 7, 2017 · 6 comments

Comments

@vaibhav101
Copy link

@vaibhav101 vaibhav101 commented May 7, 2017

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

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?

  • 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

I am trying to download a domain restricted (embed-only) Vimeo video by embedding youtube-dl in a python script.

From the CLI, I can write
youtube-dl --referer siteFromWhichIGotTheLink.com https://player.vimeo.com/video/189295917
to download this video.

But I have been unable to find such an option for embedding youtube-dl in a Python script

This is what my script looks like at the moment:

import youtube_dl

ydl_opts = {'outtmpl' : unicode('vid-name.mp4'), 'referer' : 'http://xyz.com'}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://player.vimeo.com/video/189295917'])
@dstftw
Copy link
Collaborator

@dstftw dstftw commented May 7, 2017

Put it as HTTP header in utils.std_headers.

@dstftw dstftw closed this May 7, 2017
@vaibhav101
Copy link
Author

@vaibhav101 vaibhav101 commented May 8, 2017

Thanks a lot, it works now.

For anyone unsure of how to do what @dstftw just said:

  1. Open the file <Python_directory>\Lib\site-packages\youtube_dl\utils.py
  2. Find the dictionary 'std_headers'
  3. Add the key-value pair 'referer' : 'http://embedSite.com' to it
  4. Done!
@flysee
Copy link

@flysee flysee commented Jan 11, 2018

But it's global settings.How to set it up when the different site? @vaibhav101 @dstftw

@vaibhav101
Copy link
Author

@vaibhav101 vaibhav101 commented Jan 11, 2018

it's global settings

That's right. You could either let that stay (it doesn't really affect downloading from other websites), or remove it once you are done with your script.

@simpss
Copy link

@simpss simpss commented Mar 23, 2018

as this was the first response from google. I'll update this issue with a solution that doesn't require the file change in site-packages.

We're essentially doing the same thing.

import youtube_dl
youtube_dl.utils.std_headers['Referer'] = "http://your.referer.here/"

....
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
     .....

@flysee this would also allow you to change it on the fly, in between downloads.

@flysee
Copy link

@flysee flysee commented Mar 25, 2018

Yeah,thx a lot! @simpss

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
4 participants
You can’t perform that action at this time.