mirror of
https://github.com/soimort/you-get.git
synced 2025-02-11 20:52:31 +03:00
code integration
This commit is contained in:
parent
e752181fcb
commit
e2d4881f17
@ -3,33 +3,40 @@
|
|||||||
__all__ = ['funshion_download']
|
__all__ = ['funshion_download']
|
||||||
|
|
||||||
from ..common import *
|
from ..common import *
|
||||||
import urllib.error
|
|
||||||
import json
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_download(url, output_dir = '.', merge = False, info_only = False, **kwargs):
|
def funshion_download(url, output_dir='.', merge=False, info_only=False):
|
||||||
""""""
|
"""
|
||||||
if re.match(r'http://www.fun.tv/vplay/v-(\w+)', url): #single video
|
:param url: 视频URL
|
||||||
funshion_download_by_url(url, output_dir = '.', merge = False, info_only = False)
|
:param output_dir: 下载视频目录
|
||||||
elif re.match(r'http://www.fun.tv/vplay/g-(\w+)', url): #whole drama
|
:param merge: 是否合并视频
|
||||||
funshion_download_by_drama_url(url, output_dir = '.', merge = False, info_only = False)
|
:param info_only: 是否只打印详情
|
||||||
|
"""
|
||||||
|
# single video
|
||||||
|
if re.match(r'http://www.fun.tv/vplay/v-(\w+)', url):
|
||||||
|
funshion_download_by_url(url, output_dir=output_dir, merge=merge, info_only=merge)
|
||||||
|
# whole drama
|
||||||
|
elif re.match(r'http://www.fun.tv/vplay/g-(\w+)', url):
|
||||||
|
funshion_download_by_drama_url(url, output_dir=output_dir, merge=merge, info_only=False)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Logics for single video until drama
|
|
||||||
#----------------------------------------------------------------------
|
def funshion_download_by_url(url, output_dir='.', merge=False, info_only=False):
|
||||||
def funshion_download_by_url(url, output_dir = '.', merge = False, info_only = False):
|
"""
|
||||||
"""lots of stuff->None
|
Logics for single video until drama
|
||||||
|
lots of stuff->None
|
||||||
Main wrapper for single video download.
|
Main wrapper for single video download.
|
||||||
"""
|
"""
|
||||||
if re.match(r'http://www.fun.tv/vplay/v-(\w+)', url):
|
if re.match(r'http://www.fun.tv/vplay/v-(\w+)', url):
|
||||||
match = re.search(r'http://www.fun.tv/vplay/v-(\d+)(.?)', url)
|
match = re.search(r'http://www.fun.tv/vplay/v-(\d+)(.?)', url)
|
||||||
vid = match.group(1)
|
vid = match.group(1)
|
||||||
funshion_download_by_vid(vid, output_dir = '.', merge = False, info_only = False)
|
funshion_download_by_vid(vid, output_dir=output_dir, merge=merge, info_only=False)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_download_by_vid(vid, output_dir = '.', merge = False, info_only = False):
|
def funshion_download_by_vid(vid, output_dir='.', merge=False, info_only=False):
|
||||||
"""vid->None
|
"""
|
||||||
|
vid->None
|
||||||
Secondary wrapper for single video download.
|
Secondary wrapper for single video download.
|
||||||
"""
|
"""
|
||||||
title = funshion_get_title_by_vid(vid)
|
title = funshion_get_title_by_vid(vid)
|
||||||
@ -42,40 +49,46 @@ def funshion_download_by_vid(vid, output_dir = '.', merge = False, info_only = F
|
|||||||
if not info_only:
|
if not info_only:
|
||||||
download_urls(url_list, title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
download_urls(url_list, title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_get_title_by_vid(vid):
|
def funshion_get_title_by_vid(vid):
|
||||||
"""vid->str
|
"""
|
||||||
Single video vid to title."""
|
vid->str
|
||||||
html = get_content('http://pv.funshion.com/v5/video/profile?id={vid}&cl=aphone&uc=5'.format(vid = vid))
|
Single video vid to title.
|
||||||
|
"""
|
||||||
|
html = get_content('http://pv.funshion.com/v5/video/profile?id={vid}&cl=aphone&uc=5'.format(vid=vid))
|
||||||
c = json.loads(html)
|
c = json.loads(html)
|
||||||
return c['name']
|
return c['name']
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_vid_to_urls(vid):
|
def funshion_vid_to_urls(vid):
|
||||||
"""str->str
|
"""
|
||||||
Select one resolution for single video download."""
|
str->str
|
||||||
html = get_content('http://pv.funshion.com/v5/video/play/?id={vid}&cl=aphone&uc=5'.format(vid = vid))
|
Select one resolution for single video download.
|
||||||
|
"""
|
||||||
|
html = get_content('http://pv.funshion.com/v5/video/play/?id={vid}&cl=aphone&uc=5'.format(vid=vid))
|
||||||
return select_url_from_video_api(html)
|
return select_url_from_video_api(html)
|
||||||
|
|
||||||
#Logics for drama until helper functions
|
|
||||||
#----------------------------------------------------------------------
|
def funshion_download_by_drama_url(url, output_dir='.', merge=False, info_only=False):
|
||||||
def funshion_download_by_drama_url(url, output_dir = '.', merge = False, info_only = False):
|
"""
|
||||||
"""str->None
|
Logics for drama until helper functions
|
||||||
|
str->None
|
||||||
url = 'http://www.fun.tv/vplay/g-95785/'
|
url = 'http://www.fun.tv/vplay/g-95785/'
|
||||||
"""
|
"""
|
||||||
if re.match(r'http://www.fun.tv/vplay/g-(\w+)', url):
|
if re.match(r'http://www.fun.tv/vplay/g-(\w+)', url):
|
||||||
match = re.search(r'http://www.fun.tv/vplay/g-(\d+)(.?)', url)
|
match = re.search(r'http://www.fun.tv/vplay/g-(\d+)(.?)', url)
|
||||||
id = match.group(1)
|
id = match.group(1)
|
||||||
|
|
||||||
video_list = funshion_drama_id_to_vid(id)
|
video_list = funshion_drama_id_to_vid(id)
|
||||||
|
|
||||||
for video in video_list:
|
for video in video_list:
|
||||||
funshion_download_by_id((video[0], id), output_dir = '.', merge = False, info_only = False)
|
funshion_download_by_id((video[0], id), output_dir=output_dir, merge=merge, info_only=False)
|
||||||
# id is for drama, vid not the same as the ones used in single video
|
# id is for drama, vid not the same as the ones used in single video
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_download_by_id(vid_id_tuple, output_dir = '.', merge = False, info_only = False):
|
def funshion_download_by_id(vid_id_tuple, output_dir='.', merge=False, info_only=False):
|
||||||
"""single_episode_id, drama_id->None
|
"""
|
||||||
|
single_episode_id, drama_id->None
|
||||||
Secondary wrapper for single drama video download.
|
Secondary wrapper for single drama video download.
|
||||||
"""
|
"""
|
||||||
(vid, id) = vid_id_tuple
|
(vid, id) = vid_id_tuple
|
||||||
@ -89,7 +102,7 @@ def funshion_download_by_id(vid_id_tuple, output_dir = '.', merge = False, info_
|
|||||||
if not info_only:
|
if not info_only:
|
||||||
download_urls(url_list, title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
download_urls(url_list, title, ext, total_size=None, output_dir=output_dir, merge=merge)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_drama_id_to_vid(episode_id):
|
def funshion_drama_id_to_vid(episode_id):
|
||||||
"""int->[(int,int),...]
|
"""int->[(int,int),...]
|
||||||
id: 95785
|
id: 95785
|
||||||
@ -98,47 +111,55 @@ def funshion_drama_id_to_vid(episode_id):
|
|||||||
|
|
||||||
**THIS VID IS NOT THE SAME WITH THE ONES USED IN SINGLE VIDEO!!**
|
**THIS VID IS NOT THE SAME WITH THE ONES USED IN SINGLE VIDEO!!**
|
||||||
"""
|
"""
|
||||||
html = get_content('http://pm.funshion.com/v5/media/episode?id={episode_id}&cl=aphone&uc=5'.format(episode_id = episode_id))
|
html = get_content('http://pm.funshion.com/v5/media/episode?id={episode_id}&cl=aphone&uc=5'.
|
||||||
|
format(episode_id = episode_id))
|
||||||
c = json.loads(html)
|
c = json.loads(html)
|
||||||
#{'definition': [{'name': '流畅', 'code': 'tv'}, {'name': '标清', 'code': 'dvd'}, {'name': '高清', 'code': 'hd'}], 'retmsg': 'ok', 'total': '32', 'sort': '1', 'prevues': [], 'retcode': '200', 'cid': '2', 'template': 'grid', 'episodes': [{'num': '1', 'id': '624728', 'still': None, 'name': '第1集', 'duration': '45:55'}, ], 'name': '太行山上', 'share': 'http://pm.funshion.com/v5/media/share?id=201554&num=', 'media': '201554'}
|
# {'definition': [{'name': '流畅', 'code': 'tv'}, {'name': '标清', 'code': 'dvd'}, {'name': '高清', 'code': 'hd'}],
|
||||||
|
# 'retmsg': 'ok', 'total': '32', 'sort': '1', 'prevues': [], 'retcode': '200', 'cid': '2', 'template': 'grid',
|
||||||
|
# 'episodes': [{'num': '1', 'id': '624728', 'still': None, 'name': '第1集', 'duration': '45:55'}, ],
|
||||||
|
# 'name': '太行山上', 'share': 'http://pm.funshion.com/v5/media/share?id=201554&num=', 'media': '201554'}
|
||||||
return [(i['id'], i['num']) for i in c['episodes']]
|
return [(i['id'], i['num']) for i in c['episodes']]
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_id_to_urls(id):
|
def funshion_id_to_urls(id):
|
||||||
"""int->list of URL
|
"""
|
||||||
|
int->list of URL
|
||||||
Select video URL for single drama video.
|
Select video URL for single drama video.
|
||||||
"""
|
"""
|
||||||
html = get_content('http://pm.funshion.com/v5/media/play/?id={id}&cl=aphone&uc=5'.format(id = id))
|
html = get_content('http://pm.funshion.com/v5/media/play/?id={id}&cl=aphone&uc=5'.format(id=id))
|
||||||
return select_url_from_video_api(html)
|
return select_url_from_video_api(html)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def funshion_get_title_by_id(single_episode_id, drama_id):
|
def funshion_get_title_by_id(single_episode_id, drama_id):
|
||||||
"""single_episode_id, drama_id->str
|
"""
|
||||||
|
single_episode_id, drama_id->str
|
||||||
This is for full drama.
|
This is for full drama.
|
||||||
Get title for single drama video."""
|
Get title for single drama video.
|
||||||
html = get_content('http://pm.funshion.com/v5/media/episode?id={id}&cl=aphone&uc=5'.format(id = drama_id))
|
"""
|
||||||
|
html = get_content('http://pm.funshion.com/v5/media/episode?id={id}&cl=aphone&uc=5'.format(id=drama_id))
|
||||||
c = json.loads(html)
|
c = json.loads(html)
|
||||||
|
|
||||||
for i in c['episodes']:
|
for i in c['episodes']:
|
||||||
if i['id'] == str(single_episode_id):
|
if i['id'] == str(single_episode_id):
|
||||||
return c['name'] + ' - ' + i['name']
|
return c['name'] + ' - ' + i['name']
|
||||||
|
|
||||||
# Helper functions.
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
def select_url_from_video_api(html):
|
def select_url_from_video_api(html):
|
||||||
"""str(html)->str(url)
|
"""
|
||||||
|
Helper functions.
|
||||||
|
str(html)->str(url)
|
||||||
Choose the best one.
|
Choose the best one.
|
||||||
|
|
||||||
Used in both single and drama download.
|
Used in both single and drama download.
|
||||||
|
|
||||||
code definition:
|
code definition:
|
||||||
{'tv': 'liuchang',
|
{'tv': 'liuchang',
|
||||||
'dvd': 'biaoqing',
|
'dvd': 'biaoqing',
|
||||||
'hd': 'gaoqing',
|
'hd': 'gaoqing',
|
||||||
'sdvd': 'chaoqing'}"""
|
'sdvd': 'chaoqing'}"""
|
||||||
c = json.loads(html)
|
c = json.loads(html)
|
||||||
#{'retmsg': 'ok', 'retcode': '200', 'selected': 'tv', 'mp4': [{'filename': '', 'http': 'http://jobsfe.funshion.com/query/v1/mp4/7FCD71C58EBD4336DF99787A63045A8F3016EC51.json', 'filesize': '96748671', 'code': 'tv', 'name': '流畅', 'infohash': '7FCD71C58EBD4336DF99787A63045A8F3016EC51'}...], 'episode': '626464'}
|
# {'retmsg': 'ok', 'retcode': '200', 'selected': 'tv', 'mp4':
|
||||||
|
# [{'filename': '', 'http': 'http://jobsfe.funshion.com/query/v1
|
||||||
|
# /mp4/7FCD71C58EBD4336DF99787A63045A8F3016EC51.json', 'filesize': '96748671',
|
||||||
|
# 'code': 'tv', 'name': '流畅', 'infohash': '7FCD71C58EBD4336DF99787A63045A8F3016EC51'}...], 'episode': '626464'}
|
||||||
video_dic = {}
|
video_dic = {}
|
||||||
for i in c['mp4']:
|
for i in c['mp4']:
|
||||||
video_dic[i['code']] = i['http']
|
video_dic[i['code']] = i['http']
|
||||||
@ -146,7 +167,9 @@ def select_url_from_video_api(html):
|
|||||||
url = [video_dic[quality] for quality in quality_preference_list if quality in video_dic][0]
|
url = [video_dic[quality] for quality in quality_preference_list if quality in video_dic][0]
|
||||||
html = get_html(url)
|
html = get_html(url)
|
||||||
c = json.loads(html)
|
c = json.loads(html)
|
||||||
#'{"return":"succ","client":{"ip":"107.191.**.**","sp":"0","loc":"0"},"playlist":[{"bits":"1638400","tname":"dvd","size":"555811243","urls":["http:\\/\\/61.155.217.4:80\\/play\\/1E070CE31DAA1373B667FD23AA5397C192CA6F7F.mp4",...]}]}'
|
# '{"return":"succ","client":{"ip":"107.191.**.**","sp":"0","loc":"0"},
|
||||||
|
# "playlist":[{"bits":"1638400","tname":"dvd","size":"555811243",
|
||||||
|
# "urls":["http:\\/\\/61.155.217.4:80\\/play\\/1E070CE31DAA1373B667FD23AA5397C192CA6F7F.mp4",...]}]}'
|
||||||
return [i['urls'][0] for i in c['playlist']]
|
return [i['urls'][0] for i in c['playlist']]
|
||||||
|
|
||||||
site_info = "funshion"
|
site_info = "funshion"
|
||||||
|
@ -4,22 +4,23 @@ import json
|
|||||||
# save info from common.print_info()
|
# save info from common.print_info()
|
||||||
last_info = None
|
last_info = None
|
||||||
|
|
||||||
|
|
||||||
def output(video_extractor, pretty_print=True):
|
def output(video_extractor, pretty_print=True):
|
||||||
ve = video_extractor
|
ve = video_extractor
|
||||||
out = {}
|
out = {'url': ve.url, 'title': ve.title, 'site': ve.name, 'streams': ve.streams}
|
||||||
out['url'] = ve.url
|
|
||||||
out['title'] = ve.title
|
|
||||||
out['site'] = ve.name
|
|
||||||
out['streams'] = ve.streams
|
|
||||||
if pretty_print:
|
if pretty_print:
|
||||||
print(json.dumps(out, indent=4, sort_keys=True, ensure_ascii=False))
|
print(json.dumps(out, indent=4, sort_keys=True, ensure_ascii=False))
|
||||||
else:
|
else:
|
||||||
print(json.dumps(out))
|
print(json.dumps(out))
|
||||||
|
|
||||||
# a fake VideoExtractor object to save info
|
|
||||||
class VideoExtractor(object):
|
class VideoExtractor(object):
|
||||||
|
"""
|
||||||
|
a fake VideoExtractor object to save info
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def print_info(site_info=None, title=None, type=None, size=None):
|
def print_info(site_info=None, title=None, type=None, size=None):
|
||||||
global last_info
|
global last_info
|
||||||
# create a VideoExtractor and save info for download_urls()
|
# create a VideoExtractor and save info for download_urls()
|
||||||
@ -29,17 +30,14 @@ def print_info(site_info=None, title=None, type=None, size=None):
|
|||||||
ve.title = title
|
ve.title = title
|
||||||
ve.url = None
|
ve.url = None
|
||||||
|
|
||||||
|
|
||||||
def download_urls(urls=None, title=None, ext=None, total_size=None, refer=None):
|
def download_urls(urls=None, title=None, ext=None, total_size=None, refer=None):
|
||||||
ve = last_info
|
ve = last_info
|
||||||
# save download info in streams
|
# save download info in streams
|
||||||
stream = {}
|
stream = {'container': ext, 'size': total_size, 'src': urls}
|
||||||
stream['container'] = ext
|
|
||||||
stream['size'] = total_size
|
|
||||||
stream['src'] = urls
|
|
||||||
if refer:
|
if refer:
|
||||||
stream['refer'] = refer
|
stream['refer'] = refer
|
||||||
stream['video_profile'] = '__default__'
|
stream['video_profile'] = '__default__'
|
||||||
ve.streams = {}
|
ve.streams = {'__default__': stream}
|
||||||
ve.streams['__default__'] = stream
|
|
||||||
output(ve)
|
output(ve)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user