Add files via upload

This commit is contained in:
mutto233
2018-06-29 23:40:09 -04:00
committed by GitHub
parent d8d826844b
commit dd1188506a
10 changed files with 874 additions and 874 deletions

View File

@@ -1,26 +1,26 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Tue Jun 26 23:31:00 2018 Created on Tue Jun 26 23:31:00 2018
@author: Matt @author: Matt
""" """
import re import re
import sys import sys
def atoi(text): def atoi(text):
return int(text) if text.isdigit() else text return int(text) if text.isdigit() else text
def natural_keys(text): def natural_keys(text):
''' '''
alist.sort(key=natural_keys) sorts in human order alist.sort(key=natural_keys) sorts in human order
http://nedbatchelder.com/blog/200712/human_sorting.html http://nedbatchelder.com/blog/200712/human_sorting.html
(See Toothy's implementation in the comments) (See Toothy's implementation in the comments)
''' '''
return [ atoi(c) for c in re.split('(\d+)', text) ] return [ atoi(c) for c in re.split('(\d+)', text) ]
temp_hold = list(sys.argv[1:]) temp_hold = list(sys.argv[1:])
temp_hold.sort(key=natural_keys) temp_hold.sort(key=natural_keys)
file = open('Channels_Sorted.txt','w') file = open('Channels_Sorted.txt','w')
for item in temp_hold: for item in temp_hold:
file.write(item + '\n') file.write(item + '\n')
file.close() file.close()

View File

@@ -1,107 +1,107 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Thu Jun 28 17:33:59 2018 Created on Thu Jun 28 17:33:59 2018
@author: Matt @author: Matt
""" """
import sqlite3 import sqlite3
import os import os
from shutil import copy2 from shutil import copy2
from pseudo_config import plexLibraries as global_commercials from pseudo_config import plexLibraries as global_commercials
channel_dir_increment_symbol = "_" channel_dir_increment_symbol = "_"
# Step ONE: Global database update # Step ONE: Global database update
print("+++++ Doing global update from PLEX") print("+++++ Doing global update from PLEX")
os.system('sudo python PseudoChannel.py -u') os.system('sudo python PseudoChannel.py -u')
base_dirA = os.path.dirname(os.path.abspath(__file__)) base_dirA = os.path.dirname(os.path.abspath(__file__))
locations = "pseudo-channel"+channel_dir_increment_symbol locations = "pseudo-channel"+channel_dir_increment_symbol
channel_dirs = [ item for item in os.listdir('.') if os.path.isdir(os.path.join('.', item)) ] channel_dirs = [ item for item in os.listdir('.') if os.path.isdir(os.path.join('.', item)) ]
channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs)) channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs))
for channel_dir in channel_dirs: for channel_dir in channel_dirs:
# Step TWO: Go to each folder, export the following information # Step TWO: Go to each folder, export the following information
# - Show title, lastEpisodeTitle # - Show title, lastEpisodeTitle
# - Movie title, lastPlayedDate # - Movie title, lastPlayedDate
os.chdir(channel_dir) os.chdir(channel_dir)
channel_dirA = os.path.dirname(os.path.abspath(__file__)) channel_dirA = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(channel_dirA, "pseudo-channel.db") db_path = os.path.join(channel_dirA, "pseudo-channel.db")
print("+++++ Importing from " + db_path) print("+++++ Importing from " + db_path)
try: try:
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
table = conn.cursor() table = conn.cursor()
lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall() lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall()
lastEpisode_export = list(lastEpisode_export) lastEpisode_export = list(lastEpisode_export)
lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall() lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall()
lastMovie_export = list(lastMovie_export) lastMovie_export = list(lastMovie_export)
conn.commit() conn.commit()
conn.close() conn.close()
except: except:
print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one") print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one")
lastEpisode_export = [] lastEpisode_export = []
lastMovie_export = [] lastMovie_export = []
# Step THREE: Delete the previous database, replace with the recently created global one # Step THREE: Delete the previous database, replace with the recently created global one
print("+++++ Copying global update to " + db_path) print("+++++ Copying global update to " + db_path)
copy2('../pseudo-channel.db','.') copy2('../pseudo-channel.db','.')
# Step FOUR: Import the previous information we exported previously # Step FOUR: Import the previous information we exported previously
print("+++++ Exporting to " + db_path) print("+++++ Exporting to " + db_path)
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
table = conn.cursor() table = conn.cursor()
for i in range(0,len(lastEpisode_export)): for i in range(0,len(lastEpisode_export)):
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?" sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
table.execute(sql,lastEpisode_export[i]) table.execute(sql,lastEpisode_export[i])
for i in range(0,len(lastMovie_export)): for i in range(0,len(lastMovie_export)):
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?" sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
table.execute(sql,lastMovie_export[i]) table.execute(sql,lastMovie_export[i])
# Step FIVE: Remove any media not in the directories set of commerical archives # Step FIVE: Remove any media not in the directories set of commerical archives
print("+++++ Trimming database at " + db_path) print("+++++ Trimming database at " + db_path)
os.system('sudo python report_MediaFolders.py') os.system('sudo python report_MediaFolders.py')
local_commercials = open('Commercial_Libraries.txt').read().splitlines() local_commercials = open('Commercial_Libraries.txt').read().splitlines()
local_movies = open('Movie_Libraries.txt').read().splitlines() local_movies = open('Movie_Libraries.txt').read().splitlines()
local_tvs = open('TV_Libraries.txt').read().splitlines() local_tvs = open('TV_Libraries.txt').read().splitlines()
commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials] commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials]
movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies] movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies]
tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs] tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs]
# print(db_path) # print(db_path)
# print(local_commercials) # print(local_commercials)
# print(global_commercials["Commercials"]) # print(global_commercials["Commercials"])
# print(commercial_removal) # print(commercial_removal)
for commercial in commercial_removal: for commercial in commercial_removal:
sql = "DELETE FROM commercials WHERE customSectionName=?" sql = "DELETE FROM commercials WHERE customSectionName=?"
table.execute(sql,(commercial,)) table.execute(sql,(commercial,))
for movie in movie_removal: for movie in movie_removal:
sql = "DELETE FROM movies WHERE customSectionName=?" sql = "DELETE FROM movies WHERE customSectionName=?"
table.execute(sql,(movie,)) table.execute(sql,(movie,))
for tv in tv_removal: for tv in tv_removal:
sql = "DELETE FROM shows WHERE customSectionName=?" sql = "DELETE FROM shows WHERE customSectionName=?"
table.execute(sql,(tv,)) table.execute(sql,(tv,))
sql = "DELETE FROM episodes WHERE customSectionName=?" sql = "DELETE FROM episodes WHERE customSectionName=?"
table.execute(sql,(tv,)) table.execute(sql,(tv,))
conn.commit() conn.commit()
conn.close() conn.close()
os.chdir('..') os.chdir('..')
print("+++++ " + db_path + " complete! Going to next file") print("+++++ " + db_path + " complete! Going to next file")
print("+++++ Global update COMPLETE") print("+++++ Global update COMPLETE")

