mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2026-01-02 00:03:15 +00:00
Updated bash scripts dir name/added bashscripts readme.
This commit is contained in:
33
multi-channel-bash-scripts/README.md
Normal file
33
multi-channel-bash-scripts/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
If you'd like to set up multi-channel support using PseudoChannel.py, use these scripts to:
|
||||
|
||||
1) Use a remote or Alexa or some device to trigger the channelup.sh/channeldown.sh scripts to cycle through the channels.
|
||||
|
||||
2) Setup a "crontab" to run generate-channels-daily-schedule.sh script to automate each PseudoChannel.py to generate the daily
|
||||
schedule.
|
||||
|
||||
3) Use, "updatechannels.sh" to update each channels' local db with newly added Plex library items.
|
||||
|
||||
All of these scripts need to be placed one level up from all the channels directories. Your directory structure should look something like this:
|
||||
|
||||
```bash
|
||||
-channels/
|
||||
--plex_token.py
|
||||
--channel_1/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channel_2/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channel_3/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channelup.sh
|
||||
--channeldown.sh
|
||||
--generate-channels-daily-schedule.sh
|
||||
--updatechannels.sh
|
||||
```
|
||||
|
||||
*Note: this functionality is still being tweaked as are the bash scripts so only attempt this implementation if you are somewhat confident to tinker with bash/crontabs, etc. Or feel free to contact us at github or the discord chat room dedicated to PseudoChannel.tv. Just check the repo for more info.
|
||||
128
multi-channel-bash-scripts/channeldown.sh
Normal file
128
multi-channel-bash-scripts/channeldown.sh
Normal file
@@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
|
||||
# file: channeldown.sh
|
||||
|
||||
#----
|
||||
# Simple script to cycle through multiple pseudo-channel instances - triggering start / stop.
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just
|
||||
# outside of the pseudo-channel directories:
|
||||
# -------------------
|
||||
# -channels/
|
||||
# --pseudo-channel_1/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_2/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_3/
|
||||
# ---startstop.sh
|
||||
# --channeldown.sh <--- on the same level as the 3 channels.
|
||||
#----
|
||||
|
||||
# Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
SCRIPT_TO_EXECUTE='startstop.sh'
|
||||
|
||||
OUTPUT_PREV_CHANNEL_PATH=.
|
||||
|
||||
OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
|
||||
|
||||
CHANNEL_DIR_INCREMENT_SYMBOL="_"
|
||||
|
||||
#----END EDITABLE VARS-------
|
||||
|
||||
FIRST_RUN=false
|
||||
|
||||
# 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") )
|
||||
|
||||
# If the previous channel txt file doesn't exist already create it (first run?)
|
||||
if [ ! -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
|
||||
|
||||
#FIRST_RUN_NUM=$((${#CHANNEL_DIR_ARR[@]}))
|
||||
echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
|
||||
|
||||
echo "First run: $FIRST_RUN_NUM"
|
||||
|
||||
FIRST_RUN=true
|
||||
|
||||
fi
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then read file, get prevchannel, increment, and trigger next channel:
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
NEXT_CHANNEL=""
|
||||
|
||||
NEXT_CHANNEL_NUM=1
|
||||
|
||||
PREV_CHANNEL_FOUND=false
|
||||
|
||||
PREV_CHANNEL_DIR=""
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE)
|
||||
|
||||
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
|
||||
|
||||
# Now that the prevchannel is stored in a var, loop through channels and find prev channel & increment
|
||||
for ((i = ${#CHANNEL_DIR_ARR[@]};i >= 1;i--)); do
|
||||
|
||||
NEXT_CHANNEL_NUM=$i
|
||||
|
||||
if [[ ${i} == *"$PREV_CHANNEL"* ]]; then
|
||||
echo "+++++ Found previous channel, incrementing by 1."
|
||||
PREV_CHANNEL_FOUND=true
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_ARR[i-1]}
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$PREV_CHANNEL_FOUND" = true ] ; then
|
||||
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_ARR[i-1]}
|
||||
|
||||
break
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# If the next channel is an empty string, then we need to start the cycle over.
|
||||
if [ -z "$NEXT_CHANNEL" ]; then
|
||||
|
||||
ARR_LENGTH=(${#CHANNEL_DIR_ARR[@]})
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_ARR[$ARR_LENGTH-1]}
|
||||
echo "Starting cycle over."
|
||||
echo "$PREV_CHANNEL_DIR"
|
||||
echo "$NEXT_CHANNEL"
|
||||
|
||||
fi
|
||||
|
||||
echo "+++++ The next channel is: $NEXT_CHANNEL"
|
||||
|
||||
# Write next channel to previous channel file to reference later
|
||||
echo "$NEXT_CHANNEL" | cut -d "_" -f2 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
|
||||
|
||||
# Finally let's trigger the startstop script in both the previous channel and the next channel dirs.
|
||||
# This will stop the previous channels playback & trigger the next channels playback
|
||||
|
||||
if [ "$FIRST_RUN" = false ]; then
|
||||
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
|
||||
cd ../"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
|
||||
else
|
||||
|
||||
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
|
||||
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
119
multi-channel-bash-scripts/channelup.sh
Normal file
119
multi-channel-bash-scripts/channelup.sh
Normal file
@@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
|
||||
# file: channelup.sh
|
||||
|
||||
#----
|
||||
# Simple script to cycle through multiple pseudo-channel instances - triggering start / stop.
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just
|
||||
# outside of the pseudo-channel directories:
|
||||
# -------------------
|
||||
# -channels/
|
||||
# --pseudo-channel_1/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_2/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_3/
|
||||
# ---startstop.sh
|
||||
# --channelup.sh <--- on the same level as the 3 channels.
|
||||
#----
|
||||
|
||||
# Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
SCRIPT_TO_EXECUTE='startstop.sh'
|
||||
|
||||
OUTPUT_PREV_CHANNEL_PATH=.
|
||||
|
||||
OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
|
||||
|
||||
CHANNEL_DIR_INCREMENT_SYMBOL="_"
|
||||
|
||||
#----END EDITABLE VARS-------
|
||||
|
||||
FIRST_RUN=false
|
||||
|
||||
# If the previous channel txt file doesn't exist already create it (first run?)
|
||||
if [ ! -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
|
||||
|
||||
echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
|
||||
|
||||
FIRST_RUN=true
|
||||
|
||||
fi
|
||||
|
||||
# If the file exists b
|
||||
|
||||
# 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") )
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then read file, get prevchannel, increment, and trigger next channel:
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
NEXT_CHANNEL=""
|
||||
|
||||
PREV_CHANNEL_FOUND=false
|
||||
|
||||
PREV_CHANNEL_DIR=""
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE)
|
||||
|
||||
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
|
||||
|
||||
# Now that the prevchannel is stored in a var, loop through channels and find prev channel & increment
|
||||
for channel in "${CHANNEL_DIR_ARR[@]}"
|
||||
do
|
||||
if [[ $channel == *"$PREV_CHANNEL"* ]]; then
|
||||
echo "+++++ Found previous channel, incrementing by 1."
|
||||
PREV_CHANNEL_FOUND=true
|
||||
PREV_CHANNEL_DIR=$channel
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$PREV_CHANNEL_FOUND" = true ] ; then
|
||||
|
||||
NEXT_CHANNEL=$channel
|
||||
|
||||
break
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# If the next channel is an empty string, then we need to start the cycle over.
|
||||
if [ -z "$NEXT_CHANNEL" ]; then
|
||||
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_ARR[0]}
|
||||
|
||||
fi
|
||||
|
||||
echo "+++++ The next channel is: $NEXT_CHANNEL"
|
||||
|
||||
# Write next channel to previous channel file to reference later
|
||||
echo "$NEXT_CHANNEL" | cut -d "_" -f2 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
|
||||
|
||||
# Finally let's trigger the startstop script in both the previous channel and the next channel dirs.
|
||||
# This will stop the previous channels playback & trigger the next channels playback
|
||||
|
||||
if [ "$FIRST_RUN" = false ]; then
|
||||
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
|
||||
cd ../"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
|
||||
else
|
||||
|
||||
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
|
||||
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# file: generate-channels-daily-schedules.sh
|
||||
|
||||
#----
|
||||
# Simple script to generate the daily schedule for each individual channel.
|
||||
#
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# This script needs to be setup with a crontab entry that runs everyday at midnight.
|
||||
#----
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -g'
|
||||
|
||||
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"
|
||||
|
||||
fi
|
||||
|
||||
# If the file exists b
|
||||
|
||||
# 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") )
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then loop through each channel and run the updates
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
# If virtualenv specified & exists, using that version of python instead.
|
||||
if [ -d ./"$channel"/"$VIRTUAL_ENV_DIR" ]; then
|
||||
|
||||
PYTHON_TO_USE=./"$channel"/"$VIRTUAL_ENV_DIR/bin/python"
|
||||
|
||||
fi
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
for channel in "${CHANNEL_DIR_ARR[@]}"
|
||||
do
|
||||
|
||||
echo "+++++ Trying to update: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
# If the running.pid file doesn't exists, create it, start PseudoChannel.py and add the PID to it.
|
||||
"$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
|
||||
sleep 1
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
70
multi-channel-bash-scripts/updatechannels.sh
Normal file
70
multi-channel-bash-scripts/updatechannels.sh
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
# file: updatechannels.sh
|
||||
|
||||
#----
|
||||
# Simple script to updates each channels local db with new Plex lib items / xml.
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# If you added new content to your Plex Library, just make this file executable move it
|
||||
# to where the plex_token.py file is and run ./updatechannels.sh
|
||||
#----
|
||||
|
||||
# Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -u -xml'
|
||||
|
||||
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"
|
||||
|
||||
fi
|
||||
|
||||
# If the file exists b
|
||||
|
||||
# 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") )
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then loop through each channel and run the updates
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
# If virtualenv specified & exists, using that version of python instead.
|
||||
if [ -d ./"$channel"/"$VIRTUAL_ENV_DIR" ]; then
|
||||
|
||||
PYTHON_TO_USE=./"$channel"/"$VIRTUAL_ENV_DIR/bin/python"
|
||||
|
||||
fi
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
for channel in "${CHANNEL_DIR_ARR[@]}"
|
||||
do
|
||||
|
||||
echo "+++++ Trying to update: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
# If the running.pid file doesn't exists, create it, start PseudoChannel.py and add the PID to it.
|
||||
"$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
|
||||
sleep 1
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user