From 14e376464ef369af27e70cb1c36e938bd3663183 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Thu, 21 Jan 2010 14:47:57 +0000 Subject: [PATCH] Extended mt to include details of all episode for an invidual series, and forget episodes previous to the most recent one --- trunk/mt.php | 133 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 9 deletions(-) diff --git a/trunk/mt.php b/trunk/mt.php index 3de205a..4bbc469 100644 --- a/trunk/mt.php +++ b/trunk/mt.php @@ -15,6 +15,7 @@ $messages = array(); $errors = array(); $currentSeries = array(); +$currentEpisodes = array(); if (isset($_POST['action'])) { $action = $_POST['action']; @@ -83,10 +84,15 @@ if (isset($_POST['action'])) { if ($returnValue) { $error = urlencode('Failed to forget about ' . $_POST['series'] . ' ' . $_POST['episode'] . "\n" . join("\n", $output)); header("Location: {$self}?error={$error}"); + #var_dump($_GET,$_POST); exit(0); } else { $message = urlencode('Successfully forgot about ' . $_POST['series'] . ' ' . $_POST['episode']); - header("Location: {$self}?message={$message}"); + $details = ''; + if (isset($_GET['action']) && $_GET['action'] == 'details') { + $details = "&action=details&series=" . urlencode($_POST['series']); + } + header("Location: {$self}?message={$message}{$details}"); exit(0); } break; @@ -103,6 +109,64 @@ if (isset($_POST['action'])) { if (isset($_GET['error'])) { $errors[] = $_GET['error']; } + if (isset($_GET['action'])) { + switch ($_GET['action']) { + case 'details': + if (!isset($_GET['series'])) { + $errors[] = "No series parameter specified"; + break; + } + + $series = escapeshellarg($_GET['series']); + + # Grab the list of episodes for this series + $runCmd = "{$flexgetCmd} --series {$series}"; + + $output = ''; + $returnValue = 0; + exec($runCmd, $output, $returnValue); + + if (!$returnValue) { + // Ignore the first and last two lines from the output + assert('count($output) >= 4; // Expecting at least four lines of output from flexget'); + $output = array_slice($output, 2, -2); + + // Each new entry has one line with the identifier, then one line per version seen + /* + * S01E01 + * Human Target 2010 S01E01 HDTV XviD-NoTV(www.usabit.com)... hdtv + * * Human.Target.2010.S01E01.720p.HDTV.[KvadratMalevicha.ru... 720p + * human.target.s01e01.webdl.rus.novafilm.tv.avi [15/3] unknown + */ + + $matches = array(); + $identifier = null; + foreach ($output as $line) { + if (preg_match('/^\s(s\d\de\d\d|\d+)\s*$/i', $line, $matches)) { + # This line is an identifier + $identifier = $matches[1]; + $currentEpisodes[$identifier] = array(); + } else { + # This line is an entry for the current identifier + if (!preg_match('/\s(.)\s+(.*)\s+(.*)\s*$/', $line, $matches)) { + $errors[] = "Ignored unmatched line '$line'"; + continue; + } + + $currentEpisodes[$identifier][] = array( + 'downloaded' => ($matches[1] == '*'), + 'title' => $matches[2], + 'quality' => $matches[3], + ); + + } + } + } + + + break; + } + } } # Grab the up-to-date list of tv series for display @@ -215,11 +279,17 @@ function removeClass(element, oldclass) { function seriesForget(series, episode) { id("listAction").value = "series-forget"; - id("listForgetSeries").value = series; - id("listForgetEpisode").value = episode; + id("listSeries").value = series; + id("listEpisode").value = episode; id("listOperations").submit(); } + +function episodeForget(series, episode) { + id("listOperations").action = "?action=details"; + + seriesForget(series, episode); +}