View File

@@ -1,35 +1,35 @@
If you'd like to set up multi-channel support using PseudoChannel.py, use these scripts to: 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. 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 2) Setup a "crontab" to run generate-channels-daily-schedule.sh script to automate each PseudoChannel.py to generate the daily
schedule. schedule.
3) Use, "updatechannels.sh" to update each channels' local db with newly added Plex library items. 3) Use, "updatechannels.sh" to update each channels' local db with newly added Plex library items.
4) Use, "manual.sh" to manually trigger a particular channel... i.e. `./manual.sh 9`, to switch to channel 9. 4) Use, "manual.sh" to manually trigger a particular channel... i.e. `./manual.sh 9`, to switch to channel 9.
All of these scripts need to be placed in the "./channels/" dir. Your directory structure should look something like this: All of these scripts need to be placed in the "./channels/" dir. Your directory structure should look something like this:
```bash ```bash
-channels/ -channels/
--plex_token.py --plex_token.py
--channel_01/ --channel_01/
---pseudo-channel.db ---pseudo-channel.db
---PseudoChannel.py ---PseudoChannel.py
---...etc. ---...etc.
--channel_02/ --channel_02/
---pseudo-channel.db ---pseudo-channel.db
---PseudoChannel.py ---PseudoChannel.py
---...etc. ---...etc.
--channel_03/ --channel_03/
---pseudo-channel.db ---pseudo-channel.db
---PseudoChannel.py ---PseudoChannel.py
---...etc. ---...etc.
--channelup.sh --channelup.sh
--channeldown.sh --channeldown.sh
--generate-channels-daily-schedule.sh --generate-channels-daily-schedule.sh
--updatechannels.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. *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.

View File

