Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
Upcoming now shows everything, and decorates - needs graphical fixes/…
Browse files Browse the repository at this point in the history
…tweaks
  • Loading branch information
demonrik committed Feb 3, 2020
1 parent 128b4ab commit 4457172
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 71 deletions.
6 changes: 1 addition & 5 deletions app/includes/dvrui_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
require_once("vars.php");
define('NO_IMAGE','images/no-preview.png');

function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8');
}
function getJsonFromUrl($url) {
$content = getURL($url);
return json_decode($content, true);
Expand All @@ -28,7 +24,7 @@ function getCachedJsonFromUrl($url,$maxAgeSeconds) {
$current_time = time();
$file_time = filemtime($cachefilename);
if ($current_time - $maxAgeSeconds < $file_time){
$content = file_get_contents_utf8($cachefilename);
$content = file_get_contents($cachefilename);
}else{
unlink($cachefilename);
$content = getURL($url);
Expand Down
47 changes: 42 additions & 5 deletions app/includes/dvrui_upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class DVRUI_Upcoming {
private $epData_ChannelImageURL = 'ChannelImageURL';
private $epData_ChannelName = 'ChannelName';
private $epData_ChannelNumber = 'ChannelNumber';
private $epData_Duplicate = 'dvruiDuplicate';
private $epData_Exists = 'dvruiExists';
private $epData_Conflict = 'dvruiConflict';
private $epData_Flags = 'dvruiFlags';
private $cachesecs = 3600;
private $upcoming_list = array();
private $series_list = array();
Expand Down Expand Up @@ -80,6 +84,10 @@ private function extractEpisodeInfo($episode){
$channelName = '';
$channelNumber = '';
$originalAirDate = '';
$duplicate = false;
$exists = false;
$conflict = false;
$flags = 0;

$recordingRule = $episode[$this->epData_RecordingRule];

Expand Down Expand Up @@ -116,6 +124,17 @@ private function extractEpisodeInfo($episode){
if (array_key_exists($this->epData_ImageURL,$episode)) {
$imageURL = $episode[$this->epData_ImageURL];
}

if ($this->isDuplicate($episode)) {
$duplicate = true;
$flags++;
}

if ($this->alreadyExists($episode)) {
$exists = true;
$flags++;
}

$this->upcoming_list[] = array(
$this->epData_ProgramID => $programID,
$this->epData_Title => $title,
Expand All @@ -128,7 +147,12 @@ private function extractEpisodeInfo($episode){
$this->epData_Synopsis => $synopsis,
$this->epData_ChannelName => $channelName,
$this->epData_ChannelNumber => $channelNumber,
$this->epData_RecordingRule => $recordingRule);
$this->epData_RecordingRule => $recordingRule,
$this->epData_Flags => $flags,
$this->epData_Duplicate => $duplicate,
$this->epData_Exists => $exists,
$this->epData_Conflict => $conflict
);
}

public function getSeriesCount() {
Expand Down Expand Up @@ -183,10 +207,7 @@ public function processNext($pos) {
}
for ($i = 0; $i < count($episodes_info); $i++) {
if (array_key_exists($this->epData_RecordingRule,$episodes_info[$i])){
if ((!$this->isDuplicate($episodes_info[$i]))
&& (!$this->alreadyExists($episodes_info[$i]))){
$this->extractEpisodeInfo($episodes_info[$i]);
}
$this->extractEpisodeInfo($episodes_info[$i]);
}
}
}
Expand Down Expand Up @@ -315,5 +336,21 @@ public function getEpSynopsis($pos) {
}
}

public function getEpFlags($pos){
return $this->upcoming_list[$pos][$this->epData_Flags];
}

public function getEpFlags_duplicate($pos){
return $this->upcoming_list[$pos][$this->epData_Duplicate];
}

public function getEpFlag_exist($pos){
return $this->upcoming_list[$pos][$this->epData_Exists];
}

public function getEpFlag_conflict($pos){
return $this->upcoming_list[$pos][$this->epData_Conflict];
}

}
?>
1 change: 1 addition & 0 deletions app/style/upcoming_decorator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img src='<!-- dvr_upcoming_decorator -->' class='upcoming_decorator_img'/>
3 changes: 3 additions & 0 deletions app/style/upcoming_entry_tile.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<p></p>
<p>Start: <!-- dvr_upcoming_start --></p>
<p>Channel: <!-- dvr_upcoming_channels --> <!-- dvr_upcoming_channel_name --></p>
<p class='upcoming_decorators'>
<!-- dvr_upcoming_decorators -->
</p>
</div>
118 changes: 58 additions & 60 deletions app/upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,44 @@ function openUpcomingPage($seriesid) {
return $tab->getString();
}

function getUpcoming() {
// Discover Recording Rules
function processUpcomingEntry($upcoming, $pos) {
if (getUpcomingViewMode() == 'list') {
$entry = file_get_contents('style/upcoming_entry_list.html');
} else {
$entry = file_get_contents('style/upcoming_entry_tile.html');
}

$entry = str_replace('<!-- dvr_upcoming_title -->',$upcoming->getTitle($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_episode -->',$upcoming->getEpNum($pos) . ' : ' . $upcoming->getEpTitle($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_original_airdate -->',$upcoming->getEpOriginalAirDate($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_image -->',$upcoming->getEpImg($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_synopsis -->',$upcoming->getEpSynopsis($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_start -->',$upcoming->getEpStart($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_stop -->',$upcoming->getEpEnd($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_channels -->',$upcoming->getEpChannelNum($pos),$entry);
$entry = str_replace('<!-- dvr_upcoming_channel_name -->',$upcoming->getEpChannelName($pos),$entry);

$decorator='';
if ($upcoming->getEpFlags($pos) > 0 ) {
if ($upcoming->getEpFlags_duplicate($pos)) {
$decorator.='[D]';
}
if ($upcoming->getEpFlag_exist($pos)) {
$decorator.='[E]';
}
if ($upcoming->getEpFlag_conflict($pos)) {
$decorator.='[C]';
}
}
error_log("trying to add decorator " . $decorator);
$entry = str_replace('<!-- dvr_upcoming_decorators -->',$decorator,$entry);

return $entry;
}

function processUpcoming($upcoming) {
$htmlStr = '';
$entryData = '';
$hdhr = new DVRUI_HDHRjson();
$hdhrRules = new DVRUI_Rules($hdhr);
$hdhrRules->processAllRules();
$hdhrRecordings = new DVRUI_Recordings($hdhr);
$hdhrRecordings->processAllRecordings($hdhr);
$upcoming = new DVRUI_Upcoming($hdhr,$hdhrRecordings);
$upcoming->initByRules($hdhrRules);
$numRules = $upcoming->getSeriesCount();
for ($i=0; $i < $numRules; $i++) {
$upcoming->processNext($i);
}

$upcoming->sortUpcomingByDate();
$numShows = $upcoming->getUpcomingCount();
$prevdate = "";
Expand All @@ -63,29 +85,35 @@ function getUpcoming() {
$entryData .= $entry;
}

if (getUpcomingViewMode() == 'list') {
$entry = file_get_contents('style/upcoming_entry_list.html');
} else {
$entry = file_get_contents('style/upcoming_entry_tile.html');
}
$entry = str_replace('<!-- dvr_upcoming_title -->',$upcoming->getTitle($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_episode -->',$upcoming->getEpNum($i) . ' : ' . $upcoming->getEpTitle($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_original_airdate -->',$upcoming->getEpOriginalAirDate($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_image -->',$upcoming->getEpImg($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_synopsis -->',$upcoming->getEpSynopsis($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_start -->',$upcoming->getEpStart($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_stop -->',$upcoming->getEpEnd($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_channels -->',$upcoming->getEpChannelNum($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_channel_name -->',$upcoming->getEpChannelName($i),$entry);
$entryData .= $entry;
$entryData .= processUpcomingEntry($upcoming, $i);;
$prevdate = $newdate;
}
$htmlStr = getCalendar($upcoming);
$htmlStr .= file_get_contents('style/upcoming_list.html');

$htmlStr = str_replace('<!-- dvr_upcoming_count -->','Found: ' . $numShows . ' Shows. ',$htmlStr);
$htmlStr = str_replace('<!-- dvr_upcoming_list -->',$entryData,$htmlStr);
return $htmlStr;

}

function getUpcoming() {
// Discover Recording Rules
$htmlStr = '';
$entryData = '';
$hdhr = new DVRUI_HDHRjson();
$hdhrRules = new DVRUI_Rules($hdhr);
$hdhrRules->processAllRules();
$hdhrRecordings = new DVRUI_Recordings($hdhr);
$hdhrRecordings->processAllRecordings($hdhr);
$upcoming = new DVRUI_Upcoming($hdhr,$hdhrRecordings);
$upcoming->initByRules($hdhrRules);
$numRules = $upcoming->getSeriesCount();
for ($i=0; $i < $numRules; $i++) {
$upcoming->processNext($i);
}

$htmlStr = processUpcoming($upcoming);

return $htmlStr;
}
Expand All @@ -102,37 +130,8 @@ function getSeriesUpcoming($seriesid) {
$upcoming->sortUpcomingByDate();
$numShows = $upcoming->getUpcomingCount();
$prevdate = "";
for ($i=0; $i < $numShows; $i++) {
$newdate = $upcoming->getEpStartShort($i);
if($prevdate != $newdate){
$entry = file_get_contents('style/upcoming_datebreak.html');
$entry = str_replace('<!-- dvr_upcoming_date -->',$newdate,$entry);
$entryData .= $entry;
}
if (getUpcomingViewMode() == 'list') {
$entry = file_get_contents('style/upcoming_entry_list.html');
} else {
$entry = file_get_contents('style/upcoming_entry_tile.html');
}
$entry = str_replace('<!-- dvr_upcoming_title -->',$upcoming->getTitle($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_episode -->',$upcoming->getEpNum($i) . ' : ' . $upcoming->getEpTitle($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_original_airdate -->',$upcoming->getEpOriginalAirDate($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_image -->',$upcoming->getEpImg($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_synopsis -->',$upcoming->getEpSynopsis($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_start -->',$upcoming->getEpStart($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_stop -->',$upcoming->getEpEnd($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_channels -->',$upcoming->getEpChannelNum($i),$entry);
$entry = str_replace('<!-- dvr_upcoming_channel_name -->',$upcoming->getEpChannelName($i),$entry);
$entryData .= $entry;
$prevdate = $newdate;
}

$htmlStr = getCalendar($upcoming);
$htmlStr .= file_get_contents('style/upcoming_list.html');
$htmlStr = str_replace('<!-- dvr_upcoming_count -->','Found: ' . $numShows . ' Shows. ',$htmlStr);
$htmlStr = str_replace('<!-- dvr_upcoming_list -->',$entryData,$htmlStr);


$htmlStr = processUpcoming($upcoming);
return $htmlStr;
}

Expand All @@ -143,7 +142,6 @@ function getCalendar($upcoming) {
$interval = 'now +' . $i . ' days';
$datearr[] = new DateTime($interval);
}


$html .= "<div class=datepicker><table class=datepicker>";
$html .= "<tr class=datepicker>";
Expand Down
2 changes: 1 addition & 1 deletion app/vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ final class DVRUI_Vars
const DVRUI_discover_cache = 360;
const DVRUI_upcoming_cache = 3600;

const DVRUI_DEBUG = false;
const DVRUI_DEBUG = true;
}
?>

0 comments on commit 4457172

Please sign in to comment.