mirror of
https://github.com/soimort/you-get.git
synced 2025-02-03 00:33:58 +03:00
[miaopai] fix weibo.com download error
This commit is contained in:
parent
58e806d72e
commit
7dbfece21f
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
__all__ = ['miaopai_download']
|
__all__ = ['miaopai_download']
|
||||||
|
|
||||||
|
import string
|
||||||
|
import random
|
||||||
from ..common import *
|
from ..common import *
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from ..util import fs
|
||||||
|
|
||||||
fake_headers_mobile = {
|
fake_headers_mobile = {
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
@ -20,6 +23,10 @@ def miaopai_download_by_fid(fid, output_dir = '.', merge = False, info_only = Fa
|
|||||||
|
|
||||||
mobile_page = get_content(page_url, headers=fake_headers_mobile)
|
mobile_page = get_content(page_url, headers=fake_headers_mobile)
|
||||||
url = match1(mobile_page, r'<video id=.*?src=[\'"](.*?)[\'"]\W')
|
url = match1(mobile_page, r'<video id=.*?src=[\'"](.*?)[\'"]\W')
|
||||||
|
if url is None:
|
||||||
|
wb_mp = re.search(r'<script src=([\'"])(.+?wb_mp\.js)\1>', mobile_page).group(2)
|
||||||
|
return miaopai_download_by_wbmp(wb_mp, fid, output_dir=output_dir, merge=merge,
|
||||||
|
info_only=info_only, total_size=None, **kwargs)
|
||||||
title = match1(mobile_page, r'<title>((.|\n)+?)</title>')
|
title = match1(mobile_page, r'<title>((.|\n)+?)</title>')
|
||||||
if not title:
|
if not title:
|
||||||
title = fid
|
title = fid
|
||||||
@ -29,7 +36,47 @@ def miaopai_download_by_fid(fid, output_dir = '.', merge = False, info_only = Fa
|
|||||||
if not info_only:
|
if not info_only:
|
||||||
download_urls([url], title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
download_urls([url], title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
|
def miaopai_download_by_wbmp(wbmp_url, fid, info_only=False, **kwargs):
|
||||||
|
headers = {}
|
||||||
|
headers.update(fake_headers_mobile)
|
||||||
|
headers['Host'] = 'imgaliyuncdn.miaopai.com'
|
||||||
|
wbmp = get_content(wbmp_url, headers=headers)
|
||||||
|
appid = re.search(r'appid:\s*?([^,]+?),', wbmp).group(1)
|
||||||
|
jsonp = re.search(r'jsonp:\s*?([\'"])(\w+?)\1', wbmp).group(2)
|
||||||
|
population = [i for i in string.ascii_lowercase] + [i for i in string.digits]
|
||||||
|
info_url = '{}?{}'.format('http://p.weibo.com/aj_media/info', parse.urlencode({
|
||||||
|
'appid': appid.strip(),
|
||||||
|
'fid': fid,
|
||||||
|
jsonp.strip(): '_jsonp' + ''.join(random.sample(population, 11))
|
||||||
|
}))
|
||||||
|
headers['Host'] = 'p.weibo.com'
|
||||||
|
jsonp_text = get_content(info_url, headers=headers)
|
||||||
|
jsonp_dict = json.loads(match1(jsonp_text, r'\(({.+})\)'))
|
||||||
|
if jsonp_dict['code'] != 200:
|
||||||
|
log.wtf('[Failed] "%s"' % jsonp_dict['msg'])
|
||||||
|
video_url = jsonp_dict['data']['meta_data'][0]['play_urls']['l']
|
||||||
|
title = jsonp_dict['data']['description']
|
||||||
|
title = title.replace('\n', '_')
|
||||||
|
ext = 'mp4'
|
||||||
|
headers['Host'] = 'f.us.sinaimg.cn'
|
||||||
|
print_info(site_info, title, ext, url_info(video_url, headers=headers)[2])
|
||||||
|
if not info_only:
|
||||||
|
download_urls([video_url], fs.legitimize(title), ext, headers=headers, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def miaopai_download_direct(url, info_only, **kwargs):
|
||||||
|
mobile_page = get_content(url, headers=fake_headers_mobile)
|
||||||
|
title = re.search(r'([\'"])title\1:\s*([\'"])(.+?)\2,', mobile_page).group(3)
|
||||||
|
title = title.replace('\n', '_')
|
||||||
|
stream_url = re.search(r'([\'"])stream_url\1:\s*([\'"])(.+?)\2,', mobile_page).group(3)
|
||||||
|
ext = 'mp4'
|
||||||
|
print_info(site_info, title, ext, url_info(stream_url, headers=fake_headers_mobile)[2])
|
||||||
|
if not info_only:
|
||||||
|
download_urls([stream_url], fs.legitimize(title), ext, total_size=None, headers=fake_headers_mobile, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
def miaopai_download(url, output_dir = '.', merge = False, info_only = False, **kwargs):
|
def miaopai_download(url, output_dir = '.', merge = False, info_only = False, **kwargs):
|
||||||
fid = match1(url, r'\?fid=(\d{4}:\w+)')
|
fid = match1(url, r'\?fid=(\d{4}:\w+)')
|
||||||
if fid is not None:
|
if fid is not None:
|
||||||
@ -37,6 +84,8 @@ def miaopai_download(url, output_dir = '.', merge = False, info_only = False, **
|
|||||||
elif '/p/230444' in url:
|
elif '/p/230444' in url:
|
||||||
fid = match1(url, r'/p/230444(\w+)')
|
fid = match1(url, r'/p/230444(\w+)')
|
||||||
miaopai_download_by_fid('1034:'+fid, output_dir, merge, info_only)
|
miaopai_download_by_fid('1034:'+fid, output_dir, merge, info_only)
|
||||||
|
elif re.match(r'^http[s]://weibo\.com/\d+/.+', url):
|
||||||
|
miaopai_download_direct(url, info_only=info_only, output_dir=output_dir, merge=merge, **kwargs)
|
||||||
else:
|
else:
|
||||||
mobile_page = get_content(url, headers = fake_headers_mobile)
|
mobile_page = get_content(url, headers = fake_headers_mobile)
|
||||||
hit = re.search(r'"page_url"\s*:\s*"([^"]+)"', mobile_page)
|
hit = re.search(r'"page_url"\s*:\s*"([^"]+)"', mobile_page)
|
||||||
@ -46,6 +95,7 @@ def miaopai_download(url, output_dir = '.', merge = False, info_only = False, **
|
|||||||
escaped_url = hit.group(1)
|
escaped_url = hit.group(1)
|
||||||
miaopai_download(urllib.parse.unquote(escaped_url), output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
|
miaopai_download(urllib.parse.unquote(escaped_url), output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
site_info = "miaopai"
|
site_info = "miaopai"
|
||||||
download = miaopai_download
|
download = miaopai_download
|
||||||
download_playlist = playlist_not_supported('miaopai')
|
download_playlist = playlist_not_supported('miaopai')
|
||||||
|
Loading…
Reference in New Issue
Block a user