function issupport(url)
    if url:match("^http://yunfile.com/") then return true end
    if url:match("^http://.*.yunfile.com/") then return true end
    if url:match("^http://filemarket.com/") then return true end
    return false   
end

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

function download(url)
		print('-----------------------Enter analyze-----------------------')
	print('url:'..url)
	
	agent = 'Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0'
	
	page1,head1 = idown.requesturl(url, agent, '')
	--print('page1:\n'..page1)

	print(head1)
	if page1:match('<span id="down_interval"') then 
		print('need wait 10 mins!!!!') 
		Sleep(600000)
		return -1
	end

	title = ''
    for w in string.gmatch(page1, '<meta name="keywords" content="([^%"]+)') do 
        print(w)
        title = w
    end
    title = unescapexml(title)
	print('title:'..title)

    
    realfilename = title

	url2 = ''
	for line in string.gmatch(page1, 'id="downpage_link" href="(.-)"') do
	    url2 = line
	end
	if (string.len(url2) == 0) then 
		return -1
	end
	url2 = 'http://yunfile.com'..url2
	print('url2:'..url2)
	
	page2 = idown.requesturl(url2, agent, url)
	--print('page2:\n'..page2)

	downformcode = page2:sub(page2:find('<form class="tform" id="down_from"(.-)</form>'))
    data = ''
    cookie = ''
    for k,v in string.gmatch(downformcode, 'input type="hidden" name="(.-)" value="(.-)"') do 
	data = data..k..'='..v..'&'
	if k == 'vid1' then
	    cookie = k..'='..v..'; '
	end
    end
    print('data:'..data)
    
    realurl = ''
    for w in string.gmatch(page2, '<form class="tform" id="down_from"([^%>]*)') do 
        print(w)
        for w1 in string.gmatch(w, 'action="(.-)"') do
            realurl = w1
        end
    end    
    
	result = {}
	result['encode'] = 65001
	result['verb'] = 'POST'
	result['realurl'] = realurl
	result['title'] = title
	result['realname'] = realfilename
	result['agent'] = agent
	result['redown'] = 1
	
	headers = {}
	headers['Referer'] = url2
	print('cookie:'..cookie)
	headers['Cookie'] = cookie
	result['headers'] = headers

	result['postdata'] = data

	result.debug = 1
	result.autoredir = 0    
    retstr = json:encode(result)
    print('ret:'..retstr)
	
	local downresult = idown.download(retstr)
	return downresult
end

function analyze(url)
	for i=1,10 do
		print('try:'..url)
		local result = download(url)
		if result == 0 then return 200 end
		print('download error! sleep for 1 min!')		
		idown.os.sleep(60000)
	end
	return -1
end