require('idownx')

function issupport(url)
if url:match('http://www.imgo.tv/') then return true end
return false
end

function analyze(url)
local page = idown.requesturl(url)
--<dd class="des" style="display:none;" id="story" csvc='n' ctid='63' ccid='258998' cfid='270357' cym='201206' cfstid='1' cpname='湖南卫视7月改版宣传片 栏目版' 

local pattern = "csvc='(.-)' ctid='(%d+)' ccid='(%d+)' cfid='(%d+)' cym='(%d+)' cfstid='(%d+)' cpname='(.-)'"
local csvc,ctid,ccid,cfid,cym,cfstid,title = page:match(pattern)
local url2 = string.format('http://www.imgo.tv/PowerPlayer.aspx?fstlvlId=%s&tid=%s&cid=%s&fid=%s&ym=%s&pay=%s',cfstid,ctid,ccid,cfid,cym,csvc)
local page2 = idown.requesturl(url2)

--var server="121.11.70.7";var port="8080";var plur="
local server,port,plur,pars=page2:match('var server="(.-)";var port="(.-)";var plur="(.-)";var conpars="(.-)"')
local realurl = string.format('http://%s:%s/?videoname=%s&client=flash&pars=%s',server,port,plur,pars)
local result = {
	title = title,
	realurl = realurl,
	realname = title..'.flv',
	encode = 65001
}
return 201,idown.encode(result)
end