From aa10e9f9382fb36e19a6059f2d5f67982ff43228 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Thu, 3 Sep 2015 19:54:07 +0200 Subject: [PATCH] [yinyuetai] switch to JSON API, close #559 --- src/you_get/extractors/yinyuetai.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/you_get/extractors/yinyuetai.py b/src/you_get/extractors/yinyuetai.py index 3291c86d..097a083a 100644 --- a/src/you_get/extractors/yinyuetai.py +++ b/src/you_get/extractors/yinyuetai.py @@ -4,15 +4,11 @@ __all__ = ['yinyuetai_download', 'yinyuetai_download_by_id'] from ..common import * -def yinyuetai_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False): - assert title - html = get_html('http://www.yinyuetai.com/insite/get-video-info?flex=true&videoId=' + id) - - for quality in ['he\w*', 'hd\w*', 'hc\w*', '\w+']: - url = r1(r'(http://' + quality + '\.yinyuetai\.com/uploads/videos/common/\w+\.(?:flv|mp4)\?(?:sc=[a-f0-9]{16}|v=\d{12}))', html) - if url: - break - assert url +def yinyuetai_download_by_id(vid, title=None, output_dir='.', merge=True, info_only=False): + video_info = json.loads(get_html('http://www.yinyuetai.com/insite/get-video-info?json=true&videoId=%s' % vid)) + url_models = video_info['videoInfo']['coreVideoInfo']['videoUrlModels'] + url_models = sorted(url_models, key=lambda i: i['qualityLevel']) + url = url_models[-1]['videoUrl'] type = ext = r1(r'\.(flv|mp4)', url) _, _, size = url_info(url) @@ -20,7 +16,7 @@ def yinyuetai_download_by_id(id, title = None, output_dir = '.', merge = True, i if not info_only: download_urls([url], title, ext, size, output_dir, merge = merge) -def yinyuetai_download(url, output_dir = '.', merge = True, info_only = False): +def yinyuetai_download(url, output_dir='.', merge=True, info_only=False): id = r1(r'http://\w+.yinyuetai.com/video/(\d+)$', url.split('?')[0]) assert id html = get_html(url, 'utf-8')