Универсальный парсер

Универсальный парсер 0.7.2

Нет прав для скачивания

ExPlayer

Пользователь
Доброго времени суток!
Версия TP: 2.1.4 (да, старая. да, не поддерживается.)
VPS располагается в Нидерландах (Inferno Solutions).
Сегодня вечером перестал парсится рутор (снова стало появляться сообщение "Введите текст сообщения", до сегодняшнего вечера парсер работал нормально).
Я уж подумал, что придется снова искать хостинг (в прошлый раз помог только переезд на новый хостинг :( ).
Но, после обращения в тех. поддержку хостинга оказалось, что у рутора стоит редирект на домен free-rutor.org.
Я это всё к тому, что если у кого-то возникнет похожая проблема, то попробуйте добавить free-rutor.org в functions_parser.php и parser.php.
Лично у меня так:
functions_parser.php:
PHP:
function parse_release($url,$p_source, $gettorrent)
{
    switch ($p_source){
        case "free-rutor": $p_release = parse_freerutor($url, $gettorrent);break;
    }
    return $p_release;
}

function parse_freerutor($url, $gettorrent)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'IE20');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1');
    $copy_page = curl_exec($ch);
    curl_close($ch);
    
    preg_match("#\<table id=\"details\"\>.*?<br />(.*?)\<tr\>\<td class=\"header\"\>#si", $copy_page, $copy_post);
    preg_match ("#<title>free-rutor.org :: (.*?)</title>#si", $copy_page, $r_title);

    $copy_release = @$copy_post[1];

    $text = preg_replace("#<a href=\"(.*?)\".*?>(.*?)</a>#si", "[url=\\1]\\2[/url]", $copy_release);
    $text = preg_replace("#<img src=\"(\S*?)\" style=\"float:(.*?);\" />#si", "[img=\\2]\\1[/img]", $text);
    $text = preg_replace("#<img src=\"(\S*?)\" />#si", "[img]\\1[/img]", $text);
    $text = preg_replace("#<hr />#si", "[hr]", $text);

    //hide
    while (preg_match("#<div class=\"hidewrap\">.*?this\)\)\">(.*?)</div>.*?<textarea class=\"hidearea\">(.*?)</textarea></div>#sie", $text, $match))
    {
        $replace = "[spoiler=\"".strip_tags($match[1])."\"]".$match[2]."[/spoiler]";
        $search = "|".preg_quote($match[0])."|si";
        $text = preg_replace($search, $replace, $text);
    }       
    //u i b center
    while (preg_match("#<(.*?)>(.*?)<\/\\1>#sie", $text, $match))
    {
        switch ($match[1])
        {
          case "center": $replace = "[align=".$match[1]."]".$match[2]."[/align]"; break;
          default: $replace = "[".$match[1]."]".$match[2]."[/".$match[1]."]";break;
        }
        $search = "|".preg_quote($match[0])."|si";
        $text = preg_replace($search, $replace, $text);
    }
    
    //size
    while (preg_match("#<font size=\"(\d+)\">(.*?)<\/font>#sie", $text, $match))
    {
        $replace = "[size=".(intval($match[1])+10)."]".$match[2]."[/size]";
        $search = "|".preg_quote($match[0])."|si";
        $text = preg_replace($search, $replace, $text);
    }
    //color font
    while (preg_match("#<(?:span) (?:(?:style=\"((?:[^>]*?)):((?:[^>]*?));\">))((?:(?!<(?:span) ).)*?)</(?:span)>#sie", $text, $match))
    {
        switch ($match[1]){
          case "font-family": $replace = "[font=\"".$match[2]."\"]".$match[3]."[/font]";break;
          case "color":    $replace = "[".$match[1]."=".$match[2]."]".$match[3]."[/".$match[1]."]";break;
        }
        $search = "|".preg_quote($match[0])."|si";
        $text = preg_replace($search, $replace, $text);
        
    }   

    if ($gettorrent === 1) {
        preg_match ("#<a href=\"(http:\/\/d\.free-rutor\.org\/download\/\d+)\"#si", $copy_page, $r_torrent);
        $torrent_url = @$r_torrent[1];
        $options_torrent = array(CURLOPT_URL => $torrent_url);
        $torrent_hidden = get_torrent($options_torrent);
    }else {
        $torrent_hidden = '';
    }

    $pars_data = array("title" => @$r_title[1], "bbcode" => strip_tags($text), "hidden" => $torrent_hidden);
    return $pars_data;

}