@@ -1,150 +1,150 @@
#!/bin/bash #!/bin/bash
# file: channeldown.sh # file: channeldown.sh
#---- #----
# Simple script to cycle through multiple pseudo-channel instances - triggering start / stop. # Simple script to cycle through multiple pseudo-channel instances - triggering start / stop.
#---- #----
#---- #----
# To Use: # To Use:
# Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just # Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just
# outside of the pseudo-channel directories: # outside of the pseudo-channel directories:
# ------------------- # -------------------
# -channels/ # -channels/
# --pseudo-channel_1/ # --pseudo-channel_1/
# ---startstop.sh # ---startstop.sh
# --pseudo-channel_2/ # --pseudo-channel_2/
# ---startstop.sh # ---startstop.sh
# --pseudo-channel_3/ # --pseudo-channel_3/
# ---startstop.sh # ---startstop.sh
# --channeldown.sh <--- on the same level as the 3 channels. # --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. # Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
SCRIPT_TO_EXECUTE='startstop.sh' SCRIPT_TO_EXECUTE='startstop.sh'
OUTPUT_PREV_CHANNEL_PATH=. OUTPUT_PREV_CHANNEL_PATH=.
OUTPUT_PREV_CHANNEL_FILE=".prevplaying" OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
CHANNEL_DIR_INCREMENT_SYMBOL="_" CHANNEL_DIR_INCREMENT_SYMBOL="_"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
FIRST_RUN=false FIRST_RUN=false
# Scan the dir to see how many channels there are, store them in an arr. # 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) ) CHANNEL_DIR_ARR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL"'[[:digit:]]*' -printf "%P\n" | sort -t"$CHANNEL_DIR_INCREMENT_SYMBOL" -n) )
# Since leading zeros may be an issue, we need to correctly sort the channels. The best way to do this seems to be in python # Since leading zeros may be an issue, we need to correctly sort the channels. The best way to do this seems to be in python
# So a script will take in the channels as they are, then output them in the correct, sorted order in Channels_Sorted.txt. # So a script will take in the channels as they are, then output them in the correct, sorted order in Channels_Sorted.txt.
# We will run the script, then read in the results. # We will run the script, then read in the results.
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]} sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
filename="./Channels_Sorted.txt" filename="./Channels_Sorted.txt"
i=0 i=0
while read -r line while read -r line
do do
name="$line" name="$line"
CHANNEL_DIR_SORTED[i]=$name CHANNEL_DIR_SORTED[i]=$name
i=$((i+1)) i=$((i+1))
done < "$filename" done < "$filename"
# We need to add on top of this a "buffer" where we remove all leading zeros to compare everything on the same level # We need to add on top of this a "buffer" where we remove all leading zeros to compare everything on the same level
# This simply leaves us with the number at the end. NOTE: We should have already sorted things, so this should not be a problem # This simply leaves us with the number at the end. NOTE: We should have already sorted things, so this should not be a problem
for i in "${!CHANNEL_DIR_ARR[@]}" for i in "${!CHANNEL_DIR_ARR[@]}"
do do
CHANNEL_DIR_NUMBERS[i]=$(echo ${CHANNEL_DIR_SORTED[i]} | sed "s/^pseudo-channel${CHANNEL_DIR_INCREMENT_SYMBOL}0*//") CHANNEL_DIR_NUMBERS[i]=$(echo ${CHANNEL_DIR_SORTED[i]} | sed "s/^pseudo-channel${CHANNEL_DIR_INCREMENT_SYMBOL}0*//")
if [ -z ${CHANNEL_DIR_NUMBERS[i]} ]; then if [ -z ${CHANNEL_DIR_NUMBERS[i]} ]; then
CHANNEL_DIR_NUMBERS[i]=0 CHANNEL_DIR_NUMBERS[i]=0
fi fi
done done
# If the previous channel txt file doesn't exist already create it (first run?) # 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 if [ ! -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
#FIRST_RUN_NUM=$((${#CHANNEL_DIR_ARR[@]})) #FIRST_RUN_NUM=$((${#CHANNEL_DIR_ARR[@]}))
echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
echo "First run: $FIRST_RUN_NUM" echo "First run: $FIRST_RUN_NUM"
FIRST_RUN=true FIRST_RUN=true
fi fi
# If this script see's there are multiple channels, # If this script see's there are multiple channels,
# then read file, get prevchannel, increment, and trigger next channel: # then read file, get prevchannel, increment, and trigger next channel:
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
#NEXT_CHANNEL="" #NEXT_CHANNEL=""
NEXT_CHANNEL_NUM=1 NEXT_CHANNEL_NUM=1
PREV_CHANNEL_FOUND=false PREV_CHANNEL_FOUND=false
#PREV_CHANNEL_DIR="" #PREV_CHANNEL_DIR=""
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected." echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
#PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) #PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE)
# We are now going to do the same thing here, just with previous channel # We are now going to do the same thing here, just with previous channel
PREV_CHANNEL=$(echo $(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) | sed "s/^0*//") PREV_CHANNEL=$(echo $(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) | sed "s/^0*//")
if [ -z $PREV_CHANNEL ]; then if [ -z $PREV_CHANNEL ]; then
PREV_CHANNEL=0 PREV_CHANNEL=0
fi fi
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL" echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
# This is our modified way of searching for the correct directory for the previous channel # This is our modified way of searching for the correct directory for the previous channel
for i in "${!CHANNEL_DIR_NUMBERS[@]}" for i in "${!CHANNEL_DIR_NUMBERS[@]}"
do do
item_compare=${CHANNEL_DIR_NUMBERS[i]} item_compare=${CHANNEL_DIR_NUMBERS[i]}
if [ $item_compare -eq $PREV_CHANNEL ]; then if [ $item_compare -eq $PREV_CHANNEL ]; then
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}" echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]} PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
if [ $((i-1)) -lt 0 ]; then if [ $((i-1)) -lt 0 ]; then
ARR_LENGTH=(${#CHANNEL_DIR_SORTED[@]}) ARR_LENGTH=(${#CHANNEL_DIR_SORTED[@]})
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$ARR_LENGTH-1]} NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$ARR_LENGTH-1]}
else else
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i-1))]} NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i-1))]}
fi fi
break break
fi fi
done done
if [ -z $NEXT_CHANNEL ]; then if [ -z $NEXT_CHANNEL ]; then
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]} NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]}
fi fi
echo "+++++ The next channel is: $NEXT_CHANNEL" echo "+++++ The next channel is: $NEXT_CHANNEL"
# Write next channel to previous channel file to reference later # Write next channel to previous channel file to reference later
echo "$NEXT_CHANNEL" | cut -d "_" -f2 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" 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. # 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 # This will stop the previous channels playback & trigger the next channels playback
if [ "$FIRST_RUN" = false ]; then if [ "$FIRST_RUN" = false ]; then
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE" cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
cd ../"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE" cd ../"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
else else
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE" cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
fi fi
sleep 1 sleep 1
fi fi
exit 0 exit 0

