Extended mt to include details of all episode for an invidual series, and forget episodes previous to the most recent one

This commit is contained in:
2010-01-21 14:47:57 +00:00
parent ab75775180
commit 14e376464e

View File

@@ -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 = "<?=$self?>?action=details";
seriesForget(series, episode);
}
</script>
<style>
body {
@@ -308,13 +378,58 @@ label {
</fieldset>
</form>
<?php if (isset($_GET['action']) && $_GET['action'] == 'details') { ?>
<h2>'<?=htmlspecialchars($_GET['series'])?>' Episode List</h2>
<form action="<?$self?>" method="post" id="episodeOperations">
<fieldset>
<legend>Details of each episode for '<?=htmlspecialchars($_GET['series'])?>'</legend>
<table id="episodeList">
<thead>
<tr>
<th>Episode</th>
<th>Downloaded</th>
<th>Title</th>
<th>Quality</th>
<th>Operations</th>
</tr>
</thead>
<?php
foreach ($currentEpisodes as $identifier => $episodes) {
$entryCount = count($episodes);
$rowspan = $entryCount ? " rowspan=\"{$entryCount}\"" : '';
$rowIndex = 0;
foreach ($episodes as $details) {
?>
<tr>
<?php if (!$rowIndex) { ?>
<td<?=$rowspan?>><?=$identifier?></td>
<?php } ?>
<td style="text-align: right;"><?=$details['downloaded'] ? '*' : '&nbsp;'?></td>
<td><?=htmlspecialchars($details['title'])?></td>
<td><?=htmlspecialchars($details['quality'])?></td>
<?php if (!$rowIndex) { ?>
<td<?=$rowspan?>><a title="Forget" onclick="episodeForget('<?=htmlspecialchars($_GET['series'])?>','<?=htmlspecialchars($identifier)?>')"><img class="icon" src="bin.png" /></a></td>
<?php } ?>
</tr>
<?php
++$rowIndex;
}
}
?>
</table>
</fieldset>
</form>
<?php } ?>
<h2>Currently known series/episodes</h2>
<form action="<?$self?>" method="post" id="listOperations">
<fieldset>
<legend></legend>
<legend>Details for most recent episode of each series</legend>
<input type="hidden" id="listAction" name="action" value="" />
<input type="hidden" id="listForgetSeries" name="series" value="" />
<input type="hidden" id="listForgetEpisode" name="episode" value="" />
<input type="hidden" id="listSeries" name="series" value="" />
<input type="hidden" id="listEpisode" name="episode" value="" />
<table id="seriesList">
<thead>
@@ -325,12 +440,12 @@ label {
<th>Operations</th>
</tr>
</thead>
<?php foreach ($currentSeries as $series => $details) {?>
<?php foreach ($currentSeries as $series => $details) { ?>
<tr>
<td><?=htmlspecialchars($series)?></td>
<td><a title="List episodes" href="<?=$self?>?action=details&series=<?=urlencode($series)?>"><?=htmlspecialchars($series)?></a></td>
<td><?=htmlspecialchars($details['episode'])?></td>
<td><?=htmlspecialchars($details['quality'])?></td>
<td><a title="Forget" onclick="seriesForget('<?=htmlspecialchars($series)?>','<?=htmlspecialchars($details['episode'])?>')"><img class="icon" src="bin.png" /></td>
<td><a title="Forget" onclick="seriesForget('<?=htmlspecialchars($series)?>','<?=htmlspecialchars($details['episode'])?>')"><img class="icon" src="bin.png" /></a></td>
</tr>
<?php } ?>
</table>