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

Does Youtube-DL have a way to check if a page is compatible? #4503

Closed
nickyost opened this issue Dec 17, 2014 · 3 comments
Closed

Does Youtube-DL have a way to check if a page is compatible? #4503

nickyost opened this issue Dec 17, 2014 · 3 comments

Comments

@nickyost
Copy link

@nickyost nickyost commented Dec 17, 2014

YouTube-DL has a LOT of supported sites, which is great! But if I'm building an application to utilize some of them, is there any way for me to use YouTube-DL as a "catch all"?

Example command:

youtube-dl https://www.videovendor.com/video/title_of_video/1234 --is-compatible

This would yield "Yes" or "No" (in JSON or XML) depending on whether it was compatible.

I think this may be possible to do this with "--write-info-json" and maybe check the format of that, but can we count on consistency with this? If we can, I can then load the same file so it doesn't have to hit the endpoint more than once.

Thanks!

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Dec 21, 2014

You can do youtube-dl URL -j and check the exit code, it will be 0 on success and other value if it's not supported. But it will aslo return a non 0 value for other errors, for example if the video is blocked in the country.

@dbr
Copy link

@dbr dbr commented Dec 30, 2014

Using YoutubeDL via a simple Python script, you could check all of the info extractors to see if there is a dedicated extractor for the given URL - which would avoid having to contact the remote URL at all:

import youtube_dl
def supported(url):
    ies = youtube_dl.extractor.gen_extractors()
    for ie in ies:
        if ie.suitable(url) and ie.IE_NAME != 'generic':
            # Site has dedicated extractor
            return True
    return False

print supported("http://www.youtube.com/watch?v=BaW_jenozKc") # True
print supported("http://www.google.com/bad_example_of_unsupported_site") # False

Not as thorough as actually running youtube-dl [...] -j to dump out the video information, but much quicker because it's just a regex-match on the URL which might be preferable in certain circumstances

@phihag phihag closed this in 416c7fc Dec 30, 2014
@phihag
Copy link
Contributor

@phihag phihag commented Dec 30, 2014

Since I remember this question being asked at least twice before, I've added an FAQ entry that explains why using @dbr's code snippet is not a good idea.

You can just call youtube-dl with -j (or equivalently, --write-info-json --skip-download). If you get any results, the URL is supported. If you don't, it's not.

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.