fix youtube urls validation

This commit is contained in:
imsamuka 2022-01-02 17:20:37 -03:00
parent bdc63b4c35
commit ac7bc02ec5
No known key found for this signature in database
GPG key ID: AF9ACFEF1FD372EE

View file

@ -181,7 +181,9 @@ module Youtube
# is it a video on youtube, with a query
query = uri.query
if uri.host != "www.youtube.com" || uri.path != "/watch" || !query
if !uri || !query || !uri.host || uri.path != "/watch" ||
!uri.host.not_nil!.ends_with?("youtube.com")
return false
end
@ -204,8 +206,9 @@ module Youtube
# this is an internal endpoint to validate the video ID
response = HTTP::Client.get "https://www.youtube.com/get_video_info?video_id=#{vID}"
return response.body.includes?("status=ok")
response = HTTP::Client.get "https://www.youtube.com/oembed?format=json&url=#{url}"
return response.success?
end
end