
function issupport(url)
    if url:match("^http://.-.cntv.cn") then return true end
    return false
end

function analyze(url)
require('common')
local json = require('json')
    print('-----------------------enter analyze-----------------------')
    print('url:'..url)
    page1 = idown.requesturl(url,'', '')
    --print('page1:\n'..page1)
    videoid = string.match(page1,"videoCenterId: '(.-)'") or page1:match('fo.addVariable%("videoCenterId","(.-)"')
    print('videoid:'..videoid)
    --通过获得的videoid拼接成下载地址浏览页面
    page2 = string.format('vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=%s',videoid)
    print('page2:'..page2)
    url1 ='vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid='..videoid
    print(url1)

    --通过下载页面获得原始下载地址
    req = {}
    page3 = idown.requesturl(url1,'','')
    retdata = json:decode(page3)
	print(page3)
	realurl = retdata.video.url
	print(realurl)
	if realurl ~= '' and realurl ~= nil then
    	t = split(realurl, '|')
    	
    	print('-------------------------------aaaaa----------------------------')
    	--打印table里的最后一个值
    	a=t[#t]
        print(a)
        b=string.gsub(a,";","\n")
        print(b)
    else
        print('no url')
        b = ''
        for i,v in ipairs(retdata.video.chapters) do
            b = b..v.url
            if i ~= #retdata.video.chapters then b = b..'\n' end
        end
    end
    realname=retdata.title
    print(idown.toansi(realname))
    
    --获取文件后缀
    suffix =getsuffix(getfilename(b))
    realfilename=realname..suffix
    result = {}
	result['agent'] = agent 
    result['realurl'] = b
    result['title'] = realname
    result['realname'] = realfilename
    result['encode'] = 65001
    retstr = json:encode(result)
	print('ret:'..retstr)
    print('-----------------------leave analyze-----------------------')
    return 1,retstr
end    
    