View File

@@ -1,144 +1,144 @@
#!/bin/bash #!/bin/bash
# file: channelup.sh # file: channelup.sh
#---- #----
# Simple script to cycle through multiple pseudo-channel instances - triggering start / stop. # Simple script to cycle through multiple pseudo-channel instances - triggering start / stop.
#---- #----
#---- #----
# To Use: # To Use:
# Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just # Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just
# outside of the pseudo-channel directories: # outside of the pseudo-channel directories:
# ------------------- # -------------------
# -channels/ # -channels/
# --pseudo-channel_1/ # --pseudo-channel_1/
# ---startstop.sh # ---startstop.sh
# --pseudo-channel_2/ # --pseudo-channel_2/
# ---startstop.sh # ---startstop.sh
# --pseudo-channel_3/ # --pseudo-channel_3/
# ---startstop.sh # ---startstop.sh
# --channelup.sh <--- on the same level as the 3 channels. # --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. # Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
SCRIPT_TO_EXECUTE='startstop.sh' SCRIPT_TO_EXECUTE='startstop.sh'
OUTPUT_PREV_CHANNEL_PATH=. OUTPUT_PREV_CHANNEL_PATH=.
OUTPUT_PREV_CHANNEL_FILE=".prevplaying" OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
CHANNEL_DIR_INCREMENT_SYMBOL="_" CHANNEL_DIR_INCREMENT_SYMBOL="_"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
FIRST_RUN=false FIRST_RUN=false
# If the previous channel txt file doesn't exist already create it (first run?) # 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 if [ ! -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
FIRST_RUN=true FIRST_RUN=true
fi fi
# If the file exists b # If the file exists b
# Scan the dir to see how many channels there are, store them in an arr. # 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) ) CHANNEL_DIR_ARR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL"'[[:digit:]]*' -printf "%P\n" | sort -t"$CHANNEL_DIR_INCREMENT_SYMBOL" -n) )
# Since leading zeros may be an issue, we need to correctly sort the channels. The best way to do this seems to be in python # Since leading zeros may be an issue, we need to correctly sort the channels. The best way to do this seems to be in python
# So a script will take in the channels as they are, then output them in the correct, sorted order in Channels_Sorted.txt. # So a script will take in the channels as they are, then output them in the correct, sorted order in Channels_Sorted.txt.
# We will run the script, then read in the results. # We will run the script, then read in the results.
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]} sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
filename="./Channels_Sorted.txt" filename="./Channels_Sorted.txt"
i=0 i=0
while read -r line while read -r line
do do
name="$line" name="$line"
CHANNEL_DIR_SORTED[i]=$name CHANNEL_DIR_SORTED[i]=$name
i=$((i+1)) i=$((i+1))
done < "$filename" done < "$filename"
# We need to add on top of this a "buffer" where we remove all leading zeros to compare everything on the same level # We need to add on top of this a "buffer" where we remove all leading zeros to compare everything on the same level
# This simply leaves us with the number at the end. NOTE: We should have already sorted things, so this should not be a problem # This simply leaves us with the number at the end. NOTE: We should have already sorted things, so this should not be a problem
for i in "${!CHANNEL_DIR_ARR[@]}" for i in "${!CHANNEL_DIR_ARR[@]}"
do do
CHANNEL_DIR_NUMBERS[i]=$(echo ${CHANNEL_DIR_SORTED[i]} | sed "s/^pseudo-channel${CHANNEL_DIR_INCREMENT_SYMBOL}0*//") CHANNEL_DIR_NUMBERS[i]=$(echo ${CHANNEL_DIR_SORTED[i]} | sed "s/^pseudo-channel${CHANNEL_DIR_INCREMENT_SYMBOL}0*//")
if [ -z ${CHANNEL_DIR_NUMBERS[i]} ]; then if [ -z ${CHANNEL_DIR_NUMBERS[i]} ]; then
CHANNEL_DIR_NUMBERS[i]=0 CHANNEL_DIR_NUMBERS[i]=0
fi fi
done done
# If this script see's there are multiple channels, # If this script see's there are multiple channels,
# then read file, get prevchannel, increment, and trigger next channel: # then read file, get prevchannel, increment, and trigger next channel:
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
#NEXT_CHANNEL="" #NEXT_CHANNEL=""
PREV_CHANNEL_FOUND=false PREV_CHANNEL_FOUND=false
#PREV_CHANNEL_DIR="" #PREV_CHANNEL_DIR=""
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected." echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
#PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) #PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE)
# We are now going to do the same thing here, just with previous channel # We are now going to do the same thing here, just with previous channel
PREV_CHANNEL=$(echo $(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) | sed "s/^0*//") PREV_CHANNEL=$(echo $(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) | sed "s/^0*//")
if [ -z $PREV_CHANNEL ]; then if [ -z $PREV_CHANNEL ]; then
PREV_CHANNEL=0 PREV_CHANNEL=0
fi fi
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL" echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
# This is our modified way of searching for the correct directory for the previous channel # This is our modified way of searching for the correct directory for the previous channel
for i in "${!CHANNEL_DIR_NUMBERS[@]}" for i in "${!CHANNEL_DIR_NUMBERS[@]}"
do do
item_compare=${CHANNEL_DIR_NUMBERS[i]} item_compare=${CHANNEL_DIR_NUMBERS[i]}
if [ $item_compare -eq $PREV_CHANNEL ]; then if [ $item_compare -eq $PREV_CHANNEL ]; then
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}" echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]} PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
if [ $((i+1)) -gt $((${#CHANNEL_DIR_SORTED[@]}-1)) ]; then if [ $((i+1)) -gt $((${#CHANNEL_DIR_SORTED[@]}-1)) ]; then
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]} NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]}
else else
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i+1))]} NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i+1))]}
fi fi
break break
fi fi
done done
if [ -z $NEXT_CHANNEL ]; then if [ -z $NEXT_CHANNEL ]; then
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]} NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]}
fi fi
echo "+++++ The next channel is: $NEXT_CHANNEL" echo "+++++ The next channel is: $NEXT_CHANNEL"
# Write next channel to previous channel file to reference later # Write next channel to previous channel file to reference later
echo "$NEXT_CHANNEL" | cut -d "_" -f2 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" 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. # 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 # This will stop the previous channels playback & trigger the next channels playback
if [ "$FIRST_RUN" = false ]; then if [ "$FIRST_RUN" = false ]; then
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE" cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
cd ../"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE" cd ../"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
else else
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE" cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL" && ./"$SCRIPT_TO_EXECUTE"
fi fi
sleep 1 sleep 1
fi fi
exit 0 exit 0

