json = require('json')
require('common')

function issupport(url)
	if url:find('^http://union.bokecc.com/') then return true end
	if url:find('^http://v.bokecc.com/') then return true end
	if url:find('^http://hitmv.com/') then return true end
	if url:find('^http://www.iaidv.com/') then return true end
	return false
end

function analyze(url)
    print('url:'..url)
    local uid = url:match('siteid=(%w+)')
    local fid = url:match('vid=(%w+)')
    if uid==nil then
    page = idown.requesturl(url)
    
    uid = page:match('siteid=(%w+)')
    fid = page:match('vid=(%w+)')
    end

    print(uid,fid)

    local url2=string.format('http://union.bokecc.com/servlet/GetVideoStatus?videoID=%s&userID=%s&type=1&domain=union.bokecc.com', fid, uid)
    print('url2:'..url2)

    local page2 = idown.requesturl(url2)
    print(page2)
    
    local realurl = page2:match('flvPath="([^"]+)')
    print(realurl)
    
    local title = page2:match('title="([^"]+)')
    title = unescapexml(title)..getsuffix(realurl)
    local realfilename = title
    print(realfilename)

    local result = {}
    result['realurl'] = unescapexml(realurl)
    result['title'] = title
    result['realname'] = realfilename
    result['encode'] = 65001

    local retstr = json:encode(result)
    print('ret:'..retstr)
	
    return 1, retstr
end