function get_trackers() return '{\r\n' ..'"agent":"FlylinkDC++",\r\n' ..'"page_limit":10,\r\n' ..'"version":"4",\r\n' ..'"items":\r\n' ..'[\r\n' ..'{\r\n' ..'"url":"http://45.9.75.137/rtor/",\r\n' ..'"url_top":"http://45.9.75.137/rtor/top",\r\n' ..'"name":"torrent",\r\n' ..'"page_limit":20,\r\n' ..'"index":0\r\n' ..'}\r\n' ..']\r\n' ..'}\r\n' end function get_url(p_tracker_index, p_search, p_category, p_page, p_whole_word, p_sort, p_desc) if p_tracker_index == 0 then return 'http://45.9.75.137/rtor/search/'..p_page..'/0/300/2/'..p_search end if p_tracker_index == 1 then -- return 'https://thepiratebay.org/search/'..p_search..'/'..p_page..'/7//' return '' end if p_tracker_index == 2 then return 'http://www.digbt.org/search/'..p_search..'/?u=y' end return '' end -- Дополнительные функции Должны находиться ВЫШЕ тех функций, откуда вызваны -- ********************************************************************** tMonth = {"Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Oct","Nov","Dec"} tMonthRus = {"Янв","Фев","Мар","Апр","Май","Июн","Июл","Авг","Сен","Окт","Ноя","Дек"} ------------- Преобразование регистра строк ------------- String2Lower = function(s) for i = 192, 223 do s = s:gsub(_G.string.char(i), _G.string.char(i + 32)) end s = s:gsub(_G.string.char(168), _G.string.char(184)) return s:lower() end ------------- Преобразование рус названия месяца в латинский вид ------------- function RenameMonth(month) for i,v in ipairs(tMonthRus) do if String2Lower(v)==String2Lower(month) then month=tMonth[i] end end return month end ------------- Форматирование даты из TPB наш формат ------------- function GetPBDate(msg) -- Дата формата 02-14 2010 msg = tostring(msg) local res, m,d,y = '', '01','01','2035' -- На случай косяка, укажем дату по дефолту if msg:match("(%d%d)-(%d%d) (.*)") then m,d,y = msg:match("(%d%d)-(%d%d) (.*)") -- Разделим дату на части if y:match(".-:.*") then -- В Дате, в параметре ГОД может встретиться время час:мин -- y = os.date("%y") -- Заменим это время на текущий год y = 17 end end y = tonumber(y) -- Для математических операций и сравнения, приведём год к числовому виду if y>2000 then y = y-2000 end -- Убираем 20хх у ГОДа if y<10 then y = "0"..y end -- Добавляем 0 перед числами до 10 res = d..''..tMonth[tonumber(m)]..''..y return res end -- =============================================================== -- mirror function check_error(p_tracker_index,p_body) if p_tracker_index==0 then return '' elseif p_tracker_index==1 then return '' elseif p_tracker_index==2 then return '' end end -- =============================================================== function search_group_id(p_tracker_index,p_body) p_tracker_index = tonumber(p_tracker_index) local res="" if p_tracker_index < 0 or p_body=="" then return '' end local _rn, _nt = '\r\n', '\n\t' res = '{ "items":'.._rn..'['.._rn local sep = '' if p_tracker_index == 0 then for h2_name in p_body:gmatch("

(.-)

") do local _href, _name = h2_name:match("(.-)") if _name ~= '' and _name ~= nil then res = res..sep..'' sep = ',' res = res..'"'.._name..'"'.._nt else sep = ',' res = res..'"'..""..'"'.._nt end end end res = res.._rn..']'.._rn..'}'.._rn return res end -- =============================================================== function search(p_tracker_index, p_body) p_tracker_index = tonumber(p_tracker_index) -- Убедимся что в индексе получили число. if p_tracker_index<0 or p_body=="" then return '' end -- Если вводные параметры отсутствуют или неверны, вернём пустоту. Экономим время. l_count=0 glob_mas = {} -- SWITCH CASE в LUA нет, можно написать обёртку, но работать она будет медленнее простого IF ELSE if p_tracker_index==0 then GetPage0(p_body) elseif p_tracker_index==1 then GetPage1(p_body) elseif p_tracker_index==2 then -- Index 2 GetPage1(p_body) end --[[ ********************************************************************** На вход принимаем двухуровневую таблицу glob_mas с блоками параметров в каждом уровне: PAR1 | PAR2 | PAR3 -> Имя раздачи|Магнет-ссылка|Линк на страницу раздачи PAR1 || PAR2 -> Имя раздачи||Линк на страницу раздачи (парсер 1) xxMGNT -> Магнет-ссылка (парсер 1) xxPEERxxSEED -> Числа Пиров и Сидов xxB -> Размер в Байтах 11Mar17 -> Дата размещения торрента xxCOMM -> Число комментариев xGROUP_ID -> ID Группы все прочее - reserved ]]-- local _rn, _nt = '\r\n', '\n\t' -- Cosmetic: if need, change to '', '' res = '{ "items":'.._rn..'['.._rn local sep = '' for i,v in pairs(glob_mas) do res = res..sep..' {' sep = ',' local sep2 = '' for k,v in pairs(v) do res = res..sep2.._nt sep2 = ',' -- BEGIN for Index 0 only if v:match("(.*)|(.*)|(.*)") then -- Проверим, попался ли разделитель Имени|Бит-ссылки ? local _name,_tm,_tu = v:match("(.*)|(.*)|(.*)") -- Попался, разделим данные на части _name=_name:gsub(""","'") -- _name=_name:gsub("\"","'") _name=_name:gsub("'","'") _name=_name:gsub("\\","\\\\") res = res..'"name" : "'.._name..'",'.._nt if _tm~='' then res = res..'"magnet" : "'.._tm..'",'.._nt end res = res..'"url" : "'.._tu..'"' l_count = l_count+1 -- Считаем кол-во имеющихся раздач, даже без остальных данных? elseif v:match("(.-)MGNT") then local _tm = v:match("(.-)MGNT") res = res..'"magnet" : "'.._tm..'"' elseif v:match("(.-)GROUP_ID") then local _th = v:match("(.-)GROUP_ID") res = res..'"group_id" : "'.._th..'"' elseif v:match("(.-)B") then v=v:gsub(",",".") res = res..'"size" : "'..v..'"' elseif v:match("(%d+)PEER(%d+)SEED") then local _p,_s = v:match("(%d+)PEER(%d+)SEED") res = res..'"peer" : "'.._p..'",'.._nt res = res..'"seed" : "'.._s..'"' --[-]PPA elseif v:match("date:(.*)") then --[-]PPA res = res..'"date" : "'..v:match("date:(.*)")..'"' elseif v:match("%d%d%S+%d%d") then local _d,_m,_y = v:match("(%d%d)(%S+)(%d%d)") -- можно и такую регулярку: ("(%d+)(S+)(%d+)") res = res..'"date" : "'.._d..' '..RenameMonth(_m)..' '.._y..'"' -- Получим 04 Апр 17 elseif v:match("(%d+)COMM") then res = res..'"comment" : "'..v:match("(%d+)COMM")..'"' else res = res..'"reserved" : "'..v..'"' end end res = res.._rn..' }' end res = res.._rn..']'.._rn..'}'.._rn if l_count > 0 then return res end return '' end -- local function GetH2(p_body) -- header_name ="" -- for h2_name in p_body:gmatch("

(.-)

") do -- local _href, _name = h2_name:match("(.-)") -- header_name = _name -- end -- return header_name -- end -- Index 0 : RUTOR, KINO-TOR, fast-bit.org function GetPage0(p_body) local header_name="" local table_count=0; for div_index in p_body:gmatch("
") do -- if header_name == "" then -- header_name = GetH2(div_index) -- end for q_table in div_index:gmatch("") do table_count = table_count+1 header_name = table_count -- Обходим таблицы(пока только одну) for ind in q_table:gmatch("") do if ind then mas = {} -- Заинитим/очистим массив for td_index in ind:gmatch("") do if td_index:match("href=\"m(.-)\"><.-f=\"(.*)\">(.-)") then -- Name | link local _tm,_tu,_name = td_index:match("href=\"m(.-)\"><.-f=\"(.*)\">(.-)") _name=_name:gsub("\"","'") td_index = ("%s|m%s|%s"):format(_name:gsub("|","/"),_tm,_tu) end if td_index:match("right\"(.-) (.-)(.-)class=\"red\"> (.-)") then local _pp,_,_ss = td_index:match("alt=\"S\" /> (.-)(.-)class=\"red\"> (.-)") -- td_index = td_index:match("alt=\"S\" /> (.-)").."PEER" td_index = ("%sPEER%sSEED"):format(_pp,_ss) end td_index=td_index:gsub(" ","") td_index=td_index:gsub("\"","'") td_index=td_index:gsub("(.-)>","") -- Уберём весь мусор типа align="... table.insert (mas, td_index) end table.insert (mas, ("%sGROUP_ID"):format(header_name)) table.insert (glob_mas, mas) end end end end return glob_mas end -- Index 1 : The Pirate Bay function GetPage1(p_body) for ind in p_body:gmatch("
") do -- РАЗОБЬЕМ HTML НА БЛОКИ С ФАЙЛО-ССЫЛКАМИ if ind then mas = {} -- Заинитим/очистим массив if ind:match("href=\"/tor(.-)\"(.-)>(.-)") then -- Name | link local _tl,_ttt,_name = ind:match("href=\"/tor(.-)\"(.-)>(.-)") _name=_name:gsub("","") _name=_name:gsub("","") _name=_name:gsub("\"","'") table.insert (mas, ("%s||/tor%s"):format(_name:gsub("|","/"),_tl)) end if ind:match("href=\"m(.-)\" title") then local _tm = ind:match("href=\"m(.-)\" title") table.insert (mas, ("m%sMGNT"):format(_tm)) end if ind:match("This torrent has(.-)comments.") then _cm = ind:match("This torrent has (.-) comments.") _cm=_cm:gsub(" ","'") table.insert (mas, ("%sCOMM"):format(_cm)) end if ind:match("Uploaded(.*)by") then local _upl = ind:match("Uploaded (.*)by") local _date = _upl:match("(.-),") _date=_date:gsub(" "," ") table.insert (mas, GetPBDate(_date)) local _size = _upl:match("Size (.*),") _size=_size:gsub(" "," ") _size=_size:gsub("i","") _size=_size:gsub(" ","") table.insert (mas, _size) end if ind:match("(.-).*(.-)") then -- Peers count local _dnl,_upl = ind:match("(.-).*(.-)") table.insert (mas, _dnl.."PEER".._upl.."SEED") end end table.insert (glob_mas, mas) end return glob_mas end