[weibo]weibo videos is m3u8 instead of mp4 now

This commit is contained in:
MaxwellGoblin 2017-05-22 23:05:06 +08:00
parent d0a7655727
commit 353a6a6730
2 changed files with 24 additions and 5 deletions

View File

@ -1068,6 +1068,8 @@ def print_info(site_info, title, type, size):
type_info = "Portable Network Graphics (%s)" % type type_info = "Portable Network Graphics (%s)" % type
elif type in ['image/gif']: elif type in ['image/gif']:
type_info = "Graphics Interchange Format (%s)" % type type_info = "Graphics Interchange Format (%s)" % type
elif type in ['m3u8']:
type_info = 'M3U8 Playlist {}'.format(type)
else: else:
type_info = "Unknown type (%s)" % type type_info = "Unknown type (%s)" % type
@ -1075,6 +1077,7 @@ def print_info(site_info, title, type, size):
maybe_print("Site: ", site_info) maybe_print("Site: ", site_info)
maybe_print("Title: ", unescape_html(tr(title))) maybe_print("Title: ", unescape_html(tr(title)))
print("Type: ", type_info) print("Type: ", type_info)
if type != 'm3u8':
print("Size: ", round(size / 1048576, 2), "MiB (" + str(size) + " Bytes)") print("Size: ", round(size / 1048576, 2), "MiB (" + str(size) + " Bytes)")
print() print()

View File

@ -5,6 +5,16 @@ __all__ = ['miaopai_download']
from ..common import * from ..common import *
import urllib.error import urllib.error
def build_m3u8_list(m3u8_url):
path_len = len(m3u8_url.split('/')[-1])
base_url = m3u8_url[:-path_len]
urls = []
m3u8 = get_content(m3u8_url).split('\n')
for line in m3u8:
if len(line) > 0 and line[0] != '#':
urls.append(base_url+line)
return urls
def miaopai_download_by_fid(fid, output_dir = '.', merge = False, info_only = False, **kwargs): def miaopai_download_by_fid(fid, output_dir = '.', merge = False, info_only = False, **kwargs):
'''Source: Android mobile''' '''Source: Android mobile'''
fake_headers_mobile = { fake_headers_mobile = {
@ -19,10 +29,16 @@ 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')
title = match1(mobile_page, r'<title>([^<]+)</title>') title = match1(mobile_page, r'<title>([^<]+)</title>')
if not '.m3u8' in url:
type_, ext, size = url_info(url) type_, ext, size = url_info(url)
print_info(site_info, title, type_, size) print_info(site_info, title, type_, size)
if not info_only: if not info_only:
download_urls([url], title.replace('\n',''), ext, total_size=None, output_dir=output_dir, merge=merge) download_urls([url], title.replace('\n',''), ext, total_size=None, output_dir=output_dir, merge=merge)
else:
urls = build_m3u8_list(url)
print_info(site_info, title, 'm3u8', 0)
if not info_only:
download_urls(urls, title.replace('\n', ''), 'mp4', total_size=None, output_dir=output_dir, merge=merge)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def miaopai_download(url, output_dir = '.', merge = False, info_only = False, **kwargs): def miaopai_download(url, output_dir = '.', merge = False, info_only = False, **kwargs):