you-get/src/you_get/extractors/cntv.py

69 lines
2.6 KiB
Python
Raw Normal View History

2012-09-01 20:35:22 +04:00
#!/usr/bin/env python
2017-08-11 11:27:37 +03:00
import json
import re
from ..common import get_content, r1, match1, playlist_not_supported
from ..extractor import VideoExtractor
2012-09-01 20:35:22 +04:00
__all__ = ['cntv_download', 'cntv_download_by_id']
2017-08-11 11:27:37 +03:00
class CNTV(VideoExtractor):
name = 'CNTV.com'
stream_types = [
{'id': '1', 'video_profile': '1280x720_2000kb/s', 'map_to': 'chapters4'},
{'id': '2', 'video_profile': '1280x720_1200kb/s', 'map_to': 'chapters3'},
{'id': '3', 'video_profile': '640x360_850kb/s', 'map_to': 'chapters2'},
{'id': '4', 'video_profile': '480x270_450kb/s', 'map_to': 'chapters'},
{'id': '5', 'video_profile': '320x180_200kb/s', 'map_to': 'lowChapters'},
]
ep = 'http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={}'
def __init__(self):
super().__init__()
self.api_data = None
def prepare(self, **kwargs):
self.api_data = json.loads(get_content(self.__class__.ep.format(self.vid)))
self.title = self.api_data['title']
for s in self.api_data['video']:
for st in self.__class__.stream_types:
if st['map_to'] == s:
urls = self.api_data['video'][s]
src = [u['url'] for u in urls]
stream_data = dict(src=src, size=0, container='mp4', video_profile=st['video_profile'])
self.streams[st['id']] = stream_data
def cntv_download_by_id(rid, **kwargs):
CNTV().download_by_vid(rid, **kwargs)
2012-09-01 20:35:22 +04:00
2017-08-11 11:27:37 +03:00
def cntv_download(url, **kwargs):
if re.match(r'http://tv\.cntv\.cn/video/(\w+)/(\w+)', url):
2017-08-11 11:27:37 +03:00
rid = match1(url, r'http://tv\.cntv\.cn/video/\w+/(\w+)')
2017-04-01 09:39:41 +03:00
elif re.match(r'http://tv\.cctv\.com/\d+/\d+/\d+/\w+.shtml', url):
2017-08-11 11:27:37 +03:00
rid = r1(r'var guid = "(\w+)"', get_content(url))
elif re.match(r'http://\w+\.cntv\.cn/(\w+/\w+/(classpage/video/)?)?\d+/\d+\.shtml', url) or \
re.match(r'http://\w+.cntv.cn/(\w+/)*VIDE\d+.shtml', url) or \
2016-06-30 09:43:41 +03:00
re.match(r'http://(\w+).cntv.cn/(\w+)/classpage/video/(\d+)/(\d+).shtml', url) or \
re.match(r'http://\w+.cctv.com/\d+/\d+/\d+/\w+.shtml', url) or \
re.match(r'http://\w+.cntv.cn/\d+/\d+/\d+/\w+.shtml', url):
2017-08-05 21:33:12 +03:00
page = get_content(url)
2017-08-11 11:27:37 +03:00
rid = r1(r'videoCenterId","(\w+)"', page)
if rid is None:
2017-08-05 21:33:12 +03:00
guid = re.search(r'guid\s*=\s*"([0-9a-z]+)"', page).group(1)
2017-08-11 11:27:37 +03:00
rid = guid
2012-09-01 20:35:22 +04:00
elif re.match(r'http://xiyou.cntv.cn/v-[\w-]+\.html', url):
2017-08-11 11:27:37 +03:00
rid = r1(r'http://xiyou.cntv.cn/v-([\w-]+)\.html', url)
2012-09-01 20:35:22 +04:00
else:
raise NotImplementedError(url)
2017-08-11 11:27:37 +03:00
CNTV().download_by_vid(rid, **kwargs)
2012-09-01 20:35:22 +04:00
site_info = "CNTV.com"
download = cntv_download
download_playlist = playlist_not_supported('cntv')