View File

@@ -1,72 +1,72 @@
#!/bin/bash #!/bin/bash
# file: generate-channels-daily-schedules.sh # file: generate-channels-daily-schedules.sh
#---- #----
# Simple script to generate the daily schedule for each individual channel. # Simple script to generate the daily schedule for each individual channel.
# #
#---- #----
#---- #----
# To Use: # To Use:
# This script needs to be setup with a crontab entry that runs everyday at midnight. # This script needs to be setup with a crontab entry that runs everyday at midnight.
#---- #----
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -g' SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -g'
OUTPUT_PREV_CHANNEL_PATH=. OUTPUT_PREV_CHANNEL_PATH=.
CHANNEL_DIR_INCREMENT_SYMBOL="_" CHANNEL_DIR_INCREMENT_SYMBOL="_"
PYTHON_TO_USE="$(which python)" PYTHON_TO_USE="$(which python)"
# If using 'virtualenv' with python, specify the local virtualenv dir. # If using 'virtualenv' with python, specify the local virtualenv dir.
VIRTUAL_ENV_DIR="env" VIRTUAL_ENV_DIR="env"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
# If virtualenv specified & exists, using that version of python instead. # If virtualenv specified & exists, using that version of python instead.
if [ -d "$VIRTUAL_ENV_DIR" ]; then if [ -d "$VIRTUAL_ENV_DIR" ]; then
PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python" PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python"
echo "+++++ Virtualenv found, using: $VIRTUAL_ENV_DIR/bin/python" echo "+++++ Virtualenv found, using: $VIRTUAL_ENV_DIR/bin/python"
fi fi
# Scan the dir to see how many channels there are, store them in an arr. # 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) ) 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, # If this script see's there are multiple channels,
# then loop through each channel and run the daily schedule generator # then loop through each channel and run the daily schedule generator
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected." echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
for channel in "${CHANNEL_DIR_ARR[@]}" for channel in "${CHANNEL_DIR_ARR[@]}"
do do
# If the .pid file exists for this channel, skip it because it will update while running. # If the .pid file exists for this channel, skip it because it will update while running.
if [ ! -f "$channel/running.pid" ]; then if [ ! -f "$channel/running.pid" ]; then
echo "+++++ Trying to generate daily schedule: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS echo "+++++ Trying to generate daily schedule: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
cd "$channel" && "./generate_daily_sched.sh" cd "$channel" && "./generate_daily_sched.sh"
echo "+++++ Generated: $channel - new schedule." echo "+++++ Generated: $channel - new schedule."
sleep 1 sleep 1
cd ../ cd ../
sleep 1 sleep 1
fi fi
done done
fi fi
exit 0 exit 0

View File

