use urllib instead of requests

This commit is contained in:
shanhm 2020-01-08 15:20:27 +08:00
parent 44698a0f39
commit 67c240abd0

View File

@ -5,10 +5,10 @@ import binascii
from ..common import *
import random
import requests
import string
import ctypes
from json import loads
from urllib import request
__all__ = ['ixigua_download', 'ixigua_download_playlist_by_url']
@ -82,8 +82,14 @@ def get_video_url_from_video_id(video_id):
def ixigua_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
# example url: https://www.ixigua.com/i6631065141750268420/#mid=63024814422
sess = requests.session()
html = sess.get(url, headers=headers).text
resp = urlopen_with_retry(request.Request(url))
html = resp.read().decode('utf-8')
_cookies = []
for c in resp.getheader('Set-Cookie').split("httponly,"):
_cookies.append(c.strip().split(' ')[0])
headers['cookie'] = ' '.join(_cookies)
conf = loads(match1(html, r"window\.config = (.+);"))
if not conf:
log.e("Get window.config from url failed, url: {}".format(url))
@ -97,7 +103,7 @@ def ixigua_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
if ok != 'OK':
log.e("Verify failed, verify_url: {}, result: {}".format(verify_url, ok))
return
html = sess.get(url, headers=headers).text
html = get_content(url, headers=headers)
video_id = match1(html, r"\"vid\":\"([^\"]+)")
title = match1(html, r"\"player__videoTitle\">.*?<h1.*?>(.*)<\/h1><\/div>")