local base = _G

module('ms_torrentsmd_com') 

Parameters =
	{
	Charset = 'utf-8',
	SearchUrl = 'http://torrentsmd.com/search.php?search_str=%s',
	Method = 'POST',
	Login = true,
	String = '',
	LoginUrl = 'http://torrentsmd.com/takelogin.php',
	Body = 'username=%s&password=%s',
	LoginHtml =
		'<html>\n' ..
		' <head>\n' ..
		'  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n' ..
		' </head>\n' ..
		' <script type="text/javascript">\n' ..
		'  setTimeout("document.login.submit()", 500);\n' ..
		' </script>\n' ..
		' <body>\n' ..
		'  <form method="POST" name="login" action="http://torrentsmd.com/takelogin.php">\n' ..
		'   <input type="hidden" name="username" value="%s">\n' ..
		'   <input type="hidden" name="password" value="%s">\n' ..
		'  </form>\n' ..
		' </body>\n' ..
		'</html>'
	}

function ListMedia(answer) 
	base.debug_in_file(answer .. '\n')
end

function InfoMedia(answer, data)
	--base.debug_in_file(answer .. '\n')
end

function GetUrl(mode, name)
	if mode == "Search" then
		local url = Parameters.SearchUrl
		return base.string.format(url, base.m_simpleTV.Common.string_toUTF8(name))
	end
	if (mode == "NextPage") or (mode == "PrevPage") then return name end
end

--Выполняется после регистрации на сайте
function SearchCode(session, url, str, answer)
	--base.debug_in_file(answer .. '\n')
	url = base.string.format(Parameters.SearchUrl, str)
	return base.m_simpleTV.WinInet.Get(session, url)
end