@@ -1,164 +1,164 @@
#!/bin/bash #!/bin/bash
# Credits: irodimus # Credits: irodimus
# file: manual.sh # file: manual.sh
#---- #----
# Simple script to change to specific channel given - triggering start / stop. # Simple script to change to specific channel given - triggering start / stop.
#---- #----
#---- #----
# To Use: # To Use:
# Run script by including the channel you'd like to run as an argument: ex. ./manual.sh 2, ./manual.sh 9 # Run script by including the channel you'd like to run as an argument: ex. ./manual.sh 2, ./manual.sh 9
# #
# Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just # Configure something (a tv remote or alexa) to trigger this script. Make sure you move this script just
# outside of the pseudo-channel directories: # outside of the pseudo-channel directories:
# ------------------- # -------------------
# -channels/ # -channels/
# --pseudo-channel_1/ # --pseudo-channel_1/
# ---startstop.sh # ---startstop.sh
# --pseudo-channel_2/ # --pseudo-channel_2/
# ---startstop.sh # ---startstop.sh
# --pseudo-channel_3/ # --pseudo-channel_3/
# ---startstop.sh # ---startstop.sh
# --manual.sh <--- on the same level as the 3 channels. # --manual.sh <--- on the same level as the 3 channels.
#---- #----
# Make sure that each channel dir ends with a "_" + an incrementing number as seen above. # Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
SCRIPT_TO_EXECUTE='startstop.sh' SCRIPT_TO_EXECUTE='startstop.sh'
OUTPUT_PREV_CHANNEL_PATH=. OUTPUT_PREV_CHANNEL_PATH=.
OUTPUT_PREV_CHANNEL_FILE=".prevplaying" OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
CHANNEL_DIR_INCREMENT_SYMBOL="_" CHANNEL_DIR_INCREMENT_SYMBOL="_"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
FIRST_RUN=false FIRST_RUN=false
# Scan the dir to see how many channels there are, store them in an arr. # 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) ) CHANNEL_DIR_ARR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL"'[[:digit:]]*' -printf "%P\n" | sort -t"$CHANNEL_DIR_INCREMENT_SYMBOL" -n) )
# Since leading zeros may be an issue, we need to correctly sort the channels. The best way to do this seems to be in python # Since leading zeros may be an issue, we need to correctly sort the channels. The best way to do this seems to be in python
# So a script will take in the channels as they are, then output them in the correct, sorted order in Channels_Sorted.txt. # So a script will take in the channels as they are, then output them in the correct, sorted order in Channels_Sorted.txt.
# We will run the script, then read in the results. # We will run the script, then read in the results.
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]} sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
filename="./Channels_Sorted.txt" filename="./Channels_Sorted.txt"
i=0 i=0
while read -r line while read -r line
do do
name="$line" name="$line"
CHANNEL_DIR_SORTED[i]=$name CHANNEL_DIR_SORTED[i]=$name
i=$((i+1)) i=$((i+1))
done < "$filename" done < "$filename"
# We need to add on top of this a "buffer" where we remove all leading zeros to compare everything on the same level # We need to add on top of this a "buffer" where we remove all leading zeros to compare everything on the same level
# This simply leaves us with the number at the end. NOTE: We should have already sorted things, so this should not be a problem # This simply leaves us with the number at the end. NOTE: We should have already sorted things, so this should not be a problem
for i in "${!CHANNEL_DIR_ARR[@]}" for i in "${!CHANNEL_DIR_ARR[@]}"
do do
CHANNEL_DIR_NUMBERS[i]=$(echo ${CHANNEL_DIR_SORTED[i]} | sed "s/^pseudo-channel${CHANNEL_DIR_INCREMENT_SYMBOL}0*//") CHANNEL_DIR_NUMBERS[i]=$(echo ${CHANNEL_DIR_SORTED[i]} | sed "s/^pseudo-channel${CHANNEL_DIR_INCREMENT_SYMBOL}0*//")
if [ -z ${CHANNEL_DIR_NUMBERS[i]} ]; then if [ -z ${CHANNEL_DIR_NUMBERS[i]} ]; then
CHANNEL_DIR_NUMBERS[i]=0 CHANNEL_DIR_NUMBERS[i]=0
fi fi
done done
# If the previous channel txt file doesn't exist already create it (first run?) # 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 if [ ! -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
#FIRST_RUN_NUM=$((${#CHANNEL_DIR_ARR[@]})) #FIRST_RUN_NUM=$((${#CHANNEL_DIR_ARR[@]}))
echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" echo 1 > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
echo "First run being conducted" echo "First run being conducted"
FIRST_RUN=true FIRST_RUN=true
fi fi
# If this script see's there are multiple channels, # If this script see's there are multiple channels,
# then read file, get prevchannel and nextchannel, and trigger next channel: # then read file, get prevchannel and nextchannel, and trigger next channel:
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected." echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
#NEXT_CHANNEL=$1 #NEXT_CHANNEL=$1
#NEXT_CHANNEL_DIR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL""$NEXT_CHANNEL" -printf "%P\n") ) #NEXT_CHANNEL_DIR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL""$NEXT_CHANNEL" -printf "%P\n") )
# We now need to read in the next channel and ALSO strip it of any leading zeros for correct comparison # We now need to read in the next channel and ALSO strip it of any leading zeros for correct comparison
NEXT_CHANNEL=$(echo $1 | sed "s/^0*//") NEXT_CHANNEL=$(echo $1 | sed "s/^0*//")
if [ -z $NEXT_CHANNEL ]; then if [ -z $NEXT_CHANNEL ]; then
NEXT_CHANNEL=0 NEXT_CHANNEL=0
fi fi
PREV_CHANNEL_FOUND=false PREV_CHANNEL_FOUND=false
#PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) #PREV_CHANNEL=$(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE)
# PREV_CHANNEL_DIR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL""$PREV_CHANNEL" -printf "%P\n") ) # PREV_CHANNEL_DIR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL""$PREV_CHANNEL" -printf "%P\n") )
# We are now going to do the same thing here, just with previous channel # We are now going to do the same thing here, just with previous channel
PREV_CHANNEL=$(echo $(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) | sed "s/^0*//") PREV_CHANNEL=$(echo $(<$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE) | sed "s/^0*//")
if [ -z $PREV_CHANNEL ]; then if [ -z $PREV_CHANNEL ]; then
PREV_CHANNEL=0 PREV_CHANNEL=0
fi fi
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL" echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
echo "+++++ The next channel is: $NEXT_CHANNEL" echo "+++++ The next channel is: $NEXT_CHANNEL"
# This is our modified way of searching for the correct directory for the next channel # This is our modified way of searching for the correct directory for the next channel
for i in "${!CHANNEL_DIR_NUMBERS[@]}" for i in "${!CHANNEL_DIR_NUMBERS[@]}"
do do
item_compare=${CHANNEL_DIR_NUMBERS[i]} item_compare=${CHANNEL_DIR_NUMBERS[i]}
if [ $item_compare -eq $NEXT_CHANNEL ]; then if [ $item_compare -eq $NEXT_CHANNEL ]; then
echo "NEXT CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}" echo "NEXT CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
NEXT_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]} NEXT_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
break break
fi fi
done done
# This is our modified way of searching for the correct directory for the previous channel # This is our modified way of searching for the correct directory for the previous channel
for i in "${!CHANNEL_DIR_NUMBERS[@]}" for i in "${!CHANNEL_DIR_NUMBERS[@]}"
do do
item_compare=${CHANNEL_DIR_NUMBERS[i]} item_compare=${CHANNEL_DIR_NUMBERS[i]}
if [ $item_compare -eq $PREV_CHANNEL ]; then if [ $item_compare -eq $PREV_CHANNEL ]; then
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}" echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]} PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
break break
fi fi
done done
# Write next channel to previous channel file to reference later # Write next channel to previous channel file to reference later
echo "$NEXT_CHANNEL" > "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" echo "$NEXT_CHANNEL" > "$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. # 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 # This will stop the previous channels playback & trigger the next channels playback
if [ "$FIRST_RUN" = false ]; then if [ "$FIRST_RUN" = false ]; then
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE" cd "$OUTPUT_PREV_CHANNEL_PATH"/"$PREV_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
cd ../"$NEXT_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE" cd ../"$NEXT_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
else else
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE" cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
fi fi
sleep 1 sleep 1
fi fi
exit 0 exit 0

