mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 21:45:02 +03:00
use urllib instead of requests
This commit is contained in:
parent
44698a0f39
commit
67c240abd0
@ -5,10 +5,10 @@ import binascii
|
|||||||
|
|
||||||
from ..common import *
|
from ..common import *
|
||||||
import random
|
import random
|
||||||
import requests
|
|
||||||
import string
|
import string
|
||||||
import ctypes
|
import ctypes
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from urllib import request
|
||||||
|
|
||||||
__all__ = ['ixigua_download', 'ixigua_download_playlist_by_url']
|
__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):
|
def ixigua_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||||
# example url: https://www.ixigua.com/i6631065141750268420/#mid=63024814422
|
# example url: https://www.ixigua.com/i6631065141750268420/#mid=63024814422
|
||||||
sess = requests.session()
|
resp = urlopen_with_retry(request.Request(url))
|
||||||
html = sess.get(url, headers=headers).text
|
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 = (.+);"))
|
conf = loads(match1(html, r"window\.config = (.+);"))
|
||||||
if not conf:
|
if not conf:
|
||||||
log.e("Get window.config from url failed, url: {}".format(url))
|
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':
|
if ok != 'OK':
|
||||||
log.e("Verify failed, verify_url: {}, result: {}".format(verify_url, ok))
|
log.e("Verify failed, verify_url: {}, result: {}".format(verify_url, ok))
|
||||||
return
|
return
|
||||||
html = sess.get(url, headers=headers).text
|
html = get_content(url, headers=headers)
|
||||||
|
|
||||||
video_id = match1(html, r"\"vid\":\"([^\"]+)")
|
video_id = match1(html, r"\"vid\":\"([^\"]+)")
|
||||||
title = match1(html, r"\"player__videoTitle\">.*?<h1.*?>(.*)<\/h1><\/div>")
|
title = match1(html, r"\"player__videoTitle\">.*?<h1.*?>(.*)<\/h1><\/div>")
|
||||||
|
Loading…
Reference in New Issue
Block a user