<commit_before>#!/usr/bin/env python

__all__ = ['cntv_download', 'cntv_download_by_id']

from common import *
import json
import re

def cntv_download_by_id(id, title=None, output_dir='.', stream_type=None):
	assert id
	info = json.loads(get_html('http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid='+id).decode('utf-8'))
	title = title or info['title']
	video = info['video']
	alternatives = [x for x in video.keys() if x.startswith('chapters')]
	assert alternatives in (['chapters'], ['chapters', 'chapters2']), alternatives
	chapters = video['chapters2'] if 'chapters2' in video else video['chapters']
	urls = [x['url'] for x in chapters]
	ext = r1(r'\.([^.]+)$', urls[0])
	assert ext in ('flv', 'mp4')
	download_urls(urls, title, str(ext), total_size=None)

def cntv_download(url):
	if re.match(r'http://news.cntv.cn/\d+/\d+\.shtml', url):
		id = r1(r'<!--repaste.video.code.begin-->(\w+)<!--repaste.video.code.end-->', get_html(url))
	elif re.match(r'http://xiyou.cntv.cn/v-[\w-]+\.html', url):
		id = r1(r'http://xiyou.cntv.cn/v-([\w-]+)\.html', url)
	else:
		raise NotImplementedError(url)
	cntv_download_by_id(id)

download = cntv_download
download_playlist = playlist_not_supported('cntv')

def main():
	script_main('cntv', cntv_download)

if __name__ == '__main__':
	main()

<commit_msg>fix #25<commit_after>#!/usr/bin/env python

__all__ = ['cntv_download', 'cntv_download_by_id']

from common import *
import json
import re

def cntv_download_by_id(id, title=None, output_dir='.', stream_type=None):
	assert id
	info = json.loads(get_html('http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid='+id).decode('utf-8'))
	title = title or info['title']
	video = info['video']
	alternatives = [x for x in video.keys() if x.startswith('chapters')]
	assert alternatives in (['chapters'], ['chapters', 'chapters2']), alternatives
	chapters = video['chapters2'] if 'chapters2' in video else video['chapters']
	urls = [x['url'] for x in chapters]
	ext = r1(r'\.([^.]+)$', urls[0])
	assert ext in ('flv', 'mp4')
	download_urls(urls, title, str(ext), total_size=None)

def cntv_download(url):
	if re.match(r'http://\w+\.cntv\.cn/(\w+/\w+/classpage/video/)?\d+/\d+\.shtml', url):
		id = r1(r'<!--repaste.video.code.begin-->(\w+)<!--repaste.video.code.end-->', get_html(url))
	elif re.match(r'http://xiyou.cntv.cn/v-[\w-]+\.html', url):
		id = r1(r'http://xiyou.cntv.cn/v-([\w-]+)\.html', url)
	else:
		raise NotImplementedError(url)
	cntv_download_by_id(id)

download = cntv_download
download_playlist = playlist_not_supported('cntv')

def main():
	script_main('cntv', cntv_download)

if __name__ == '__main__':
	main()


{'fraction_non_alphanumeric': 0.20916030534351146, 'fraction_numerical': 0.007633587786259542, 'mean_word_length': 5.081206496519721, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '384151', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1054, 'n_words': 197}