parsep.php:
PHP:
<?php

if (!defined('IN_AJAX')) die(basename(__FILE__));

global $bb_cfg, $userdata, $lang, $bnc_error;

if ($bb_cfg['parsmod_disable']) $this->ajax_die($lang['PARS_NO_WORK']);
if (empty($this->request['pars_url']))     $this->ajax_die($lang['PARS_NO_URL']);

$gettorrent = isset($this->request['gettorrent'])? intval($this->request['gettorrent']):0;
$tor_id = isset($this->request['tor_id'])? intval($this->request['tor_id']):'';
$pars_url = $this->request['pars_url'];
$allowed_sources = array("free-rutor");

preg_match("#.*(?:\.|\/)(.*?)\.\w+\/#si", $pars_url, $s_domain);
if (!in_array($s_domain[1], $allowed_sources)) $this->ajax_die($lang['PARS_NOT_ALLOWED_SOURCES']);

if ($tor_id)    delete_old_torrent($tor_id);

$p_data = parse_release($pars_url, $s_domain[1], $gettorrent);


$this->response['title'] = $p_data['title'];
$this->response['bbcode'] = $p_data['bbcode'];
$this->response['hid'] = $p_data['hidden'];
На данный момент работает. :)
 

Kirkus

Пользователь
Все парсит кроме торрента, не подскажете что не так в блоке

Код:
    if ($gettorrent === 1) {
      
       preg_match ("#<a href=\"(http:\/\/film-tor\.org\/download\/\d+)\"#si", $copy_page, $r_torrent);
        $torrent_url = @$r_torrent[1];
        $options_torrent = array(CURLOPT_URL => $torrent_url);
        $torrent_hidden = get_torrent($options_torrent);
    }else {
        $torrent_hidden = '';
    }

    $pars_data = array("title" => @$r_title[1], "bbcode" => strip_tags($text), "hidden" => $torrent_hidden);
    return $pars_data;
 

daemonz

Пользователь
R600 rus. Запара с аяксом. Может кто сможет, уже как надо отредактированный файл кинуть?
 

Вложения

  • Безымянный.png
    Безымянный.png
    60.9 KB · Просмотры: 57

Kirkus

Пользователь
@Kirkus
парсер не заточен под домен film-tor[.]org

Это конечно прекрасный ответ! Спасибо. Но почему-то у меня ВСЁ парсит кроме торрент файла? Торрент 0 байт. Вероятно, ошибка в строчке

Код:
  preg_match ("#<a href=\"(http:\/\/film-tor\.org\/download\/\d+)\"#si", $copy_page, $r_torrent);
 

Gaus111

Пользователь
Откатился на V 2.1.5
Поставил парсер 0.7.2
Перелопатил всю тему что бы не сыпать кучей вопросов.
Собрал все правки и фиксы по файлам. Сам парсер работает
но всё равно не скачивает файл торента, он нулевой.
И при парсе текста с топика всё равно по всей теме кидает этот bb-код [font-serif1]
Вот скрин файла и сам файл прикрепляю.
Кто поможет ребят. ? Если кто из Киева с меня пивас в благодарочку)))
Снимок3.PNGtreker.PNG
 

Вложения

  • functions_parser.rar
    3.1 KB · Просмотры: 11
Последнее редактирование:

Virtuoz

Пользователь
Откатился на V 2.1.5
Поставил парсер 0.7.2
Перелопатил всю тему что бы не сыпать кучей вопросов.
Собрал все правки и фиксы по файлам. Сам парсер работает
но всё равно не скачивает файл торента, он нулевой.
И при парсе текста с топика всё равно по всей теме кидает этот bb-код [font-serif1]
Вот скрин файла и сам файл прикрепляю.
Кто поможет ребят. ? Если кто из Киева с меня пивас в благодарочку)))
Посмотреть вложение 5155Посмотреть вложение 5156
Оригинальное решение проблемы сделать откат, а то что на трекерах с которых парсят не сидят на жопе ровно и код меняют ни о чем не говорит? По шрифту то тебе в posting_editor.tpl
 
Сверху