mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2026-01-06 18:23:15 +00:00
Added multi-channel scripts: viewer/api plus bash script to generate html files.
This commit is contained in:
72
main-dir/generate-html-schedules.sh
Normal file
72
main-dir/generate-html-schedules.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
# file: generate-html-schedules.sh
|
||||
|
||||
#----
|
||||
# Simple script to generate the ONLY the html schedule for each individual channel. Useful when using the multi-channel-viewer.php file.
|
||||
#
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# ./generate-html-schedules.sh
|
||||
#----
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -m'
|
||||
|
||||
OUTPUT_PREV_CHANNEL_PATH=.
|
||||
|
||||
CHANNEL_DIR_INCREMENT_SYMBOL="_"
|
||||
|
||||
PYTHON_TO_USE="$(which python)"
|
||||
|
||||
# If using 'virtualenv' with python, specify the local virtualenv dir.
|
||||
VIRTUAL_ENV_DIR="env"
|
||||
|
||||
#----END EDITABLE VARS-------
|
||||
|
||||
# If virtualenv specified & exists, using that version of python instead.
|
||||
if [ -d "$VIRTUAL_ENV_DIR" ]; then
|
||||
|
||||
PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python"
|
||||
|
||||
echo "+++++ Virtualenv found, using: $VIRTUAL_ENV_DIR/bin/python"
|
||||
|
||||
fi
|
||||
|
||||
# Scan the dir to see how many channels there are, store them in an arr.
|
||||
CHANNEL_DIR_ARR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL"'[[:digit:]]*' -printf "%P\n" | sort -t"$CHANNEL_DIR_INCREMENT_SYMBOL" -n) )
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then loop through each channel and run the daily schedule generator
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
for channel in "${CHANNEL_DIR_ARR[@]}"
|
||||
do
|
||||
|
||||
# If the .pid file exists for this channel, skip it because it updated the html when running.
|
||||
if [ ! -f "$channel/running.pid" ]; then
|
||||
|
||||
echo "+++++ Trying to generate HTML schedule: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
|
||||
cd "$channel" && $PYTHON_TO_USE $SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
|
||||
echo "+++++ Generated: $channel - HTML schedule."
|
||||
|
||||
sleep 1
|
||||
|
||||
cd ../
|
||||
|
||||
sleep 1
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
64
main-dir/multi-channel-api.php
Normal file
64
main-dir/multi-channel-api.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<!--
|
||||
multi-channel-api.php
|
||||
|
||||
This file triggers bash-scripts based on a url string. Simply navigate your browser or use
|
||||
cURL or some other method to pass in URL params to trigger corresponding scripts.
|
||||
|
||||
To use:
|
||||
1) Install PHP
|
||||
sudo apt install php
|
||||
|
||||
2) Run screen (so you can start a simple php server and exit the console):
|
||||
screen
|
||||
|
||||
3) Navigate your directory with all the channels (i.e. /home/pi/channels/), and run a simple php server:
|
||||
php -S 192.168.1.112:8080
|
||||
-Make sure to update the IP:PORT to your client IP and whatever port you want to use/is open.
|
||||
|
||||
4) Trigger a bash script by navigating to your IP:PORT/multi-channel-api.php/?command=THE_COMMAND:
|
||||
http://192.168.1.112:8080/multi-channel-api.php/?command=KEY_CHANNELUP
|
||||
|
||||
or use cURL: curl -I --request GET http://192.168.1.112:8080/?command=KEY_CHANNELUP
|
||||
-->
|
||||
<?php
|
||||
header("HTTP/1.1 200 OK");
|
||||
if (isset($_GET['command'])) {
|
||||
echo $_GET['command'];
|
||||
$command = $_GET['command'];
|
||||
} else {
|
||||
// Fallback behaviour goes here
|
||||
}
|
||||
$old_path = getcwd();
|
||||
chdir('/home/justin/channels/');
|
||||
if ($command == "KEY_PLAY"){
|
||||
$output = shell_exec('./manual.sh 01');
|
||||
} else if ($command == "KEY_STOP"){
|
||||
$output = shell_exec('./stop-all-channels.sh');
|
||||
} else if ($command == "KEY_CHANNELUP"){
|
||||
$output = shell_exec('./channelup.sh');
|
||||
} else if ($command == "KEY_CHANNELDOWN"){
|
||||
$output = shell_exec('./channeldown.sh');
|
||||
} else if ($command == "KEY_1"){
|
||||
$output = shell_exec('./manual.sh 01');
|
||||
} else if ($command == "KEY_2"){
|
||||
$output = shell_exec('./manual.sh 02');
|
||||
} else if ($command == "KEY_3"){
|
||||
$output = shell_exec('./manual.sh 03');
|
||||
} else if ($command == "KEY_4"){
|
||||
$output = shell_exec('./manual.sh 04');
|
||||
} else if ($command == "KEY_5"){
|
||||
$output = shell_exec('./manual.sh 05');
|
||||
} else if ($command == "KEY_6"){
|
||||
$output = shell_exec('./manual.sh 06');
|
||||
} else if ($command == "KEY_7"){
|
||||
$output = shell_exec('./manual.sh 07');
|
||||
} else if ($command == "KEY_8"){
|
||||
$output = shell_exec('./manual.sh 08');
|
||||
} else if ($command == "KEY_9"){
|
||||
$output = shell_exec('./manual.sh 09');
|
||||
} else {
|
||||
//$output = shell_exec('./manual.sh 01');
|
||||
}
|
||||
chdir($old_path);
|
||||
echo "<pre>$output</pre>";
|
||||
?>
|
||||
217
main-dir/multi-channel-viewer.php
Normal file
217
main-dir/multi-channel-viewer.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<!--
|
||||
multi-channel-viewer.php
|
||||
|
||||
To use:
|
||||
1) Install PHP
|
||||
sudo apt install php
|
||||
|
||||
2) Run screen (so you can start a simple php server and exit the console):
|
||||
screen
|
||||
|
||||
3) Navigate your directory with all the channels (i.e. /home/pi/channels/), and run a simple php server:
|
||||
php -S 192.168.1.112:8080
|
||||
-Make sure to update the IP:PORT to your client IP and whatever port you want to use/is open.
|
||||
|
||||
4) Point your browser to the to IP:PORT/multi-channel-viewer.php:
|
||||
http://192.168.1.112:8080/multi-channel-viewer.php
|
||||
|
||||
5) All this does is load in/display (via iframe) the html files that each channel generates.
|
||||
Click "Generate Now Playing Schedules", to generate up-to-date html schedules to view what's playing.
|
||||
-->
|
||||
<!doctype html>
|
||||
<html class="no-js" lang="">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<title></title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="manifest" href="site.webmanifest">
|
||||
<link rel="apple-touch-icon" href="icon.png">
|
||||
<link rel="shortcut icon" href="https://raw.githubusercontent.com/justinemter/pseudo-channel/master/favicon.ico" type="image/x-icon">
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
|
||||
<style type="text/css">
|
||||
.channels-selector {
|
||||
width: 124px;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
}
|
||||
.channels-selector a {
|
||||
margin-top: 3px;
|
||||
font-size: 24px;
|
||||
}
|
||||
.channels-selector .channel-left {
|
||||
float: left;
|
||||
}
|
||||
.channels-selector .channel-right {
|
||||
float: right;
|
||||
}
|
||||
.channels-selector h1 {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
}
|
||||
form {
|
||||
margin: 20px 10px;
|
||||
text-align: center;
|
||||
}
|
||||
.schedules-html-paths {
|
||||
display: none;
|
||||
}
|
||||
.heading {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!--[if lte IE 9]>
|
||||
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
|
||||
<![endif]-->
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
|
||||
<script>window.jQuery || document.write('<script src="js/vendor/jquery-3.3.1.min.js"><\/script>')</script>
|
||||
|
||||
<?php
|
||||
$schedules_html_paths = array();
|
||||
$dirs = array_filter(glob('*'), 'is_dir');
|
||||
|
||||
foreach($dirs as $file)
|
||||
{
|
||||
if (strpos($file, 'channel') !== false) {
|
||||
array_push($schedules_html_paths, $file."/schedules/index.html");
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
function updateNowPlayingSchedules() {
|
||||
exec("./generate-html-schedules.sh",$out);
|
||||
/*foreach($out as $key => $value)
|
||||
{
|
||||
echo $key." ".$value."<br>";
|
||||
}*/
|
||||
echo " Update Complete";
|
||||
}
|
||||
if (isset($_GET['update'])) {
|
||||
echo 'Generating new html schedules.';
|
||||
updateNowPlayingSchedules();
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="schedules-html-paths" data-results="<?php echo implode(",",$schedules_html_paths); ?>"></div>
|
||||
|
||||
<h1 class="heading">Multi-Channel</h1>
|
||||
|
||||
<form id="myForm">
|
||||
<select id="selectNumber">
|
||||
<option>Choose a Channel</option>
|
||||
</select>
|
||||
<a id="gen-schedules" href="?update=true">Generate Now Playing Schedules</a>
|
||||
</form>
|
||||
|
||||
<div class="channels-selector">
|
||||
<a href="#" class="channel-controls channel-left"><</a>
|
||||
<h1></h1>
|
||||
<a href="#" class="channel-controls channel-right">></a>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
var getBackMyJSON = $('.schedules-html-paths').data('results');
|
||||
//console.log(getBackMyJSON);
|
||||
var schedules_html_paths = getBackMyJSON.split(',');
|
||||
//console.log(schedules_html_paths[0]);
|
||||
var select = document.getElementById("selectNumber");
|
||||
var options = [];
|
||||
for(var j = 0; j < schedules_html_paths.length; j++){
|
||||
options.push(schedules_html_paths[j]);
|
||||
//console.log(j);
|
||||
}
|
||||
$('#selectNumber').empty();
|
||||
$('#selectNumber').change(function() {
|
||||
$("#iframeHolder").empty();
|
||||
$("#iframeHolder").append('<iframe id="iframe" src="'+$(this).val()+'" width="100%" height="900"></iframe>');
|
||||
//Getting channel number
|
||||
var channelNum = getChannelNumberFromStr($(this).val());
|
||||
$thisItem = $(this);
|
||||
console.log($thisItem.val());
|
||||
$('#selectNumber option').each(function(){
|
||||
if($(this).val() == $thisItem.val()){
|
||||
console.log("I made it");
|
||||
$(this).attr("selected", "selected");
|
||||
} else {
|
||||
$(this).removeAttr("selected");
|
||||
console.log("In here")
|
||||
}
|
||||
})
|
||||
$(".channels-selector h1").empty().append(channelNum);
|
||||
});
|
||||
$.each(options, function(i, p) {
|
||||
if(i == 0){
|
||||
$('#selectNumber').append($('<option selected="selected"></option>').val(p).html(getChannelNumberFromStr(p)));
|
||||
} else {
|
||||
$('#selectNumber').append($('<option></option>').val(p).html(getChannelNumberFromStr(p)));
|
||||
}
|
||||
});
|
||||
$(".channel-right").click(function(){
|
||||
var nextItem = false;
|
||||
for(var i=0; i < $('#selectNumber option').length; i++){
|
||||
if(nextItem){
|
||||
$('#selectNumber option').eq(i).attr('selected', 'selected');
|
||||
$('#selectNumber').trigger('change');
|
||||
|
||||
break;
|
||||
} else{
|
||||
}
|
||||
if($('#selectNumber option').eq(i).attr("selected") == "selected") {
|
||||
|
||||
if(i != $('#selectNumber option').length -1){
|
||||
$('#selectNumber option').eq(i).removeAttr('selected');
|
||||
}
|
||||
nextItem = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$("#selectNumber option").each(function(i) {
|
||||
|
||||
});
|
||||
});
|
||||
$(".channel-left").click(function(){
|
||||
var nextItem = false;
|
||||
for(var i=$('#selectNumber option').length; i >= 0; i--){
|
||||
if(nextItem){
|
||||
$('#selectNumber option').eq(i).attr('selected', 'selected');
|
||||
$('#selectNumber').trigger('change');
|
||||
break;
|
||||
} else{
|
||||
//
|
||||
}
|
||||
if($('#selectNumber option').eq(i).attr("selected") == "selected") {
|
||||
|
||||
if(i != 0){
|
||||
$('#selectNumber option').eq(i).removeAttr('selected');
|
||||
}
|
||||
nextItem = true;
|
||||
|
||||
}
|
||||
}
|
||||
$("#selectNumber option").each(function(i) {
|
||||
|
||||
});
|
||||
});
|
||||
$('#selectNumber').trigger('change');
|
||||
function getChannelNumberFromStr(str){
|
||||
return str.split('channel_').pop().split('/schedules')[0];
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="iframeHolder"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user