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

function issupport(url)
    print(url)
    if url:match('^http://%w+.5sing.com/%d+.html') then return true end
    return false
end

function analyze(url)
	print('-----------------------Enter analyze-----------------------')
	print('url:'..url)
	
	page,head = idown.requesturl(url)
	--print('page:\n'..page)
	
	--获取标题
	title = page:match('var SongName   = "([^"]*)')
	local singerid = page:match('singerID: (%d+)')
	local singer = page:match(string.format('<a href="http://%s.5sing.com" title="(.-)"', singerid))
	local cookie2 = head:match("(SingLinkGate=.-);")

	title = title..' - '..singer
	print('title:'..title)

    --获得文件地址      
	realurl = page:match('file:%s*"(.-)"')
	print('realurl:'..realurl)
		
	result = {}
	result['realurl'] = realurl
	result['title'] = title
	result['realname'] = title..'.mp3'
	result['agent'] = 'NSPlayer/11.0.5721.5275 WMFSDK/11.0'
	result['encode'] = 65001
	
	headers = {}
	headers['Cookie'] = cookie or cookie2
	result['headers'] = headers
		
	retstr = json:encode(result)
	print('ret:'..retstr)
	
	return 1, retstr
end