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 check if the url is a valid url before downloading ? #11649

Closed
deangelo200 opened this issue Jan 9, 2017 · 16 comments
Closed

How can i check if the url is a valid url before downloading ? #11649

deangelo200 opened this issue Jan 9, 2017 · 16 comments

Comments

@deangelo200
Copy link

@deangelo200 deangelo200 commented Jan 9, 2017

How can i check if the url is a valid url before downloading ?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 9, 2017

Use self._is_valid_url()

@yan12125 yan12125 closed this Jan 9, 2017
@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

Where would i have to use ? completely lost

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 9, 2017

Are you writing extractors or just using youtube-dl as a CLI program?

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

Writing an extractor
` with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(url, download=False)
video_id = info_dict.get("id", None)
video_title = info_dict.get('title', None)
video_thumb = info_dict.get('thumbnail',None)
context = {
'form': form,
'title':video_title,
'id': video_id,
'thumbnails':video_thumb

                }`
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 9, 2017

Well, at this level _is_valid_url is not available. Need other approaches. What's your scenario?

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

I want to add a feature to my website to let persons download songs but if the person entered an invalid url i want to run some functions

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 9, 2017

I guess I've got you. Just catch ExtractorError and analyze it

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

How to do this ? Can you give me a short example please

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 9, 2017

Like this. Do whatever you want to e.

from youtube_dl.utils import ExtractorError

try:
    info_dict = ydl.extract_info(url, download=False)
except ExtractorError as e:
    print(e)
@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

thanks. if you dont mind can you hit me up a quick email deangeloalmeus@gmail.com

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

image
Hey am getting this error instead of getting this error i want to send the user to a page

@Hrxn
Copy link

@Hrxn Hrxn commented Jan 9, 2017

How about using Regular Expressions to check? Pretty much the standard way to validate form input.

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

I was thinking the same thing but i want to send the users to an error page if their is an error in the url.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jan 9, 2017

Oops I forgot DownloadError wraps ExtractorError. Replace ExtractorError in the previous code with DownloadError

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

image
Are you familiar with Django

@deangelo200
Copy link
Author

@deangelo200 deangelo200 commented Jan 9, 2017

Dont worry i got it to work thanks guys :)

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.