def check_file_type(url): try: r = requests.head(url) type = r.headers.get('content-type') if type == 'video/mp4' or type == 'video/x-flv' or type == 'application/octet-stream' or type == 'application/x-mpegurl': return url except: pass
def pxy_request(url,params): proxfree = 'https://www.proxfree.com' headers = headers={'User-Agent':'iPhone'} r = requests.head(proxfree, headers=headers, stream=True) cookie = r.headers.get('set-cookie') s = re.search('s=(.+?)(?:$|;)', cookie) token = re.search('token=(.+?)(?:$|;)', cookie) if s and token: cookie = 's=%s; token=%s; default=5' % (s.group(1),token.group(1)) common.set_yt_pxy_token(token.group(1)) proxy = 'https://%s.proxfree.com/request.php?do=go' % location headers.update({'Cookie':cookie}) if params: link = '%s?%s' % (url,urllib.urlencode(params)) else: link = url form_data = {'get':link, 'pfserverDropdown':proxy, 'pfipDropdown':'default'} response = requests.post(proxy, headers=headers, data=form_data) return response