aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dl/extractor/cctv.py
diff options
context:
space:
mode:
authorRemita Amine <remitamine@gmail.com>2016-09-07 10:10:43 +0100
committerRemita Amine <remitamine@gmail.com>2016-09-07 10:11:09 +0100
commit846d8b76a07f617b595e0f1a2ae7ba22acafd98d (patch)
treedc87b7002bd3d0b8c9b5b51d8956ca9a77efd3b9 /youtube_dl/extractor/cctv.py
parentaa3f9fe695134719de87837238045beec10c4ab5 (diff)
downloadyoutube-dl-846d8b76a07f617b595e0f1a2ae7ba22acafd98d.zip
youtube-dl-846d8b76a07f617b595e0f1a2ae7ba22acafd98d.tar.gz
youtube-dl-846d8b76a07f617b595e0f1a2ae7ba22acafd98d.tar.bz2
[cctv] Add new extractor(closes #8153)
Diffstat (limited to 'youtube_dl/extractor/cctv.py')
-rw-r--r--youtube_dl/extractor/cctv.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/youtube_dl/extractor/cctv.py b/youtube_dl/extractor/cctv.py
new file mode 100644
index 0000000..72a72cb
--- /dev/null
+++ b/youtube_dl/extractor/cctv.py
@@ -0,0 +1,53 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+import re
+
+from .common import InfoExtractor
+from ..utils import float_or_none
+
+
+class CCTVIE(InfoExtractor):
+ _VALID_URL = r'''(?x)https?://(?:.+?\.)?
+ (?:
+ cctv\.(?:com|cn)|
+ cntv\.cn
+ )/
+ (?:
+ video/[^/]+/(?P<id>[0-9a-f]{32})|
+ \d{4}/\d{2}/\d{2}/(?P<display_id>VID[0-9A-Za-z]+)
+ )'''
+ _TESTS = [{
+ 'url': 'http://english.cntv.cn/2016/09/03/VIDEhnkB5y9AgHyIEVphCEz1160903.shtml',
+ 'md5': '819c7b49fc3927d529fb4cd555621823',
+ 'info_dict': {
+ 'id': '454368eb19ad44a1925bf1eb96140a61',
+ 'ext': 'mp4',
+ 'title': 'Portrait of Real Current Life 09/03/2016 Modern Inventors Part 1',
+ }
+ }, {
+ 'url': 'http://tv.cctv.com/2016/09/07/VIDE5C1FnlX5bUywlrjhxXOV160907.shtml',
+ 'only_matching': True,
+ }, {
+ 'url': 'http://tv.cntv.cn/video/C39296/95cfac44cabd3ddc4a9438780a4e5c44',
+ 'only_matching': True
+ }]
+
+ def _real_extract(self, url):
+ video_id, display_id = re.match(self._VALID_URL, url).groups()
+ if not video_id:
+ webpage = self._download_webpage(url, display_id)
+ video_id = self._search_regex(
+ r'(?:fo\.addVariable\("videoCenterId",\s*|guid\s*=\s*)"([0-9a-f]{32})',
+ webpage, 'video_id')
+ api_data = self._download_json(
+ 'http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=' + video_id, video_id)
+ m3u8_url = re.sub(r'maxbr=\d+&?', '', api_data['hls_url'])
+
+ return {
+ 'id': video_id,
+ 'title': api_data['title'],
+ 'formats': self._extract_m3u8_formats(
+ m3u8_url, video_id, 'mp4', 'm3u8_native', fatal=False),
+ 'duration': float_or_none(api_data.get('video', {}).get('totalLength')),
+ }