mirror of
https://github.com/house-of-vanity/tracker_watcher.git
synced 2025-07-07 18:04:06 +00:00
Initial commit
Work in progress. It doesn't work right now.
This commit is contained in:
77
add.php
Normal file
77
add.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
// TODO. Rewrite connection bs
|
||||||
|
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root');
|
||||||
|
|
||||||
|
// Check all vars presented
|
||||||
|
if (
|
||||||
|
!(isset($_POST['url']) && isset($_POST['telegram'])) ||
|
||||||
|
strlen($_POST['url']) == 0 ||
|
||||||
|
strlen($_POST['telegram']) == 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
die("Check your parameters is valid.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$url = $_POST['url'];
|
||||||
|
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
|
||||||
|
die('Not a valid URL');
|
||||||
|
}
|
||||||
|
parse_str((parse_url($url, PHP_URL_QUERY)), $url);
|
||||||
|
$url = $url['t'];
|
||||||
|
$username = $_POST['telegram'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check url is valid
|
||||||
|
|
||||||
|
// check user already reqested notify about this topic
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'SELECT c.username, u.link FROM `contact` c
|
||||||
|
LEFT JOIN `url` u ON u.id = c.topic_id
|
||||||
|
WHERE c.username = "'.$username.'" AND u.link = "'.$url.'"'
|
||||||
|
);
|
||||||
|
if($stmt->rowCount() > 0)
|
||||||
|
{
|
||||||
|
die("Exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
// trying to find same url in db
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'SELECT id FROM `url`
|
||||||
|
WHERE link = "'.$url.'"'
|
||||||
|
);
|
||||||
|
if($stmt->rowCount() > 0)
|
||||||
|
{
|
||||||
|
// make notify for new user using presented url id
|
||||||
|
$id = $stmt->fetch();
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'INSERT into contact (username, topic_id)
|
||||||
|
VALUES ("'.$username.'","'.$id['id'].'")'
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
// insert new url and user in db
|
||||||
|
$json = file_get_contents(
|
||||||
|
'http://api.rutracker.org/v1/get_tor_topic_data?by=topic_id&val='.$url
|
||||||
|
);
|
||||||
|
$obj = json_decode($json);
|
||||||
|
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'INSERT into url (link,u_date)
|
||||||
|
VALUES ("'.$url.'","'.gmdate("Y-m-d H:i:s", $obj->result->{$url}->reg_time).'")'
|
||||||
|
);
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'SELECT id FROM url WHERE link="'.$url.'"'
|
||||||
|
);
|
||||||
|
$new_topic_id = $stmt->fetch();
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'INSERT into contact (username, topic_id)
|
||||||
|
VALUES ("'.$username.'","'.$new_topic_id['id'].'")'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
while ($row = $stmt->fetch())
|
||||||
|
{
|
||||||
|
echo $row['link'] . "\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
?>
|
22
index.php
Normal file
22
index.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Let me know</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Rutracker notifyer </h1>
|
||||||
|
<h3>I will notify you when interesting for you topic will be updated.</h3>
|
||||||
|
<form action="add.php" method="post">
|
||||||
|
<label>URL </label><input name="url" type="text"><br>
|
||||||
|
<label>Telegram </label><input name="telegram" type="text">
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
28
updater.php
Normal file
28
updater.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
// TODO. Rewrite connection bs
|
||||||
|
// UTC time
|
||||||
|
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root');
|
||||||
|
|
||||||
|
$stmt = $dbh->query(
|
||||||
|
'SELECT * FROM `url`'
|
||||||
|
);
|
||||||
|
while ($url = $stmt->fetch())
|
||||||
|
{
|
||||||
|
$json = file_get_contents(
|
||||||
|
'http://api.rutracker.org/v1/get_tor_topic_data?by=topic_id&val='.$url['link']
|
||||||
|
);
|
||||||
|
$obj = json_decode($json);
|
||||||
|
printf(
|
||||||
|
"Topic id is %s. Add date %s, Update date %s. Title %s.<br>",
|
||||||
|
$url['link'],
|
||||||
|
$url['c_date'],
|
||||||
|
gmdate("Y-m-d H:i:s", $obj->result->{$url['link']}->reg_time),
|
||||||
|
$obj->result->{$url['link']}->topic_title
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
01.16
|
||||||
|
Topic id is 5504902. Add date 2018-01-16 23:34:35, Update date 2018-01-13 20:43:04. Title Цитрус / Citrus (Такахаси Такэо) [TV] [1-2 из 12] [Без хардсаба] [JAP+SUB] [2018, Драма, романтика, школа, сёдзе ай, WEBRip] [1080p].
|
||||||
|
Topic id is 5506142. Add date 2018-01-16 23:48:59, Update date 2018-01-13 22:55:55. Title Повелитель (ТВ-2) / Overlord II (Ито Наоюки) [TV] [1 из 13] [Без хардсаба] [JAP+SUB] [2018,приключения, фэнтези, WEBRip] [720p].
|
||||||
|
*/
|
||||||
|
?>
|
Reference in New Issue
Block a user