require('idownx')

function issupport(url)
if url:match('^http://www.chinadaily.com.cn/') then return true end
return false
end

function analyze(url)
    --flashvars="id=13697&#38;head=http://mpub.chinadaily.com.cn/xmls/"
    local page = idown.requesturl(url)
    local id,head = page:match('flashvars="id=(%d+)&#38;head=(.-)"')
    print(id,head)
    local hash = idown.crypt.md5(id)
    print(hash)
    local p1,p2 = hash:sub(1,2),hash:sub(3,4)
    local xmlurl = string.format('%s%s/%s/%s.xml',head,p1,p2,id)
    local xmlpage = idown.requesturl(xmlurl)
    print(xmlpage)
    local title = xmlpage:match('<title><!%[CDATA%[(.-)]]></title>')
    local result = {
        title = title,
        realurl = xmlpage:match('<fileUrl>(.-)</fileUrl>'),
        realname = title..'.flv',
        encode = 65001
    }
    return 201,idown.encode(result)
end