Python - Verify If A Url Is A Video Raw File Link Without Urllib.request.urlopen
I want to verify if a url is video raw file link or not, for example: http://hidden_path/video_name.mp4 Below is my current code: def is_video(url): r = None try: r
Solution 1:
If you just want to check the Content-Type of the header you can send a HEAD request instead of the GET.
Once you have obtained the response from the HEAD request you can check for video in the Content-Type header as above.
Example:
>>>req = urllib.request.Request(url, method='HEAD', headers={'User-Agent': 'Mozilla/5.0'})>>>r = urllib.request.urlopen(req)>>>r.getheader('Content-Type')
'video/mp4'
Solution 2:
Hope this does it
import mimetypes
url = 'http://media.theaterchurch.com/podcast/video/hd/720p/2016/05-08-16-720p.mp4'print mimetypes.MimeTypes().guess_type(url)[0]
outputs this...
video/mp4
Post a Comment for "Python - Verify If A Url Is A Video Raw File Link Without Urllib.request.urlopen"