Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Автоперезакачка торрента — А как это вообще устроено? Как же авторизация, и т.д?
А вам не страшно держать столько торрентов?
1) Автоматический парсер дирректорий с поддиректориями с нахождением .torrent файлов и
nohup /root/scripts/notyfy.sh /opt/samba/torrent/video/ /opt/HDD/video/ &
nohup /root/scripts/notyfy.sh /opt/samba/torrent/music/ /opt/HDD/music/ &
nohup /root/scripts/notyfy.sh /opt/samba/torrent/distr/ /opt/HDD/distr/ &
#!/bin/bash
#как запустить в фоне
#nohup /root/scripts/notyfy.sh /opt/samba/torrent/video/ /opt/HDD/video/ &
#inotify-tools не забудьте поставить
[ $# -ne 2 ] && { echo Usage: $0 [/torrent/watch/dir/] [/when/torrent/download/]; exit; }
DIR=$1
DWN=$2
###Авторизация для трансмишеа
AUTH=" 192.168.1.1:9091 -n user:password "
while RES=$(inotifywait -e create $DIR --format %f .)
do
if [ ! -z `expr $RES : '.*\(torrent$\)'` ]; then
transmission-remote $AUTH -a $DIR/$RES --download-dir $DWN;
rm -f $DIR/$RES;
fi
done
вкидывает описание и прочее.
<?php
include_once("http.php");
class KinoPoisk {
public function Parse($subject) {
$p = '#itemprop="name">(.*)</h1>#';
preg_match($p, $subject, $matches);
$name=strip_tags($matches[1]);
$altname="";
$p = '#itemprop="alternativeHeadline">(.*)</span>#';
preg_match($p, $subject, $matches);
if(count ($altname)!=0)
$altname=$matches[1];
$p = '#<a href="/lists/m_act%5Byear%5D/(.*)/"#';
preg_match($p, $subject, $matches);
$year=$matches[1];
$p = '#<img width="205" src="(.*)" alt#';
preg_match($p, $subject, $matches);
$img=$matches[1];
$p = '#itemprop="description">(.*)</div>#';
preg_match($p, $subject, $matches);
$desc=$matches[1];
$p = '#IMDb:(.*)</div>#';
preg_match($p, $subject, $matches);
$imdb=$matches[1];
$p = '#rating_ball">(.*)</span>#';
preg_match($p, $subject, $matches);
$rating=$matches[1];
$p = '#itemprop="genre">(.*)#';
preg_match($p, $subject, $matches);
$genre=strip_tags($matches[1]);
return array("name"=> mysql_real_escape_string(html_entity_decode($name)),
"altname" => mysql_real_escape_string(html_entity_decode($altname)),
"img"=>$img,
"year"=>$year,
"genre"=>mysql_real_escape_string(html_entity_decode($genre)),
"desc"=>mysql_real_escape_string(html_entity_decode($desc)),
"IDMb"=>mysql_real_escape_string(html_entity_decode($imdb)),
"rate"=>mysql_real_escape_string(html_entity_decode($rating)));
}
public function GetAndParse($film) {
$curl = new HttpBurn();
$html = $curl->Get($film);
$data = $this->Parse(iconv('cp1251','utf-8',$html)) + array("URL"=>$film);
return $data;
}
public function Find($film) {
$curl = new HttpBurn();
$f = $curl->Get("www.kinopoisk.ru/index.php?first=no&what=&kp_query=".rawurlencode($film));
$p = '#<p class="pic"><a href=\"(.*)\"><img#';
preg_match($p, $f, $matches);
$f = $matches[1];
$p = '#film/(.*)/sr/#';
preg_match($p, $f, $matches);
$html = $curl->Get("http://www.kinopoisk.ru/film/".$matches[1]);
$data = $this->Parse(iconv('cp1251','utf-8',$html)) + array("URL"=>"http://www.kinopoisk.ru/film/".$matches[1]);
return $data;
}
}
<?php
class HttpBurn {
public $UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0";
public $headers = array
(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8',
'Accept-Language: ru,en-us;q=0.7,en;q=0.3',
'Accept-Encoding: deflate',
'Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7'
);
public $refer = "http://ya.ru";
public function Get($URL){
if($ch = curl_init($URL)){
curl_setopt ($ch, CURLOPT_USERAGENT, $this->UserAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER,$this->headers);
curl_setopt($ch, CURLOPT_REFERER, $this->refer);
curl_setopt($ch, CURLOPT_COOKIEJAR, "kino_coo.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "kino_coo.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
return null;
}
public function Post($url,$post){
if( $curl = curl_init($url) ) {
curl_setopt ($curl, CURLOPT_USERAGENT, $this->UserAgent);
curl_setopt($curl, CURLOPT_HTTPHEADER,$this->headers);
curl_setopt($curl, CURLOPT_REFERER, $this->refer);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$out = curl_exec($curl);
curl_close($curl);
return $out;
}
return null;
}
}
$o = new KinoPoisk();
$film = $o->Find("а зори здесь тихие");
var_dump($film);
Для меня киллер-фича rtorrent — это возможность выбора директории для закачки на сервере, при добавлениии торрента.
Альтернативные интерфейсы вроде rutorrent у меня как-то не прижились — ставить php только ради rutorrent неохота
ln downloaded_file new_file
# Если качается в папку incomplete (по умолчанию) - переместить данные завершённой закачки в папку complete
system.method.insert = finished_set4single,simple,"d.set_custom=incomplete,/home/torrents/incomplete"
system.method.insert = finished_set4multi,simple,"d.set_custom=incomplete,$cat=\{/home/torrents/incomplete/\\,$d.get_base_filename=\}"
system.method.insert = finished_if,simple,"equal={d.get_directory=,d.get_custom=incomplete}"
system.method.insert = finished_do,simple,"d.set_directory=/home/torrents/complete/;execute=mv,-u,$d.get_base_path=,/home/torrents/complete/"
system.method.set_key = event.download.finished,finished_event,"branch={$d.is_multi_file=,finished_set4multi=,finished_set4single=};branch={$finished_if=,finished_do=}"
Не понятно зачем лишние телодвижения
Фаил то переместится, а вот раздача отвалится.
____________________ | | | | |cover.jp|gsong1.m|p3| |________|________|__| __________ | | | |song1.mp|3| |________|_|
Разбираемся с rtorrent всерьёз