function issupport(url)
    if url:match("^http://%w+.tv189.com/") then return true end
    return false   
end

function GetLagestFile(page2)
    require("xml")
    for line in string.gmatch(page2,'(<url .-</url>)')do
        print(line)
        local x=xml.eval(line)
        print(x)
        print(x.sz)
        print(x[1])
        size = 0
        if tonumber(x.sz)>=size then
            size=tonumber(x.sz)
            realurl=x[1]
        end
    end
    print(size)
    print(realurl)
    return realurl
end

function analyze(url)
    require('common')
    json = require('json')
    print('---------------enter analyze---------------')
    print('url:'..url)
    local agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)'
    --打开网页
    page1=idown.requesturl(url,'','')
    -- print('page1:\n'..page1)
    --抓取id
    local id=string.match(page1,"pid = '(%d*)'")
    local index=string.match(page1,"index = '(%d*)'")      
    print(id)
    print(index) 
    --用id和index拼接成地址
    url1='http://pgmsvr.tv189.cn/program/getVideoPlayInfo?pid='..id..'&indexid='..index..'&nocache=766'
    page2=idown.requesturl(url1,'','')
    --print(page2)
    local realurl = GetLagestFile(page2)
    realname = string.match(page2,'<tt><!%[CDATA%[(.*)]]></tt>') 
    print(idown.toansi(realname))   
    --获取文件后缀
    suffix =getsuffix(getfilename(realurl))
    realfilename=realname..suffix
    result = {}
	result['agent'] = agent 
    result['realurl'] = realurl
    result['title'] = realname
    result['realname'] = realfilename
    result['encode'] = 65001
    retstr = json:encode(result)
	print('ret:'..retstr)
    print('-----------------------leave analyze-----------------------')
    return 1,retstr
end