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

function issupport(url)
    if url:match('^http://play.9sky.com/t_%d+/') then return true end
    return false
end

function analyze(url)
	print('-----------------------Enter analyze-----------------------')
	print('url:'..url)
	
	page = idown.requesturl(url)
	
	id = url:match('t_(%d+)')
	print(id)
	
	url2 = string.format('http://play.9sky.com/proxy/cache/proxy.aspx?act=exd&id=%s&type=0&ver=0.0.0.0', id)
	page = idown.requesturl(url2, '', url)
	
	page = page:gsub("%%u", "\\u")
	detail = json:decode(page)
	print(page)
	
	name = unescape(detail['info']['title'])
	realfilename = name..'.wma'
	title = realfilename
	realurl = string.format('http://co.9sky.com/api/sina/weibo-play.aspx?id=%s', id)
	
	result = {}
	result['realurl'] = realurl
	result['title'] = title
	result['realname'] = realfilename
	result['encode'] = 65001
	
	retstr = json:encode(result)
	print('ret:'..retstr)

	print('-----------------------Leave analyze-----------------------')
	return 1, retstr
end