From 8a2f1306d812467814332f4be1ab9a322326c4ce Mon Sep 17 00:00:00 2001 From: Zhang Ning Date: Sun, 30 Aug 2015 17:22:32 +0800 Subject: [PATCH] Support HunanTV Known Iussue: sometimes 403 Forbidden no idle to get stream size Signed-off-by: Zhang Ning --- src/you_get/common.py | 3 +- src/you_get/extractors/hunan.py | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/you_get/extractors/hunan.py diff --git a/src/you_get/common.py b/src/you_get/common.py index 0a79ab98..ce204d1d 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -922,7 +922,7 @@ def script_main(script_name, download, download_playlist = None): sys.exit(1) def url_to_module(url): - from .extractors import netease, w56, acfun, baidu, baomihua, bilibili, blip, catfun, cntv, cbs, coursera, dailymotion, dongting, douban, douyutv, ehow, facebook, freesound, funshion, google, sina, ifeng, alive, instagram, iqiyi, joy, jpopsuki, khan, ku6, kugou, kuwo, letv, lizhi, magisto, miaopai, miomio, mixcloud, mtv81, nicovideo, pptv, qianmo, qq, sohu, songtaste, soundcloud, ted, theplatform, tudou, tucao, tumblr, twitter, vid48, videobam, vidto, vimeo, vine, vk, xiami, yinyuetai, youku, youtube, zhanqi + from .extractors import netease, w56, acfun, baidu, baomihua, bilibili, blip, catfun, cntv, cbs, coursera, dailymotion, dongting, douban, douyutv, ehow, facebook, freesound, funshion, google, sina, ifeng, alive, instagram, iqiyi, joy, jpopsuki, khan, ku6, kugou, kuwo, letv, lizhi, magisto, miaopai, miomio, mixcloud, mtv81, nicovideo, pptv, qianmo, qq, sohu, songtaste, soundcloud, ted, theplatform, tudou, tucao, tumblr, twitter, vid48, videobam, vidto, vimeo, vine, vk, xiami, yinyuetai, youku, youtube, zhanqi, hunan video_host = r1(r'https?://([^/]+)/', url) video_url = r1(r'https?://[^/]+(.*)', url) @@ -1001,6 +1001,7 @@ def url_to_module(url): 'youtu': youtube, 'youtube': youtube, 'zhanqi': zhanqi, + 'hunantv': hunan, } if k in downloads: return downloads[k], url diff --git a/src/you_get/extractors/hunan.py b/src/you_get/extractors/hunan.py new file mode 100644 index 00000000..edeb6933 --- /dev/null +++ b/src/you_get/extractors/hunan.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +__all__ = ['hunan_download'] + +from ..common import * +from ..extractor import VideoExtractor +from random import randint +import json +import re + +class Hunantv(VideoExtractor): + name = "芒果TV (HunanTV)" + + stream_types = [ + {'id': '超清', 'container': 'fhv', 'video_profile': '超清'}, + {'id': '高清', 'container': 'fhv', 'video_profile': '高清'}, + {'id': '标清', 'container': 'fhv', 'video_profile': '标清'}, + ] + + def get_vid_from_url(url): + """Extracts video ID from URL. + """ + return match1(url, "/([0-9]+).html") + + + def prepare(self, **kwargs): + assert self.url or self.vid + + if self.url and not self.vid: + self.vid = self.__class__.get_vid_from_url(self.url) + + rn = randint(0, 99999999) + api_url = 'http://v.api.hunantv.com/player/video?video_id={}&random={}'.format(self.vid,rn) + meta = json.loads(get_html(api_url)) + if meta['status'] != 200: + log.wtf('[failed] status: {}, msg: {}'.format(meta['status'],meta['msg'])) + if not meta['data']: + log.wtf('[Failed] Video not found.') + data = meta['data'] + + info = data['info'] + self.title = info['title'] + + self.lstreams = data['stream'] + + for lstream in self.lstreams: + self.streams[lstream['name']] = {'container': 'fhv', 'video_profile': lstream['name'], 'size' : 0} + + def extract(self, **kwargs): + if 'stream_id' in kwargs and kwargs['stream_id']: + # Extract the stream + stream_id = kwargs['stream_id'] + + if stream_id not in self.streams: + log.e('[Error] Invalid video format.') + log.e('Run \'-i\' command with no specific video format to view all available formats.') + exit(2) + else: + # Extract stream with the best quality + stream_id = self.streams_sorted[0]['id'] + + for lstream in self.lstreams: + if stream_id == lstream['name']: + rn = randint(0, 99999999) + meta = json.loads(get_html("{}&random={}".format((lstream['url']),rn))) + if meta['status'] == 'ok': + self.streams[stream_id]['src'] = [meta['info']] + +site = Hunantv() +download = site.download_by_url +hunan_download_by_vid = site.download_by_vid +download_playlist = playlist_not_supported('hunantv')