mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-01 10:48:53 +00:00
Add release regex support into db and some other minor fixes
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
DROP TABLE IF EXISTS release_naming_regexes;
|
||||
CREATE TABLE release_naming_regexes (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
group_regex VARCHAR(255) NULL COMMENT 'This is a regex to match against usenet groups',
|
||||
regex VARCHAR(5000) NOT NULL COMMENT 'Regex used for extracting name from subject',
|
||||
status TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1=ON 0=OFF',
|
||||
description VARCHAR(1000) NOT NULL COMMENT 'Optional extra details on this regex',
|
||||
ordinal INT SIGNED NOT NULL DEFAULT '0' COMMENT 'Order to run the regex in',
|
||||
PRIMARY KEY (id),
|
||||
INDEX ix_release_naming_regexes_group_regex (group_regex),
|
||||
INDEX ix_release_naming_regexes_status (status),
|
||||
INDEX ix_release_naming_regexes_ordinal (ordinal)
|
||||
)
|
||||
ENGINE = MYISAM
|
||||
DEFAULT CHARSET = utf8
|
||||
COLLATE = utf8_unicode_ci
|
||||
AUTO_INCREMENT = 100000;
|
||||
|
||||
INSERT INTO release_naming_regexes (id, group_regex, regex, status, description, ordinal)
|
||||
VALUES (
|
||||
1,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/\\[\\d+\\]-\\[.+?\\]-\\[.+?\\]-\\[ (.+\\.S\\d\\dE\\d\\d\\..+?) \\][- ]\\[\d+\\/\\d+\\][ -]{0,3}"[\\w\\säöüÄÖÜß+¤¶!.,&_()\\[\\]\\\'\\`{}-]{8,}?\\b.?([-_](proof|sample|thumbs?))*(\\.part\\d*(\\.rar)?|\\.rar|\\.7z)?(\\d{1,3}\\.rev"|\\.vol.+?"|\\.[A-Za-z0-9]{2,4}"|")[-_\\s]{0,3}\d+([.,]\\d+)? [kKmMgG][bB][-_\\s]{0,3}[-_\\s]{0,3}yEnc$/ui',
|
||||
1,
|
||||
'rename these teevee releases as the requestid is for the full season ::: [169018]-[FULL]-[a.b.teevee]-[ House.of.Lies.S01E01.720p.WEB-DL.DD5.1.H.264-BS ]-[04/32] - "House.of.Lies.S01E01.The.Gods.of.Dangerous.Financial.Instruments.720p.WEB-DL.DD5.1.H.264-BS.part03.rar" yEnc',
|
||||
5
|
||||
), (
|
||||
2,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/\\[\\d+\\]-\\[.+?\\]-\\[.+?\\]-\\[ .+\\.S\\d\\d\\..+? \\][- ]\\[\\d+\\/\\d+\\][ -]{0,3}"([\\w\\säöüÄÖÜß+¤¶!.,&_()\[\]\\\'\\`{}#-]{8,}?\\b.?)([-_](proof|sample|thumbs?))*(\\.part\\d*(\\.rar)?|\\.rar|\\.7z)?(\\d{1,3}\\.rev"|\\.vol.+?"|\\.[A-Za-z0-9]{2,4}"|")[-_\\s]{0,3}\d+([.,]\\d+)? [kKmMgG][bB][-_\\s]{0,3}[-_\\s]{0,3}yEnc$/ui',
|
||||
1,
|
||||
'Season only in 4th block so take filename ::: [169019]-[FULL]-[a.b.teevee]-[ House.of.Lies.S02.720p.WEB-DL.DD5.1.H.264-BS ]-[24/32] - "House.of.Lies.S02E02.When.Dinosaurs.Ruled.the.Planet.720p.WEB-DL.DD5.1.H.264-BS.vol000+01.par2" yEnc',
|
||||
10
|
||||
), (
|
||||
3,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/^\\[#+\\]-\\[.+?\\]-\\[.+?\\]-\\[ (?P<match1>.+?) \\][- ]\\[\\d+\\/\\d+\\][-_\\s]{0,3}("|#34;).+?("|#34;) yEnc$/',
|
||||
1,
|
||||
'[######]-[FULL]-[#a.b.teevee@EFNet]-[ Misfits.S01.SUBPACK.DVDRip.XviD-P0W4DVD ] [1/5] - "Misfits.S01.SUBPACK.DVDRip.XviD-P0W4DVD.nfo" yEnc',
|
||||
15
|
||||
), (
|
||||
4,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/^\\[#+\\]-\\[.+?\\]-\\[.+?\\]-\\[(?P<match1>.+?)\\][- ]\\[\\d+\\/\\d+\\][-_\\s]{0,3}".+?" yEnc$/',
|
||||
1,
|
||||
'[34148]-[FULL]-[#a.b.teevee@EFNet]-[Batman.The.Animated.Series.S04E01.DVDRiP.XviD-PyRo]-[00/35] "Batman.The.Animated.Series.S04E01.DVDRiP.XviD-PyRo.nzb" yEnc',
|
||||
20
|
||||
), (
|
||||
5,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/^\\[#+\\]-\\[.+?\\]-\\[ (?P<match1>.+?) \\][- ]\\[\\d+\\/\\d+\\][-_\\s]{0,3}".+?" yEnc$/',
|
||||
1,
|
||||
'[38722]-[#a.b.foreign@EFNet]-[ Game.Of.Thrones.S01E01.Der.Winter.Naht.GERMAN.DL.WS.1080p.HDTV.x264-MiSFiTS ]-[01/37] - "misfits-gameofthrones1080-s01e01-sample-sample.par2" yEnc',
|
||||
25
|
||||
), (
|
||||
6,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/^\\[#+\\]-\\[.+?\\]-\\[.+?\\]-\\[ (?P<match1>.+?) \\][- ]\\[\\d+\\/\\d+\\][-_\\s]{0,3}("|#34;).+?("|#34;) yEnc$/',
|
||||
1,
|
||||
'[#a.b.teevee] Parks.and.Recreation.S01E01.720p.WEB-DL.DD5.1.H.264-CtrlHD - [01/24] - "Parks.and.Recreation.S01E01.720p.WEB-DL.DD5.1.H.264-CtrlHD.nfo" yEnc',
|
||||
30
|
||||
), (
|
||||
7,
|
||||
'alt\\.binaries\\.teevee',
|
||||
'/\\[#+\\]-\\[.+?\\]-\\[.+?\\]-\\[ ?(?P<match1>.+?) ?\\][- ]\\[\\d+\\/\\d+\\][-_\\s]{0,3}("|#34;).+?("|#34;) \\(\\d+\\/\\d+\\) \\(\\d+\\/\\d+$/',
|
||||
1,
|
||||
'[17319]-[FULL]-[#a.b.teevee@EFNet]-[ CSI.New.York.S05E22.720p.HDTV.X264-DIMENSION ]-[01/34] "csi.new.york.522.720p-dimension.nfo" (1/1) (1/1',
|
||||
35
|
||||
);
|
||||
|
||||
UPDATE `tmux` set `value` = '118' where `setting` = 'sqlpatch';
|
||||
+13
-10
@@ -70,19 +70,22 @@ Class Sharing
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param DB $db
|
||||
* @param NNTP $nntp
|
||||
* @param array $options Class instances.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(&$db = null, &$nntp = null)
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
if (!is_null($db)) {
|
||||
$this->db = $db;
|
||||
} else {
|
||||
$this->db = new DB();
|
||||
}
|
||||
$defaults= [
|
||||
'Settings' => null,
|
||||
'NNTP' => null,
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
|
||||
|
||||
// Get all sharing info from DB.
|
||||
$check = $this->db->queryOneRow('SELECT * FROM sharing');
|
||||
$check = $this->pdo->queryOneRow('SELECT * FROM sharing');
|
||||
|
||||
// Initiate sharing settings if this is the first time..
|
||||
if (empty($check)) {
|
||||
@@ -94,7 +97,7 @@ Class Sharing
|
||||
return;
|
||||
}
|
||||
|
||||
$this->nntp = $nntp;
|
||||
$this->nntp = ($options['NNTP'] instanceof \NNTP ? $options['NNTP'] : new \NNTP(['Settings' => $this->pdo]));
|
||||
|
||||
// Cache sharing settings.
|
||||
$this->siteSettings = $check;
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
// This script waits for ajax queries from the web.
|
||||
|
||||
if (!isset($_GET['action'])) {
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/adminpage.php");
|
||||
require_once(WWW_DIR."/lib/binaries.php");
|
||||
require_once(WWW_DIR."/lib/Regexes.php");
|
||||
require_once(WWW_DIR."/lib/groups.php");
|
||||
require_once(WWW_DIR."/lib/releasecomments.php");
|
||||
|
||||
// Make sure the user is an admin and logged in.
|
||||
$admin = new AdminPage;
|
||||
|
||||
$settings = ['Settings' => $admin->settings];
|
||||
switch($_GET['action']) {
|
||||
case 'binary_blacklist_delete':
|
||||
$id = (int) $_GET['row_id'];
|
||||
(new Binaries($settings))->deleteBlacklist($id);
|
||||
print "Blacklist $id deleted.";
|
||||
break;
|
||||
|
||||
case 'collection_regex_delete':
|
||||
$id = (int) $_GET['row_id'];
|
||||
(new Regexes(['Settings' => $admin->settings, 'Table_Name' => 'collection_regexes']))->deleteRegex($id);
|
||||
print "Regex $id deleted.";
|
||||
break;
|
||||
|
||||
case 'release_naming_regex_delete':
|
||||
$id = (int) $_GET['row_id'];
|
||||
(new Regexes(['Settings' => $admin->settings, 'Table_Name' => 'release_naming_regexes']))->deleteRegex($id);
|
||||
print "Regex $id deleted.";
|
||||
break;
|
||||
|
||||
case 'group_edit_purge_all':
|
||||
session_write_close();
|
||||
(new Groups($settings))->purge();
|
||||
print "All groups purged.";
|
||||
break;
|
||||
|
||||
case 'group_edit_reset_all':
|
||||
(new Groups($settings))->resetall();
|
||||
print "All groups reset.";
|
||||
break;
|
||||
|
||||
case 'group_edit_purge_single':
|
||||
$id = (int)$_GET['group_id'];
|
||||
session_write_close();
|
||||
(new Groups($settings))->purge($id);
|
||||
print "Group $id purged.";
|
||||
break;
|
||||
|
||||
case 'group_edit_reset_single':
|
||||
$id = (int)$_GET['group_id'];
|
||||
session_write_close();
|
||||
(new Groups($settings))->reset($id);
|
||||
print "Group $id reset.";
|
||||
break;
|
||||
|
||||
case 'group_edit_delete_single':
|
||||
$id = (int)$_GET['group_id'];
|
||||
session_write_close();
|
||||
(new Groups($settings))->delete($id);
|
||||
print "Group $id deleted.";
|
||||
break;
|
||||
|
||||
case 'toggle_group_active_status':
|
||||
print (new Groups($settings))->updateGroupStatus((int)$_GET['group_id'], (isset($_GET['group_status']) ? (int)$_GET['group_status'] : 0));
|
||||
break;
|
||||
|
||||
case 'toggle_group_backfill_status':
|
||||
print (new Groups($settings))->updateBackfillStatus((int)$_GET['group_id'], (isset($_GET['backfill_status']) ? (int)$_GET['backfill_status'] : 0));
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_status':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing_sites SET enabled = %d WHERE id = %d', $_GET['site_status'], $_GET['site_id']));
|
||||
print ($_GET['site_status'] == 1 ? 'Activated' : 'Deactivated') . ' site ' . $_GET['site_id'];
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_enabled':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing SET enabled = %d', $_GET['enabled_status']));
|
||||
print ($_GET['enabled_status'] == 1 ? 'Enabled' : 'Disabled') . ' sharing!';
|
||||
break;
|
||||
|
||||
case 'sharing_start_position':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing SET start_position = %d', $_GET['start_position']));
|
||||
print ($_GET['start_position'] == 1 ? 'Enabled' : 'Disabled') . ' fetching from start of group!';
|
||||
break;
|
||||
|
||||
case 'sharing_reset_settings':
|
||||
$guid = $admin->settings->queryOneRow('SELECT site_guid FROM sharing');
|
||||
$guid = ($guid === false ? '' : $guid['site_guid']);
|
||||
(new Sharing(['Settings' => $admin->settings]))->initSettings($guid);
|
||||
print 'Re-initiated sharing settings!';
|
||||
break;
|
||||
|
||||
case 'sharing_purge_site':
|
||||
$guid = $admin->settings->queryOneRow(sprintf('SELECT site_guid FROM sharing_sites WHERE id = %d', $_GET['purge_site']));
|
||||
if ($guid === false) {
|
||||
print 'Error purging site ' . $_GET['purge_site'] . '!';
|
||||
} else {
|
||||
$ids = $admin->settings->query(sprintf('SELECT id FROM releasecomments WHERE siteid = %s', $admin->settings->escapeString($guid['site_guid'])));
|
||||
$total = count($ids);
|
||||
if ($total > 0) {
|
||||
$rc = new ReleaseComments($admin->settings);
|
||||
foreach ($ids as $id) {
|
||||
$rc->deleteComment($id['id']);
|
||||
}
|
||||
}
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing_sites SET comments = 0 WHERE id = %d', $_GET['purge_site']));
|
||||
print 'Deleted ' . $total . ' comments for site ' . $_GET['purge_site'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_posting':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing SET posting = %d', $_GET['posting_status']));
|
||||
print ($_GET['posting_status'] == 1 ? 'Enabled' : 'Disabled') . ' posting!';
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_fetching':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing SET fetching = %d', $_GET['fetching_status']));
|
||||
print ($_GET['fetching_status'] == 1 ? 'Enabled' : 'Disabled') . ' fetching!';
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_site_auto_enabling';
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing SET auto_enable = %d', $_GET['auto_status']));
|
||||
print ($_GET['auto_status'] == 1 ? 'Enabled' : 'Disabled') . ' automatic site enabling!';
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_hide_users':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing SET hide_users = %d', $_GET['hide_status']));
|
||||
print ($_GET['hide_status'] == 1? 'Enabled' : 'Disabled') . ' hiding of user names!';
|
||||
break;
|
||||
|
||||
case 'sharing_toggle_all_sites':
|
||||
$admin->settings->queryExec(sprintf('UPDATE sharing_sites SET enabled = %d', $_GET['toggle_all']));
|
||||
break;
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/adminpage.php");
|
||||
require_once(WWW_DIR."/lib/CollectionsCleaning.php");
|
||||
require_once(WWW_DIR."/lib/category.php");
|
||||
require_once './config.php';
|
||||
|
||||
$page = new AdminPage();
|
||||
$cc = new CollectionsCleaning(['Settings' => $page->settings]);
|
||||
$regexes = new Regexes(['Settings' => $page->settings, 'Table_Name' => 'collection_regexes']);
|
||||
|
||||
// Set the current action.
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
|
||||
@@ -32,9 +29,9 @@ switch($action) {
|
||||
}
|
||||
|
||||
if ($_POST["id"] == "") {
|
||||
$cc->addRegex($_POST);
|
||||
$regexes->addRegex($_POST);
|
||||
} else {
|
||||
$cc->updateRegex($_POST);
|
||||
$regexes->updateRegex($_POST);
|
||||
}
|
||||
|
||||
header("Location:".WWW_TOP."/collection_regexes-list.php");
|
||||
@@ -45,7 +42,7 @@ switch($action) {
|
||||
if (isset($_GET["id"])) {
|
||||
$page->title = "Collections Regex Edit";
|
||||
$id = $_GET["id"];
|
||||
$r = $cc->getRegexByID($id);
|
||||
$r = $regexes->getRegexByID($id);
|
||||
} else {
|
||||
$page->title = "Collections Regex Add";
|
||||
$r = ['status' => 1];
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/adminpage.php");
|
||||
require_once(WWW_DIR."/lib/CollectionsCleaning.php");
|
||||
require_once './config.php';
|
||||
|
||||
$page = new AdminPage();
|
||||
$cc = new CollectionsCleaning(['Settings' => $page->settings]);
|
||||
$regexes = new Regexes(['Settings' => $page->settings, 'Table_Name' => 'collection_regexes']);
|
||||
|
||||
$page->title = "Collections Regex List";
|
||||
|
||||
@@ -14,10 +12,10 @@ if (isset($_REQUEST['group']) && !empty($_REQUEST['group'])) {
|
||||
}
|
||||
|
||||
$offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0;
|
||||
$regex = $cc->getRegex($group, ITEMS_PER_PAGE, $offset);
|
||||
$regex = $regexes->getRegex($group, ITEMS_PER_PAGE, $offset);
|
||||
$page->smarty->assign('regex', $regex);
|
||||
|
||||
$count = $cc->getCount($group);
|
||||
$count = $regexes->getCount($group);
|
||||
$page->smarty->assign('pagertotalitems', $count);
|
||||
$page->smarty->assign('pageroffset', $offset);
|
||||
$page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE);
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
<?php
|
||||
require_once("config.php");
|
||||
require_once(WWW_DIR."/lib/adminpage.php");
|
||||
require_once(WWW_DIR."/lib/site.php");
|
||||
require_once(WWW_DIR."/lib/CollectionsCleaning.php");
|
||||
require_once './config.php';
|
||||
|
||||
$page = new AdminPage();
|
||||
$s = new Sites();
|
||||
$site = $s->get();
|
||||
|
||||
$page->title = "Collections Regex Test";
|
||||
|
||||
$tpg = $page->site->tablepergroup;
|
||||
$tpg = $page->settings->getSetting('tablepergroup');
|
||||
$page->smarty->assign('tpg', $tpg);
|
||||
|
||||
if ($tpg) {
|
||||
@@ -21,7 +16,7 @@ if ($tpg) {
|
||||
$page->smarty->assign(['group' => $group, 'regex' => $regex, 'limit' => $limit]);
|
||||
|
||||
if ($group && $regex) {
|
||||
$page->smarty->assign('data', (new CollectionsCleaning(['Settings' => $page->settings]))->testRegex($group, $regex, $limit));
|
||||
$page->smarty->assign('data', (new Regexes(['Settings' => $page->settings, 'Table_Name' => 'collection_regexes']))->testCollectionRegex($group, $regex, $limit));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
require_once './config.php';
|
||||
|
||||
$page = new AdminPage();
|
||||
$regexes = new Regexes(['Settings' => $page->settings, 'Table_Name' => 'release_naming_regexes']);
|
||||
|
||||
// Set the current action.
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
|
||||
|
||||
switch($action) {
|
||||
case 'submit':
|
||||
if ($_POST["group_regex"] == "") {
|
||||
$page->smarty->assign('error', "Group regex must not be empty!");
|
||||
break;
|
||||
}
|
||||
|
||||
if ($_POST["regex"] == "") {
|
||||
$page->smarty->assign('error', "Regex cannot be empty");
|
||||
break;
|
||||
}
|
||||
|
||||
if ($_POST['description'] == '') {
|
||||
$_POST['description'] = '';
|
||||
}
|
||||
|
||||
if (!is_numeric($_POST['ordinal']) || $_POST['ordinal'] < 0) {
|
||||
$page->smarty->assign('error', "Ordinal must be a number, 0 or higher.");
|
||||
break;
|
||||
}
|
||||
|
||||
if ($_POST["id"] == "") {
|
||||
$regexes->addRegex($_POST);
|
||||
} else {
|
||||
$regexes->updateRegex($_POST);
|
||||
}
|
||||
|
||||
header("Location:".WWW_TOP."/release_naming_regexes-list.php");
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
default:
|
||||
if (isset($_GET["id"])) {
|
||||
$page->title = "Release Naming Regex Edit";
|
||||
$id = $_GET["id"];
|
||||
$r = $regexes->getRegexByID($id);
|
||||
} else {
|
||||
$page->title = "Release Naming Regex Add";
|
||||
$r = ['status' => 1];
|
||||
}
|
||||
$page->smarty->assign('regex', $r);
|
||||
break;
|
||||
}
|
||||
|
||||
$page->smarty->assign('status_ids', array(Category::STATUS_ACTIVE,Category::STATUS_INACTIVE));
|
||||
$page->smarty->assign('status_names', array( 'Yes', 'No'));
|
||||
|
||||
$page->content = $page->smarty->fetch('release_naming_regexes-edit.tpl');
|
||||
$page->render();
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
require_once './config.php';
|
||||
|
||||
$page = new AdminPage();
|
||||
$regexes = new Regexes(['Settings' => $page->settings, 'Table_Name' => 'release_naming_regexes']);
|
||||
|
||||
$page->title = "Release Naming Regex List";
|
||||
|
||||
$group = '';
|
||||
if (isset($_REQUEST['group']) && !empty($_REQUEST['group'])) {
|
||||
$group = $_REQUEST['group'];
|
||||
}
|
||||
|
||||
$offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0;
|
||||
$regex = $regexes->getRegex($group, ITEMS_PER_PAGE, $offset);
|
||||
$page->smarty->assign('regex', $regex);
|
||||
|
||||
$count = $regexes->getCount($group);
|
||||
$page->smarty->assign('pagertotalitems', $count);
|
||||
$page->smarty->assign('pageroffset', $offset);
|
||||
$page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE);
|
||||
|
||||
$page->smarty->assign('pagerquerybase', WWW_TOP . "/release_naming_regexes-list.php?" . $group . "offset=");
|
||||
$page->smarty->assign('pager', $page->smarty->fetch("pager.tpl"));
|
||||
|
||||
$page->content = $page->smarty->fetch('release_naming_regexes-list.tpl');
|
||||
$page->render();
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once './config.php';
|
||||
|
||||
$page = new AdminPage();
|
||||
|
||||
$page->title = "Release Naming Regex Test";
|
||||
|
||||
$group = trim(isset($_POST['group']) && !empty($_POST['group']) ? $_POST['group'] : '');
|
||||
$regex = trim(isset($_POST['regex']) && !empty($_POST['regex']) ? $_POST['regex'] : '');
|
||||
$showLimit = (isset($_POST['showlimit']) && is_numeric($_POST['showlimit']) ? $_POST['showlimit'] : 250);
|
||||
$queryLimit = (isset($_POST['querylimit']) && is_numeric($_POST['querylimit']) ? $_POST['querylimit'] : 100000);
|
||||
$page->smarty->assign(['group' => $group, 'regex' => $regex, 'showlimit' => $showLimit, 'querylimit' => $queryLimit]);
|
||||
|
||||
if ($group && $regex) {
|
||||
$page->smarty->assign('data', (new Regexes(['Settings' => $page->settings, 'Table_Name' => 'release_naming_regexes']))->testReleaseNamingRegex($group, $regex, $showLimit, $queryLimit));
|
||||
}
|
||||
|
||||
|
||||
$page->content = $page->smarty->fetch('release_naming_regexes-test.tpl');
|
||||
$page->render();
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require_once(WWW_DIR . "/lib/Regexes.php");
|
||||
|
||||
/**
|
||||
* Cleans names for collections/imports/namefixer.
|
||||
@@ -60,9 +61,9 @@ class CollectionsCleaning
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @var array Cache of regex and their TTL.
|
||||
* @var Regexes
|
||||
*/
|
||||
protected $_regexCache;
|
||||
protected $_regexes;
|
||||
|
||||
/**
|
||||
* @param array $options Class instances.
|
||||
@@ -80,183 +81,7 @@ class CollectionsCleaning
|
||||
$options += $defaults;
|
||||
|
||||
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new regex.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function addRegex(array $data)
|
||||
{
|
||||
return (bool)$this->pdo->queryInsert(
|
||||
sprintf(
|
||||
'INSERT INTO collection_regexes (group_regex, regex, status, description, ordinal) VALUES (%s, %s, %d, %s, %d)',
|
||||
trim($this->pdo->escapeString($data['group_regex'])),
|
||||
trim($this->pdo->escapeString($data['regex'])),
|
||||
$data['status'],
|
||||
trim($this->pdo->escapeString($data['description'])),
|
||||
$data['ordinal']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a regex with new info.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateRegex(array $data)
|
||||
{
|
||||
return (bool)$this->pdo->queryExec(
|
||||
sprintf(
|
||||
'UPDATE collection_regexes
|
||||
SET group_regex = %s, regex = %s, status = %d, description = %s, ordinal = %d
|
||||
WHERE id = %d',
|
||||
trim($this->pdo->escapeString($data['group_regex'])),
|
||||
trim($this->pdo->escapeString($data['regex'])),
|
||||
$data['status'],
|
||||
trim($this->pdo->escapeString($data['description'])),
|
||||
$data['ordinal'],
|
||||
$data['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single regex using its id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegexByID($id)
|
||||
{
|
||||
return $this->pdo->queryOneRow(sprintf('SELECT * FROM collection_regexes WHERE id = %d', $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all regex.
|
||||
*
|
||||
* @param string $group_regex Optional, a keyword to find a group.
|
||||
* @param int $limit Optional, amount of results to limit.
|
||||
* @param int $offset Optional, the offset to use when limiting the result set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegex($group_regex = '', $limit = 0, $offset = 0)
|
||||
{
|
||||
return $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT * FROM collection_regexes %s %s',
|
||||
($group_regex ? ('WHERE group_regex ' . $this->pdo->likeString($group_regex)) : ''),
|
||||
($limit ? ('LIMIT ' . $limit . ' OFFSET ' . $offset) : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of regex in the DB.
|
||||
*
|
||||
* @param string $group_regex Optional, keyword to find a group.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount($group_regex = '')
|
||||
{
|
||||
$query = $this->pdo->queryOneRow(
|
||||
sprintf(
|
||||
'SELECT COUNT(id) AS count FROM collection_regexes %s',
|
||||
($group_regex ? ('WHERE group_regex ' . $this->pdo->likeString($group_regex)) : '')
|
||||
)
|
||||
);
|
||||
return (int)$query['count'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a regex using its id.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function deleteRegex($id)
|
||||
{
|
||||
$this->pdo->queryExec('DELETE FROM collection_regexes WHERE id = ' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a regex for a group name.
|
||||
*
|
||||
* Requires table per group to be on.
|
||||
*
|
||||
* @param string $groupName
|
||||
* @param string $regex
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function testRegex($groupName, $regex, $limit)
|
||||
{
|
||||
$groups = new Groups(['Settings' => $this->pdo]);
|
||||
$groupID = $groups->getIDByName($groupName);
|
||||
|
||||
if (!$groupID) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$tableNames = $groups->getCBPTableNames(true, $groupID);
|
||||
|
||||
$rows = $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT
|
||||
b.name, b.totalparts, b.currentparts, b.binaryhash,
|
||||
c.fromname, c.collectionhash
|
||||
FROM %s b
|
||||
INNER JOIN %s c ON c.id = b.collection_id',
|
||||
$tableNames['bname'], $tableNames['cname']
|
||||
)
|
||||
);
|
||||
|
||||
$data = [];
|
||||
if ($rows) {
|
||||
$limit--;
|
||||
$hashes = [];
|
||||
foreach ($rows as $row) {
|
||||
if (preg_match($regex, $row['name'], $matches)) {
|
||||
ksort($matches);
|
||||
$string = $string2 = '';
|
||||
foreach ($matches as $key => $match) {
|
||||
if (!is_int($key)) {
|
||||
$string .= $match;
|
||||
$string2 .= '<br/>' . $key . ': ' . $match;
|
||||
}
|
||||
}
|
||||
$files = 0;
|
||||
if (preg_match('/[[(\s](\d{1,5})(\/|[\s_]of[\s_]|-)(\d{1,5})[])\s$:]/i', $row['name'], $fileCount)) {
|
||||
$files = $fileCount[3];
|
||||
}
|
||||
$newCollectionHash = sha1($string . $row['fromname'] . $groupID . $files);
|
||||
$data['New hash: ' . $newCollectionHash . $string2][$row['binaryhash']] = [
|
||||
'file_name' => $row['name'],
|
||||
'file_total_parts' => $row['totalparts'],
|
||||
'file_current_parts' => $row['currentparts'],
|
||||
'collection_poster' => $row['fromname'],
|
||||
'old_collection_hash' => $row['collectionhash'],
|
||||
];
|
||||
|
||||
if ($limit > 0) {
|
||||
if (count($hashes) > $limit) {
|
||||
break;
|
||||
}
|
||||
$hashes[$newCollectionHash] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
$this->_regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'collection_regexes']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,7 +98,7 @@ class CollectionsCleaning
|
||||
$this->groupName = $groupName;
|
||||
|
||||
// Try DB regex first.
|
||||
$potentialString = $this->_processDBRegex();
|
||||
$potentialString = $this->_regexes->tryRegex($subject, $groupName);
|
||||
if ($potentialString) {
|
||||
return $potentialString;
|
||||
}
|
||||
@@ -472,81 +297,6 @@ class CollectionsCleaning
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the regex from the DB, cache them locally for 15 mins.
|
||||
* Cache them also in the cache server, as this script might be terminated.
|
||||
*/
|
||||
protected function _fetchRegex()
|
||||
{
|
||||
// Check if we need to do an initial cache or refresh our cache.
|
||||
if (isset($this->_regexCache[$this->groupName]['ttl']) && (time() - $this->_regexCache[$this->groupName]['ttl']) < 900) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all regex from DB which match the current group name. Cache them for 15 minutes. #CACHEDQUERY#
|
||||
$this->_regexCache[$this->groupName]['regex'] = $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT c.regex FROM collection_regexes c WHERE %s REGEXP c.group_regex AND c.status = 1 ORDER BY c.ordinal ASC, c.group_regex ASC',
|
||||
$this->pdo->escapeString($this->groupName)
|
||||
), true, 900
|
||||
);
|
||||
// Set the TTL.
|
||||
$this->_regexCache[$this->groupName]['ttl'] = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* This will process the regex stored in the DB before trying hardcoded regex below.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _processDBRegex()
|
||||
{
|
||||
$this->_fetchRegex();
|
||||
|
||||
$returnString = '';
|
||||
// If there are no regex, return and try regex in this file.
|
||||
if ($this->_regexCache[$this->groupName]['regex']) {
|
||||
foreach ($this->_regexCache[$this->groupName]['regex'] as $regex) {
|
||||
|
||||
$returnString = $this->_matchDBRegex($regex['regex']);
|
||||
// If this regex found something, break and return, or else continue trying other regex.
|
||||
if ($returnString) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $returnString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matches on a regex taken from the database.
|
||||
*
|
||||
* Requires at least 1 named captured group.
|
||||
*
|
||||
* @param string $regex
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _matchDBRegex($regex)
|
||||
{
|
||||
$returnString = '';
|
||||
if (preg_match($regex, $this->subject, $matches)) {
|
||||
if (count($matches) > 0) {
|
||||
// Sort the keys, the named key matches will be concatenated in this order.
|
||||
ksort($matches);
|
||||
foreach ($matches as $key => $value) {
|
||||
// Ignore non-named capture groups. Only named capture groups are important.
|
||||
if (is_int($key)) {
|
||||
continue;
|
||||
}
|
||||
// Concatenate the string to return.
|
||||
$returnString .= $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $returnString;
|
||||
}
|
||||
|
||||
// a.b.0daystuffz
|
||||
protected function _0daystuffz()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
require_once(WWW_DIR . "/lib/groups.php");
|
||||
require_once(WWW_DIR . "/lib/framework/db.php");
|
||||
|
||||
Class Regexes
|
||||
{
|
||||
/**
|
||||
* @var \DB
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @var string Name of the current table we are working on.
|
||||
*/
|
||||
public $tableName;
|
||||
|
||||
/**
|
||||
* @var array Cache of regex and their TTL.
|
||||
*/
|
||||
protected $_regexCache;
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
$defaults = [
|
||||
'Settings' => null,
|
||||
'Table_Name' => '',
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
|
||||
$this->tableName = $options['Table_Name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new regex.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function addRegex(array $data)
|
||||
{
|
||||
return (bool)$this->pdo->queryInsert(
|
||||
sprintf(
|
||||
'INSERT INTO %s (group_regex, regex, status, description, ordinal) VALUES (%s, %s, %d, %s, %d)',
|
||||
$this->tableName,
|
||||
trim($this->pdo->escapeString($data['group_regex'])),
|
||||
trim($this->pdo->escapeString($data['regex'])),
|
||||
$data['status'],
|
||||
trim($this->pdo->escapeString($data['description'])),
|
||||
$data['ordinal']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a regex with new info.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateRegex(array $data)
|
||||
{
|
||||
return (bool)$this->pdo->queryExec(
|
||||
sprintf(
|
||||
'UPDATE %s
|
||||
SET group_regex = %s, regex = %s, status = %d, description = %s, ordinal = %d
|
||||
WHERE id = %d',
|
||||
$this->tableName,
|
||||
trim($this->pdo->escapeString($data['group_regex'])),
|
||||
trim($this->pdo->escapeString($data['regex'])),
|
||||
$data['status'],
|
||||
trim($this->pdo->escapeString($data['description'])),
|
||||
$data['ordinal'],
|
||||
$data['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single regex using its id.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegexByID($id)
|
||||
{
|
||||
return $this->pdo->queryOneRow(sprintf('SELECT * FROM %s WHERE id = %d', $this->tableName, $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all regex.
|
||||
*
|
||||
* @param string $group_regex Optional, a keyword to find a group.
|
||||
* @param int $limit Optional, amount of results to limit.
|
||||
* @param int $offset Optional, the offset to use when limiting the result set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRegex($group_regex = '', $limit = 0, $offset = 0)
|
||||
{
|
||||
return $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT * FROM %s %s %s',
|
||||
$this->tableName,
|
||||
$this->_groupQueryString($group_regex),
|
||||
($limit ? ('LIMIT ' . $limit . ' OFFSET ' . $offset) : '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of regex in the DB.
|
||||
*
|
||||
* @param string $group_regex Optional, keyword to find a group.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount($group_regex = '')
|
||||
{
|
||||
$query = $this->pdo->queryOneRow(
|
||||
sprintf(
|
||||
'SELECT COUNT(id) AS count FROM %s %s',
|
||||
$this->tableName,
|
||||
$this->_groupQueryString($group_regex)
|
||||
)
|
||||
);
|
||||
return (int)$query['count'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a regex using its id.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function deleteRegex($id)
|
||||
{
|
||||
$this->pdo->queryExec(sprintf('DELETE FROM %s WHERE id = %d', $this->tableName, $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a single collection regex for a group name.
|
||||
*
|
||||
* Requires table per group to be on.
|
||||
*
|
||||
* @param string $groupName
|
||||
* @param string $regex
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function testCollectionRegex($groupName, $regex, $limit)
|
||||
{
|
||||
$groups = new Groups(['Settings' => $this->pdo]);
|
||||
$groupID = $groups->getIDByName($groupName);
|
||||
|
||||
if (!$groupID) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$tableNames = $groups->getCBPTableNames(true, $groupID);
|
||||
|
||||
$rows = $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT
|
||||
b.name, b.totalparts, b.currentparts, b.binaryhash,
|
||||
c.fromname, c.collectionhash
|
||||
FROM %s b
|
||||
INNER JOIN %s c ON c.id = b.collection_id',
|
||||
$tableNames['bname'], $tableNames['cname']
|
||||
)
|
||||
);
|
||||
|
||||
$data = [];
|
||||
if ($rows) {
|
||||
$limit--;
|
||||
$hashes = [];
|
||||
foreach ($rows as $row) {
|
||||
if (preg_match($regex, $row['name'], $matches)) {
|
||||
ksort($matches);
|
||||
$string = $string2 = '';
|
||||
foreach ($matches as $key => $match) {
|
||||
if (!is_int($key)) {
|
||||
$string .= $match;
|
||||
$string2 .= '<br/>' . $key . ': ' . $match;
|
||||
}
|
||||
}
|
||||
$files = 0;
|
||||
if (preg_match('/[[(\s](\d{1,5})(\/|[\s_]of[\s_]|-)(\d{1,5})[])\s$:]/i', $row['name'], $fileCount)) {
|
||||
$files = $fileCount[3];
|
||||
}
|
||||
$newCollectionHash = sha1($string . $row['fromname'] . $groupID . $files);
|
||||
$data['New hash: ' . $newCollectionHash . $string2][$row['binaryhash']] = [
|
||||
'file_name' => $row['name'],
|
||||
'file_total_parts' => $row['totalparts'],
|
||||
'file_current_parts' => $row['currentparts'],
|
||||
'collection_poster' => $row['fromname'],
|
||||
'old_collection_hash' => $row['collectionhash'],
|
||||
];
|
||||
|
||||
if ($limit > 0) {
|
||||
if (count($hashes) > $limit) {
|
||||
break;
|
||||
}
|
||||
$hashes[$newCollectionHash] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a single release naming regex for a group name.
|
||||
*
|
||||
* @param string $groupName
|
||||
* @param string $regex
|
||||
* @param int $displayLimit
|
||||
* @param int $queryLimit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function testReleaseNamingRegex($groupName, $regex, $displayLimit, $queryLimit)
|
||||
{
|
||||
$groups = new Groups(['Settings' => $this->pdo]);
|
||||
$groupID = $groups->getIDByName($groupName);
|
||||
|
||||
if (!$groupID) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT name, searchname, id FROM releases WHERE groupid = %d LIMIT %d',
|
||||
$groupID,
|
||||
$queryLimit
|
||||
)
|
||||
);
|
||||
|
||||
$data = [];
|
||||
if ($rows) {
|
||||
$limit = 1;
|
||||
foreach ($rows as $row) {
|
||||
$match = $this->_matchRegex($regex, $row['name']);
|
||||
if ($match) {
|
||||
$data[$row['id']] = [
|
||||
'subject' => $row['name'],
|
||||
'old_name' => $row['searchname'],
|
||||
'new_name' => $match
|
||||
];
|
||||
if ($limit++ > $displayLimit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will try to find regex in the DB for a group and a usenet subject, attempt to match them and return the matches.
|
||||
*
|
||||
* @param string $subject
|
||||
* @param string $groupName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function tryRegex($subject, $groupName)
|
||||
{
|
||||
$this->_fetchRegex($groupName);
|
||||
|
||||
$returnString = '';
|
||||
// If there are no regex, return and try regex in this file.
|
||||
if ($this->_regexCache[$groupName]['regex']) {
|
||||
foreach ($this->_regexCache[$groupName]['regex'] as $regex) {
|
||||
|
||||
$returnString = $this->_matchRegex($regex['regex'], $subject);
|
||||
// If this regex found something, break and return, or else continue trying other regex.
|
||||
if ($returnString) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $returnString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the regex from the DB, cache them locally for 15 mins.
|
||||
* Cache them also in the cache server, as this script might be terminated.
|
||||
*
|
||||
* @param string $groupName
|
||||
*/
|
||||
protected function _fetchRegex($groupName)
|
||||
{
|
||||
// Check if we need to do an initial cache or refresh our cache.
|
||||
if (isset($this->_regexCache[$groupName]['ttl']) && (time() - $this->_regexCache[$groupName]['ttl']) < 900) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all regex from DB which match the current group name. Cache them for 15 minutes. #CACHEDQUERY#
|
||||
$this->_regexCache[$groupName]['regex'] = $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT c.regex FROM %s c WHERE %s REGEXP c.group_regex AND c.status = 1 ORDER BY c.ordinal ASC, c.group_regex ASC',
|
||||
$this->tableName,
|
||||
$this->pdo->escapeString($groupName)
|
||||
), true, 900
|
||||
);
|
||||
// Set the TTL.
|
||||
$this->_regexCache[$groupName]['ttl'] = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matches on a regex taken from the database.
|
||||
*
|
||||
* Requires at least 1 named captured group.
|
||||
*
|
||||
* @param string $regex
|
||||
* @param string $subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _matchRegex($regex, $subject)
|
||||
{
|
||||
$returnString = '';
|
||||
if (preg_match($regex, $subject, $matches)) {
|
||||
if (count($matches) > 0) {
|
||||
// Sort the keys, the named key matches will be concatenated in this order.
|
||||
ksort($matches);
|
||||
foreach ($matches as $key => $value) {
|
||||
// Ignore non-named capture groups. Only named capture groups are important.
|
||||
if (is_int($key)) {
|
||||
continue;
|
||||
}
|
||||
// Concatenate the string to return.
|
||||
$returnString .= $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $returnString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format part of a query.
|
||||
*
|
||||
* @param string $group_regex
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _groupQueryString($group_regex)
|
||||
{
|
||||
return ($group_regex ? ('WHERE group_regex ' . $this->pdo->likeString($group_regex)) : '');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
require_once(WWW_DIR . "lib/framework/db.php");
|
||||
require_once(WWW_DIR . "lib/groups.php");
|
||||
require_once(WWW_DIR . "lib/CollectionsCleaning.php");
|
||||
require_once(WWW_DIR . "lib/Regexes.php");
|
||||
require_once(NN_TMUX . 'lib' . DS . 'prehash.php');
|
||||
/*
|
||||
* Cleans names for releases/imports/namefixer.
|
||||
@@ -72,6 +73,11 @@ class ReleaseCleaning
|
||||
*/
|
||||
public $subject = '';
|
||||
|
||||
/**
|
||||
* @var Regexes
|
||||
*/
|
||||
protected $_regexes;
|
||||
|
||||
/**
|
||||
* @param DB $settings
|
||||
*/
|
||||
@@ -83,6 +89,7 @@ class ReleaseCleaning
|
||||
$this->e2 = \CollectionsCleaning::REGEX_FILE_EXTENSIONS .
|
||||
\CollectionsCleaning::REGEX_SUBJECT_SIZE . \CollectionsCleaning::REGEX_END;
|
||||
$this->pdo = ($settings instanceof DB ? $settings : new DB());
|
||||
$this->_regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'release_naming_regexes']);
|
||||
}
|
||||
|
||||
public function releaseCleaner($subject, $fromName, $size, $groupName, $usepre = false)
|
||||
@@ -178,10 +185,18 @@ class ReleaseCleaning
|
||||
if ($usepre === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try DB regex.
|
||||
$potentialName = $this->_regexes->tryRegex($subject, $groupName);
|
||||
if ($potentialName) {
|
||||
return $potentialName;
|
||||
}
|
||||
|
||||
//if www.town.ag releases check against generic_town regexes
|
||||
if (preg_match('/www\.town\.ag/i', $this->subject)) {
|
||||
return $this->generic_town();
|
||||
}
|
||||
|
||||
switch ($groupName) {
|
||||
case 'alt.binaries.0day.stuffz':
|
||||
return $this->_0daystuffz();
|
||||
@@ -6834,56 +6849,6 @@ class ReleaseCleaning
|
||||
|
||||
public function teevee()
|
||||
{
|
||||
// rename these teevee releases as the requestid is for the full season
|
||||
// Episode info in 4th block so use that
|
||||
//[169018]-[FULL]-[a.b.teevee]-[ House.of.Lies.S01E01.720p.WEB-DL.DD5.1.H.264-BS ]-[04/32] - "House.of.Lies.S01E01.The.Gods.of.Dangerous.Financial.Instruments.720p.WEB-DL.DD5.1.H.264-BS.part03.rar" yEnc
|
||||
if (preg_match('/\[\d+\]-\[.+?\]-\[.+?\]-\[ (.+\.S\d\dE\d\d\..+?) \][- ]\[\d+\/\d+\][ -]{0,3}"[\w\säöüÄÖÜß+¤¶!.,&_()\[\]\'\`{}-]{8,}?\b.?' . $this->e1,
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
}
|
||||
// Season only in 4th block so take filename
|
||||
//[169019]-[FULL]-[a.b.teevee]-[ House.of.Lies.S02.720p.WEB-DL.DD5.1.H.264-BS ]-[24/32] - "House.of.Lies.S02E02.When.Dinosaurs.Ruled.the.Planet.720p.WEB-DL.DD5.1.H.264-BS.vol000+01.par2" yEnc
|
||||
if (preg_match('/\[\d+\]-\[.+?\]-\[.+?\]-\[ .+\.S\d\d\..+? \][- ]\[\d+\/\d+\][ -]{0,3}"([\w\säöüÄÖÜß+¤¶!.,&_()\[\]\'\`{}#-]{8,}?\b.?)' . $this->e1,
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
}
|
||||
// END teevee requestid renaming
|
||||
|
||||
//[######]-[FULL]-[#a.b.teevee@EFNet]-[ Misfits.S01.SUBPACK.DVDRip.XviD-P0W4DVD ] [1/5] - "Misfits.S01.SUBPACK.DVDRip.XviD-P0W4DVD.nfo" yEnc
|
||||
if (preg_match('/^\[#+\]-\[.+?\]-\[.+?\]-\[ (.+?) \][- ]\[\d+\/\d+\][-_\s]{0,3}("|#34;).+?("|#34;) yEnc$/',
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
} //[34148]-[FULL]-[#a.b.teevee@EFNet]-[Batman.The.Animated.Series.S04E01.DVDRiP.XviD-PyRo]-[00/35] "Batman.The.Animated.Series.S04E01.DVDRiP.XviD-PyRo.nzb" yEnc
|
||||
if (preg_match('/^\[#+\]-\[.+?\]-\[.+?\]-\[(.+?)\][- ]\[\d+\/\d+\][-_\s]{0,3}".+?" yEnc$/',
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
} //[38722]-[#a.b.foreign@EFNet]-[ Game.Of.Thrones.S01E01.Der.Winter.Naht.GERMAN.DL.WS.1080p.HDTV.x264-MiSFiTS ]-[01/37] - "misfits-gameofthrones1080-s01e01-sample-sample.par2" yEnc
|
||||
if (preg_match('/^\[#+\]-\[.+?\]-\[ (.+?) \][- ]\[\d+\/\d+\][-_\s]{0,3}".+?" yEnc$/',
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
} //[#a.b.teevee] Parks.and.Recreation.S01E01.720p.WEB-DL.DD5.1.H.264-CtrlHD - [01/24] - "Parks.and.Recreation.S01E01.720p.WEB-DL.DD5.1.H.264-CtrlHD.nfo" yEnc
|
||||
if (preg_match('/^\[#+\]-\[.+?\]-\[.+?\]-\[ (.+?) \][- ]\[\d+\/\d+\][-_\s]{0,3}("|#34;).+?("|#34;) yEnc$/',
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
} //[17319]-[FULL]-[#a.b.teevee@EFNet]-[ CSI.New.York.S05E22.720p.HDTV.X264-DIMENSION ]-[01/34] "csi.new.york.522.720p-dimension.nfo" (1/1) (1/1
|
||||
if (preg_match('/\[#+\]-\[.+?\]-\[.+?\]-\[ ?(.+?) ?\][- ]\[\d+\/\d+\][-_\s]{0,3}("|#34;).+?("|#34;) \(\d+\/\d+\) \(\d+\/\d+$/',
|
||||
$this->subject,
|
||||
$match)
|
||||
) {
|
||||
return $match[1];
|
||||
}
|
||||
//(01/37) "Entourage S08E08.part01.rar" - 349,20 MB - yEnc
|
||||
//(01/24) "EGtnu7OrLNQMO2pDbgpDrBL8SnjZDpab.nfo" - 686 B - 338.74 MB - yEnc (1/1)
|
||||
if (preg_match('/^\(\d+\/\d+\) "([\w\säöüÄÖÜß+¤¶!.,&_()\[\]\'\`{}#-]{8,}?\b.?)' . $this->e0 .
|
||||
|
||||
@@ -117,7 +117,7 @@ class TmuxOutput extends Tmux
|
||||
$buffer = '';
|
||||
$state = ($this->runVar['settings']['is_running'] == 1) ? 'Running' : 'Disabled';
|
||||
//$version = $this->_tvers . 'r' . $this->_vers;
|
||||
$tversion = '0.6r0053';
|
||||
$tversion = '0.6r0060';
|
||||
|
||||
$buffer .= sprintf($this->tmpMasks[2],
|
||||
"Monitor $state v$tversion @ $this->_tvers [" . $this->_vers ."]: ",
|
||||
|
||||
@@ -655,6 +655,31 @@ function ajax_collection_regex_delete(id)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ajax_release_naming_regex_delete()
|
||||
*
|
||||
* @param id binary id
|
||||
*/
|
||||
function ajax_release_naming_regex_delete(id)
|
||||
{
|
||||
// no caching of results
|
||||
var rand_no = Math.random();
|
||||
$.ajax({
|
||||
url : WWW_TOP + '/admin/ajax.php?action=release_naming_regex_delete&rand=' + rand_no,
|
||||
data : { row_id: id},
|
||||
dataType : "html",
|
||||
success : function(data)
|
||||
{
|
||||
$('div#message').html(data);
|
||||
$('div#message').show('fast', function() {});
|
||||
$('#row-'+id).fadeOut(2000);
|
||||
$('#message').fadeOut(5000);
|
||||
},
|
||||
error: function(xhr,err,e) { alert( "Error in ajax_release_naming_regex_delete: " + err ); }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
$('#regexGroupSelect').change(function() {
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
<li class="last"><a href="{$smarty.const.WWW_TOP}/collection_regexes-list.php">View</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-sub"><a href="#">Release Names</a>
|
||||
<ul>
|
||||
<li><a href="{$smarty.const.WWW_TOP}/release_name_regexes-edit.php?action=add">Add</a></li>
|
||||
<li><a href="{$smarty.const.WWW_TOP}/release_name_regexes-test.php?action=add">Test</a></li>
|
||||
<li class="last"><a href="{$smarty.const.WWW_TOP}/release_name_regexes-list.php">View</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="{$smarty.const.WWW_TOP}/binaryblacklist-list.php">View</a> <a style="padding:0;" href="{$smarty.const.WWW_TOP}/binaryblacklist-edit.php?action=add">Add</a> Blacklist</li>
|
||||
<li><a href="{$smarty.const.WWW_TOP}/release-list.php">View Releases</a></li>
|
||||
<li><a href="{$smarty.const.WWW_TOP}/preview-list.php">View Previews</a></li>
|
||||
|
||||
@@ -26,13 +26,12 @@
|
||||
The regex delimiters are not added, you MUST add them. See <a href="http://php.net/manual/en/regexp.reference.delimiters.php">this</a> page.<br />
|
||||
To make the regex case insensitive, add i after the last delimiter.<br />
|
||||
You MUST include at least one regex capture group.<br />
|
||||
You MUST name your regex capture groups.<br />
|
||||
You MUST name your regex capture groups (the ones you want to be included).<br />
|
||||
A string will be created from your matched capture groups.<br />
|
||||
The string will form part of a "collection hash".<br />
|
||||
The collection hash is used to group many parts together, to form the finalized release.<br />
|
||||
The usenet group and name of the poster are added automatically when hashing.<br />
|
||||
Capture groups are sorted alphabetically (by capture group name) when concatenating the string.<br />
|
||||
The regex search will be done case insensitive.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<h1>{$page->title}</h1>
|
||||
{if $error != ''}
|
||||
<div class="error">{$error}</div>
|
||||
{/if}
|
||||
<form action="{$SCRIPT_NAME}?action=submit" method="POST">
|
||||
<table class="input">
|
||||
<tr>
|
||||
<td><label for="group_regex">Group:</label></td>
|
||||
<td>
|
||||
<input type="hidden" name="id" value="{$regex.id}" />
|
||||
<input type="text" id="group_regex" name="group_regex" value="{$regex.group_regex|escape:html}" />
|
||||
<div class="hint">
|
||||
Regex to match against a group or multiple groups.<br />
|
||||
Delimiters are already added, and PCRE_CASELESS is added after for case insensitivity.
|
||||
An example of matching a single group: alt\.binaries\.example<br />
|
||||
An example of matching multiple groups: alt\.binaries.*
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="regex">Regex:</label></td>
|
||||
<td>
|
||||
<textarea id="regex" name="regex" >{$regex.regex|escape:html}</textarea>
|
||||
<div class="hint">
|
||||
The regex to use when trying to name a release using the usenet subject.<br />
|
||||
The regex delimiters are not added, you MUST add them. See <a href="http://php.net/manual/en/regexp.reference.delimiters.php">this</a> page.<br />
|
||||
To make the regex case insensitive, add i after the last delimiter.<br />
|
||||
You MUST include at least one regex capture group.<br />
|
||||
You MUST name your regex capture groups (the ones you want included).<br />
|
||||
The named capture groups will be concatenated into a string.
|
||||
Capture groups are sorted alphabetically (by capture group name) when concatenating the string.<br />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="description">Description:</label></td>
|
||||
<td>
|
||||
<textarea id="description" name="description" >{$regex.description|escape:html}</textarea>
|
||||
<div class="hint">
|
||||
Description for this regex.<br />
|
||||
You can include an example usenet subject this regex would match on.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="ordinal">Ordinal:</label></td>
|
||||
<td>
|
||||
<input class="ordinal" id="ordinal" name="ordinal" type="text" value="{$regex.ordinal}" />
|
||||
<div class="hint">
|
||||
The order to run this regex in.<br />
|
||||
Must be a number, 0 or higher.<br />
|
||||
If multiple regex have the same ordinal, MySQL will randomly sort them.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="status">Active:</label></td>
|
||||
<td>
|
||||
{html_radios id="status" name='status' values=$status_ids output=$status_names selected=$regex.status separator='<br />'}
|
||||
<div class="hint">Only active regex are used during the collection matching process.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<input type="submit" value="Save" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
@@ -0,0 +1,43 @@
|
||||
<h1>{$page->title}</h1>
|
||||
<p>This page lists regex used for getting names for releases from usenet subjects.</p>
|
||||
<div id="message"></div>
|
||||
|
||||
<form name="groupsearch" action="" style="margin-bottom:5px;">
|
||||
<label for="group">Search a group:</label>
|
||||
<input id="group" type="text" name="group" value="{$group}" size="15" />
|
||||
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
{if $regex}
|
||||
|
||||
<div>{$pager}</div>
|
||||
<table style="margin-top:10px;" class="data Sortable highlight">
|
||||
<tr>
|
||||
<th style="width:20px;">id</th>
|
||||
<th>group</th>
|
||||
<th style="width:25px;">edit</th>
|
||||
<th>description</th>
|
||||
<th style="width:40px;">delete</th>
|
||||
<th>ordinal</th>
|
||||
<th>status</th>
|
||||
<th>regex</th>
|
||||
</tr>
|
||||
{foreach from=$regex item=row}
|
||||
<tr id="row-{$row.id}" class="{cycle values=",alt"}">
|
||||
<td>{$row.id}</td>
|
||||
<td>{$row.group_regex}</td>
|
||||
<td title="Edit this regex"><a href="{$smarty.const.WWW_TOP}/release_naming_regexes-edit.php?id={$row.id}">Edit</a></td>
|
||||
<td>{$row.description|truncate:50:"...":true}</td>
|
||||
<td title="Delete this regex"><a href="javascript:ajax_release_naming_regex_delete({$row.id})" onclick="return confirm('Are you sure? This will delete the regex from this list.');" >Delete</a></td>
|
||||
<td>{$row.ordinal}</td>
|
||||
{if $row.status==1}
|
||||
<td style="color:#00CC66">Active</td>
|
||||
{else}
|
||||
<td style="color:#FF0000">Disabled</td>
|
||||
{/if}
|
||||
<td title="Edit this regex"><a href="{$smarty.const.WWW_TOP}/release_naming_regexes-edit.php?id={$row.id}">{$row.regex|escape:html|truncate:50:"...":true}</a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
<div style="margin-top: 15px">{$pager}</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,35 @@
|
||||
<h1>{$page->title}</h1>
|
||||
<p>This page is used for testing regex for getting release names from usenet subject.
|
||||
<br />Maximum releases to display will limit the amount of results displayed on the page. 0 for no limit.
|
||||
<br />Query limit will limit the amount of releases to select from MySQL (setting this high can be very slow). 0 for no limit.
|
||||
</p>
|
||||
|
||||
<form name="search" action="" method="post" style="margin-bottom:5px;">
|
||||
<label for="group" style="padding-right:1px">Group:</label>
|
||||
<input id="group" type="text" name="group" value="{$group|htmlentities}" size="20" /><br />
|
||||
<label for="regex" style="padding-right:1px">Regex:</label>
|
||||
<input id="regex" type="text" name="regex" value="{$regex|htmlentities}" size="100" /><br/>
|
||||
<label for="showlimit" style="padding-right:7px">Maximum releases to display:</label>
|
||||
<input id="showlimit" type="text" name="showlimit" value="{$showlimit}" size="8" /><br/>
|
||||
<label for="querylimit" style="padding-right:7px">Query limit:</label>
|
||||
<input id="querylimit" type="text" name="querylimit" value="{$querylimit}" size="8" /><br/>
|
||||
<input type="submit" value="Test" />
|
||||
</form>
|
||||
{if $data}
|
||||
<table style="margin-top:10px;" class="data Sortable highlight">
|
||||
<tr>
|
||||
<th>Release ID</th>
|
||||
<th>Usenet Subject</th>
|
||||
<th>Old Search Name</th>
|
||||
<th>New Search Name</th>
|
||||
</tr>
|
||||
{foreach from=$data key=id item=names}
|
||||
<tr id="row-{$id}" class="{cycle values=",alt"}">
|
||||
<td>{$id}</td>
|
||||
<td>{$names.subject}</td>
|
||||
<td>{$names.old_name}</td>
|
||||
<td>{$names.new_name}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user