View File

@@ -1,4 +1,4 @@
'''Change the values below, rename this file to "plex_token.py", and move this file just '''Change the values below, rename this file to "plex_token.py", and move this file just
outside of this directory ("../pseudo-channel")''' outside of this directory ("../pseudo-channel")'''
token = "<your token>" token = "<your token>"
baseurl = 'http://media.home:32400' baseurl = 'http://media.home:32400'

View File

@@ -1,103 +1,103 @@
#!/bin/bash #!/bin/bash
# file: stopall.sh # file: stopall.sh
#---- #----
# Simple script to stop any/all channels by killing the processes/deleting the corresponding # Simple script to stop any/all channels by killing the processes/deleting the corresponding
# .pid files/previouschannel file. # .pid files/previouschannel file.
# #
#---- #----
#---- #----
# To Use: # To Use:
# This script needs to be placed on the same level as your channels. # This script needs to be placed on the same level as your channels.
#---- #----
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
OUTPUT_PREV_CHANNEL_PATH=. OUTPUT_PREV_CHANNEL_PATH=.
OUTPUT_PREV_CHANNEL_FILE=".prevplaying" OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
CHANNEL_DIR_INCREMENT_SYMBOL="_" CHANNEL_DIR_INCREMENT_SYMBOL="_"
PID_FILE_NAME="running.pid" PID_FILE_NAME="running.pid"
# If using 'virtualenv' with python, specify the local virtualenv dir. # If using 'virtualenv' with python, specify the local virtualenv dir.
VIRTUAL_ENV_DIR="env" VIRTUAL_ENV_DIR="env"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
FIRST_RUN=false FIRST_RUN=false
# If the prevplaying file exists, delete it # If the prevplaying file exists, delete it
if [ -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then if [ -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
rm "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" rm "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
fi fi
# Scan the dir to see how many channels there are, store them in an arr. # 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) ) 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, # If this script see's there are multiple channels,
# check each channel dir for running .pid file to kill the process/delete the file: # check each channel dir for running .pid file to kill the process/delete the file:
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
NEXT_CHANNEL="" NEXT_CHANNEL=""
PREV_CHANNEL_FOUND=false PREV_CHANNEL_FOUND=false
PREV_CHANNEL_DIR="" PREV_CHANNEL_DIR=""
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected." echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
# Loop through each Channel Dir, if .pid file exists, then kill pid and rm pid file. # Loop through each Channel Dir, if .pid file exists, then kill pid and rm pid file.
for channel in "${CHANNEL_DIR_ARR[@]}" for channel in "${CHANNEL_DIR_ARR[@]}"
do do
if [ -e "$channel/$PID_FILE_NAME" ]; then if [ -e "$channel/$PID_FILE_NAME" ]; then
the_pid=$(<$channel/$PID_FILE_NAME) the_pid=$(<$channel/$PID_FILE_NAME)
kill "$the_pid" kill "$the_pid"
COUNTER=1 COUNTER=1
while [ -e /proc/$the_pid ] while [ -e /proc/$the_pid ]
do do
echo "+++++ $the_pid is still running" echo "+++++ $the_pid is still running"
sleep .7 sleep .7
COUNTER=$[$COUNTER +1] COUNTER=$[$COUNTER +1]
if [ $COUNTER -eq 20 ]; then if [ $COUNTER -eq 20 ]; then
kill -9 "$the_pid" kill -9 "$the_pid"
fi fi
if [ $COUNTER -eq 40 ]; then if [ $COUNTER -eq 40 ]; then
exit 1 exit 1
fi fi
done done
echo "+++++ $the_pid has finished" echo "+++++ $the_pid has finished"
echo "+++++ Removing $channel/$PID_FILE_NAME" echo "+++++ Removing $channel/$PID_FILE_NAME"
rm "$channel/$PID_FILE_NAME" rm "$channel/$PID_FILE_NAME"
fi fi
done done
echo "Exiting stop-all-channels.sh script." echo "Exiting stop-all-channels.sh script."
fi fi
exit 0 exit 0

View File

@@ -1,77 +1,77 @@
#!/bin/bash #!/bin/bash
# file: updatechannels.sh # file: updatechannels.sh
#---- #----
# Simple script to updates each channels local db with new Plex lib items / xml. # Simple script to updates each channels local db with new Plex lib items / xml.
#---- #----
#---- #----
# To Use: # To Use:
# If you added new content to your Plex Library, just make this file executable move it # 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 # 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. # Make sure that each channel dir ends with a "_" + an incrementing number as seen above.
#----BEGIN EDITABLE VARS---- #----BEGIN EDITABLE VARS----
SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -u -xml' SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -u -xml'
OUTPUT_PREV_CHANNEL_PATH=. OUTPUT_PREV_CHANNEL_PATH=.
CHANNEL_DIR_INCREMENT_SYMBOL="_" CHANNEL_DIR_INCREMENT_SYMBOL="_"
PYTHON_TO_USE="$(which python)" PYTHON_TO_USE="$(which python)"
# If using 'virtualenv' with python, specify the local virtualenv dir. # If using 'virtualenv' with python, specify the local virtualenv dir.
VIRTUAL_ENV_DIR="env" VIRTUAL_ENV_DIR="env"
#----END EDITABLE VARS------- #----END EDITABLE VARS-------
# If virtualenv specified & exists, using that version of python instead. # If virtualenv specified & exists, using that version of python instead.
if [ -d "$VIRTUAL_ENV_DIR" ]; then if [ -d "$VIRTUAL_ENV_DIR" ]; then
PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python" PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python"
fi fi
# If virtualenv specified & exists at root of project, using that version of python instead. # If virtualenv specified & exists at root of project, using that version of python instead.
if [ -d "../$VIRTUAL_ENV_DIR" ]; then if [ -d "../$VIRTUAL_ENV_DIR" ]; then
PYTHON_TO_USE="../$VIRTUAL_ENV_DIR/bin/python" PYTHON_TO_USE="../$VIRTUAL_ENV_DIR/bin/python"
fi fi
# If the file exists b # If the file exists b
# Scan the dir to see how many channels there are, store them in an arr. # 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) ) 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, # If this script see's there are multiple channels,
# then loop through each channel and run the updates # then loop through each channel and run the updates
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 0 ]; then if [ "${#CHANNEL_DIR_ARR[@]}" -gt 0 ]; then
# If virtualenv specified & exists, using that version of python instead. # If virtualenv specified & exists, using that version of python instead.
if [ -d "./$channel/$VIRTUAL_ENV_DIR" ]; then if [ -d "./$channel/$VIRTUAL_ENV_DIR" ]; then
PYTHON_TO_USE=./"$channel"/"$VIRTUAL_ENV_DIR/bin/python" PYTHON_TO_USE=./"$channel"/"$VIRTUAL_ENV_DIR/bin/python"
fi fi
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected." echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
for channel in "${CHANNEL_DIR_ARR[@]}" for channel in "${CHANNEL_DIR_ARR[@]}"
do do
echo "+++++ Trying to update: $PYTHON_TO_USE $channel/$SCRIPT_TO_EXECUTE_PLUS_ARGS" 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. # 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 "$PYTHON_TO_USE" "$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
sleep 1 sleep 1
done done
fi fi
exit 0 exit 0