mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-28 22:23:13 +00:00
Add files via upload
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue Jun 26 23:31:00 2018
|
||||
|
||||
@author: Matt
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
|
||||
def atoi(text):
|
||||
return int(text) if text.isdigit() else text
|
||||
|
||||
def natural_keys(text):
|
||||
'''
|
||||
alist.sort(key=natural_keys) sorts in human order
|
||||
http://nedbatchelder.com/blog/200712/human_sorting.html
|
||||
(See Toothy's implementation in the comments)
|
||||
'''
|
||||
return [ atoi(c) for c in re.split('(\d+)', text) ]
|
||||
|
||||
temp_hold = list(sys.argv[1:])
|
||||
temp_hold.sort(key=natural_keys)
|
||||
file = open('Channels_Sorted.txt','w')
|
||||
for item in temp_hold:
|
||||
file.write(item + '\n')
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue Jun 26 23:31:00 2018
|
||||
|
||||
@author: Matt
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
|
||||
def atoi(text):
|
||||
return int(text) if text.isdigit() else text
|
||||
|
||||
def natural_keys(text):
|
||||
'''
|
||||
alist.sort(key=natural_keys) sorts in human order
|
||||
http://nedbatchelder.com/blog/200712/human_sorting.html
|
||||
(See Toothy's implementation in the comments)
|
||||
'''
|
||||
return [ atoi(c) for c in re.split('(\d+)', text) ]
|
||||
|
||||
temp_hold = list(sys.argv[1:])
|
||||
temp_hold.sort(key=natural_keys)
|
||||
file = open('Channels_Sorted.txt','w')
|
||||
for item in temp_hold:
|
||||
file.write(item + '\n')
|
||||
file.close()
|
||||
@@ -1,107 +1,107 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Jun 28 17:33:59 2018
|
||||
|
||||
@author: Matt
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
from shutil import copy2
|
||||
from pseudo_config import plexLibraries as global_commercials
|
||||
|
||||
channel_dir_increment_symbol = "_"
|
||||
|
||||
|
||||
|
||||
# Step ONE: Global database update
|
||||
print("+++++ Doing global update from PLEX")
|
||||
os.system('sudo python PseudoChannel.py -u')
|
||||
|
||||
|
||||
base_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||
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 = list(filter(lambda x: x.startswith(locations),channel_dirs))
|
||||
|
||||
for channel_dir in channel_dirs:
|
||||
# Step TWO: Go to each folder, export the following information
|
||||
# - Show title, lastEpisodeTitle
|
||||
# - Movie title, lastPlayedDate
|
||||
os.chdir(channel_dir)
|
||||
|
||||
channel_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
||||
print("+++++ Importing from " + db_path)
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
table = conn.cursor()
|
||||
|
||||
|
||||
lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall()
|
||||
lastEpisode_export = list(lastEpisode_export)
|
||||
lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall()
|
||||
lastMovie_export = list(lastMovie_export)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except:
|
||||
print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one")
|
||||
lastEpisode_export = []
|
||||
lastMovie_export = []
|
||||
|
||||
|
||||
# Step THREE: Delete the previous database, replace with the recently created global one
|
||||
print("+++++ Copying global update to " + db_path)
|
||||
copy2('../pseudo-channel.db','.')
|
||||
|
||||
|
||||
# Step FOUR: Import the previous information we exported previously
|
||||
print("+++++ Exporting to " + db_path)
|
||||
conn = sqlite3.connect(db_path)
|
||||
table = conn.cursor()
|
||||
|
||||
for i in range(0,len(lastEpisode_export)):
|
||||
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
|
||||
table.execute(sql,lastEpisode_export[i])
|
||||
|
||||
for i in range(0,len(lastMovie_export)):
|
||||
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
||||
table.execute(sql,lastMovie_export[i])
|
||||
|
||||
# Step FIVE: Remove any media not in the directories set of commerical archives
|
||||
print("+++++ Trimming database at " + db_path)
|
||||
os.system('sudo python report_MediaFolders.py')
|
||||
local_commercials = open('Commercial_Libraries.txt').read().splitlines()
|
||||
local_movies = open('Movie_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]
|
||||
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]
|
||||
|
||||
# print(db_path)
|
||||
# print(local_commercials)
|
||||
# print(global_commercials["Commercials"])
|
||||
# print(commercial_removal)
|
||||
|
||||
for commercial in commercial_removal:
|
||||
sql = "DELETE FROM commercials WHERE customSectionName=?"
|
||||
table.execute(sql,(commercial,))
|
||||
for movie in movie_removal:
|
||||
sql = "DELETE FROM movies WHERE customSectionName=?"
|
||||
table.execute(sql,(movie,))
|
||||
for tv in tv_removal:
|
||||
sql = "DELETE FROM shows WHERE customSectionName=?"
|
||||
table.execute(sql,(tv,))
|
||||
sql = "DELETE FROM episodes WHERE customSectionName=?"
|
||||
table.execute(sql,(tv,))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
os.chdir('..')
|
||||
|
||||
print("+++++ " + db_path + " complete! Going to next file")
|
||||
|
||||
|
||||
print("+++++ Global update COMPLETE")
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Thu Jun 28 17:33:59 2018
|
||||
|
||||
@author: Matt
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
from shutil import copy2
|
||||
from pseudo_config import plexLibraries as global_commercials
|
||||
|
||||
channel_dir_increment_symbol = "_"
|
||||
|
||||
|
||||
|
||||
# Step ONE: Global database update
|
||||
print("+++++ Doing global update from PLEX")
|
||||
os.system('sudo python PseudoChannel.py -u')
|
||||
|
||||
|
||||
base_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||
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 = list(filter(lambda x: x.startswith(locations),channel_dirs))
|
||||
|
||||
for channel_dir in channel_dirs:
|
||||
# Step TWO: Go to each folder, export the following information
|
||||
# - Show title, lastEpisodeTitle
|
||||
# - Movie title, lastPlayedDate
|
||||
os.chdir(channel_dir)
|
||||
|
||||
channel_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
||||
print("+++++ Importing from " + db_path)
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
table = conn.cursor()
|
||||
|
||||
|
||||
lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall()
|
||||
lastEpisode_export = list(lastEpisode_export)
|
||||
lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall()
|
||||
lastMovie_export = list(lastMovie_export)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except:
|
||||
print("+++++ Database experiencing errors or hasn't been formed yet; creating fresh one")
|
||||
lastEpisode_export = []
|
||||
lastMovie_export = []
|
||||
|
||||
|
||||
# Step THREE: Delete the previous database, replace with the recently created global one
|
||||
print("+++++ Copying global update to " + db_path)
|
||||
copy2('../pseudo-channel.db','.')
|
||||
|
||||
|
||||
# Step FOUR: Import the previous information we exported previously
|
||||
print("+++++ Exporting to " + db_path)
|
||||
conn = sqlite3.connect(db_path)
|
||||
table = conn.cursor()
|
||||
|
||||
for i in range(0,len(lastEpisode_export)):
|
||||
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
|
||||
table.execute(sql,lastEpisode_export[i])
|
||||
|
||||
for i in range(0,len(lastMovie_export)):
|
||||
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
||||
table.execute(sql,lastMovie_export[i])
|
||||
|
||||
# Step FIVE: Remove any media not in the directories set of commerical archives
|
||||
print("+++++ Trimming database at " + db_path)
|
||||
os.system('sudo python report_MediaFolders.py')
|
||||
local_commercials = open('Commercial_Libraries.txt').read().splitlines()
|
||||
local_movies = open('Movie_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]
|
||||
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]
|
||||
|
||||
# print(db_path)
|
||||
# print(local_commercials)
|
||||
# print(global_commercials["Commercials"])
|
||||
# print(commercial_removal)
|
||||
|
||||
for commercial in commercial_removal:
|
||||
sql = "DELETE FROM commercials WHERE customSectionName=?"
|
||||
table.execute(sql,(commercial,))
|
||||
for movie in movie_removal:
|
||||
sql = "DELETE FROM movies WHERE customSectionName=?"
|
||||
table.execute(sql,(movie,))
|
||||
for tv in tv_removal:
|
||||
sql = "DELETE FROM shows WHERE customSectionName=?"
|
||||
table.execute(sql,(tv,))
|
||||
sql = "DELETE FROM episodes WHERE customSectionName=?"
|
||||
table.execute(sql,(tv,))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
os.chdir('..')
|
||||
|
||||
print("+++++ " + db_path + " complete! Going to next file")
|
||||
|
||||
|
||||
print("+++++ Global update COMPLETE")
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
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.
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
-channels/
|
||||
--plex_token.py
|
||||
--channel_01/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channel_02/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channel_03/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channelup.sh
|
||||
--channeldown.sh
|
||||
--generate-channels-daily-schedule.sh
|
||||
--updatechannels.sh
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
|
||||
```bash
|
||||
-channels/
|
||||
--plex_token.py
|
||||
--channel_01/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channel_02/
|
||||
---pseudo-channel.db
|
||||
---PseudoChannel.py
|
||||
---...etc.
|
||||
--channel_03/
|
||||
---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.
|
||||
@@ -1,150 +1,150 @@
|
||||
#!/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" | 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
|
||||
# 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.
|
||||
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
|
||||
|
||||
filename="./Channels_Sorted.txt"
|
||||
i=0
|
||||
while read -r line
|
||||
do
|
||||
name="$line"
|
||||
CHANNEL_DIR_SORTED[i]=$name
|
||||
i=$((i+1))
|
||||
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
|
||||
# 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[@]}"
|
||||
do
|
||||
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
|
||||
CHANNEL_DIR_NUMBERS[i]=0
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
# 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*//")
|
||||
if [ -z $PREV_CHANNEL ]; then
|
||||
PREV_CHANNEL=0
|
||||
fi
|
||||
|
||||
|
||||
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
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $PREV_CHANNEL ]; then
|
||||
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
if [ $((i-1)) -lt 0 ]; then
|
||||
ARR_LENGTH=(${#CHANNEL_DIR_SORTED[@]})
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$ARR_LENGTH-1]}
|
||||
else
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i-1))]}
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z $NEXT_CHANNEL ]; then
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[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
|
||||
|
||||
#!/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" | 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
|
||||
# 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.
|
||||
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
|
||||
|
||||
filename="./Channels_Sorted.txt"
|
||||
i=0
|
||||
while read -r line
|
||||
do
|
||||
name="$line"
|
||||
CHANNEL_DIR_SORTED[i]=$name
|
||||
i=$((i+1))
|
||||
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
|
||||
# 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[@]}"
|
||||
do
|
||||
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
|
||||
CHANNEL_DIR_NUMBERS[i]=0
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
# 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*//")
|
||||
if [ -z $PREV_CHANNEL ]; then
|
||||
PREV_CHANNEL=0
|
||||
fi
|
||||
|
||||
|
||||
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
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $PREV_CHANNEL ]; then
|
||||
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
if [ $((i-1)) -lt 0 ]; then
|
||||
ARR_LENGTH=(${#CHANNEL_DIR_SORTED[@]})
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$ARR_LENGTH-1]}
|
||||
else
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i-1))]}
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z $NEXT_CHANNEL ]; then
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[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
|
||||
@@ -1,144 +1,144 @@
|
||||
#!/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" | 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
|
||||
# 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.
|
||||
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
|
||||
|
||||
filename="./Channels_Sorted.txt"
|
||||
i=0
|
||||
while read -r line
|
||||
do
|
||||
name="$line"
|
||||
CHANNEL_DIR_SORTED[i]=$name
|
||||
i=$((i+1))
|
||||
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
|
||||
# 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[@]}"
|
||||
do
|
||||
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
|
||||
CHANNEL_DIR_NUMBERS[i]=0
|
||||
fi
|
||||
done
|
||||
|
||||
# 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)
|
||||
|
||||
# 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*//")
|
||||
if [ -z $PREV_CHANNEL ]; then
|
||||
PREV_CHANNEL=0
|
||||
fi
|
||||
|
||||
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
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $PREV_CHANNEL ]; then
|
||||
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
if [ $((i+1)) -gt $((${#CHANNEL_DIR_SORTED[@]}-1)) ]; then
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]}
|
||||
else
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i+1))]}
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z $NEXT_CHANNEL ]; then
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[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
|
||||
|
||||
#!/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" | 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
|
||||
# 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.
|
||||
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
|
||||
|
||||
filename="./Channels_Sorted.txt"
|
||||
i=0
|
||||
while read -r line
|
||||
do
|
||||
name="$line"
|
||||
CHANNEL_DIR_SORTED[i]=$name
|
||||
i=$((i+1))
|
||||
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
|
||||
# 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[@]}"
|
||||
do
|
||||
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
|
||||
CHANNEL_DIR_NUMBERS[i]=0
|
||||
fi
|
||||
done
|
||||
|
||||
# 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)
|
||||
|
||||
# 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*//")
|
||||
if [ -z $PREV_CHANNEL ]; then
|
||||
PREV_CHANNEL=0
|
||||
fi
|
||||
|
||||
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
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $PREV_CHANNEL ]; then
|
||||
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
if [ $((i+1)) -gt $((${#CHANNEL_DIR_SORTED[@]}-1)) ]; then
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[0]}
|
||||
else
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[$((i+1))]}
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z $NEXT_CHANNEL ]; then
|
||||
NEXT_CHANNEL=${CHANNEL_DIR_SORTED[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
|
||||
@@ -1,72 +1,72 @@
|
||||
#!/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"
|
||||
|
||||
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 will update while running.
|
||||
if [ ! -f "$channel/running.pid" ]; then
|
||||
|
||||
echo "+++++ Trying to generate daily schedule: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
|
||||
cd "$channel" && "./generate_daily_sched.sh"
|
||||
|
||||
echo "+++++ Generated: $channel - new schedule."
|
||||
|
||||
sleep 1
|
||||
|
||||
cd ../
|
||||
|
||||
sleep 1
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
#!/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"
|
||||
|
||||
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 will update while running.
|
||||
if [ ! -f "$channel/running.pid" ]; then
|
||||
|
||||
echo "+++++ Trying to generate daily schedule: ""$PYTHON_TO_USE" ./"$channel"/$SCRIPT_TO_EXECUTE_PLUS_ARGS
|
||||
|
||||
cd "$channel" && "./generate_daily_sched.sh"
|
||||
|
||||
echo "+++++ Generated: $channel - new schedule."
|
||||
|
||||
sleep 1
|
||||
|
||||
cd ../
|
||||
|
||||
sleep 1
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,164 +1,164 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Credits: irodimus
|
||||
|
||||
# file: manual.sh
|
||||
|
||||
#----
|
||||
# Simple script to change to specific channel given - triggering start / stop.
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# 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
|
||||
# outside of the pseudo-channel directories:
|
||||
# -------------------
|
||||
# -channels/
|
||||
# --pseudo-channel_1/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_2/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_3/
|
||||
# ---startstop.sh
|
||||
# --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.
|
||||
|
||||
#----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" | 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
|
||||
# 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.
|
||||
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
|
||||
|
||||
filename="./Channels_Sorted.txt"
|
||||
i=0
|
||||
while read -r line
|
||||
do
|
||||
name="$line"
|
||||
CHANNEL_DIR_SORTED[i]=$name
|
||||
i=$((i+1))
|
||||
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
|
||||
# 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[@]}"
|
||||
do
|
||||
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
|
||||
CHANNEL_DIR_NUMBERS[i]=0
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 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 being conducted"
|
||||
|
||||
FIRST_RUN=true
|
||||
|
||||
fi
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then read file, get prevchannel and nextchannel, and trigger next channel:
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
#NEXT_CHANNEL=$1
|
||||
|
||||
#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
|
||||
NEXT_CHANNEL=$(echo $1 | sed "s/^0*//")
|
||||
|
||||
if [ -z $NEXT_CHANNEL ]; then
|
||||
NEXT_CHANNEL=0
|
||||
fi
|
||||
|
||||
PREV_CHANNEL_FOUND=false
|
||||
|
||||
#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") )
|
||||
|
||||
# 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*//")
|
||||
if [ -z $PREV_CHANNEL ]; then
|
||||
PREV_CHANNEL=0
|
||||
fi
|
||||
|
||||
|
||||
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
|
||||
|
||||
echo "+++++ The next channel is: $NEXT_CHANNEL"
|
||||
|
||||
# This is our modified way of searching for the correct directory for the next channel
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $NEXT_CHANNEL ]; then
|
||||
echo "NEXT CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
NEXT_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# This is our modified way of searching for the correct directory for the previous channel
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $PREV_CHANNEL ]; then
|
||||
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Write next channel to previous channel file to reference later
|
||||
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.
|
||||
# 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_DIR" && ./"$SCRIPT_TO_EXECUTE"
|
||||
else
|
||||
|
||||
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
|
||||
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
|
||||
fi
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# Credits: irodimus
|
||||
|
||||
# file: manual.sh
|
||||
|
||||
#----
|
||||
# Simple script to change to specific channel given - triggering start / stop.
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# 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
|
||||
# outside of the pseudo-channel directories:
|
||||
# -------------------
|
||||
# -channels/
|
||||
# --pseudo-channel_1/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_2/
|
||||
# ---startstop.sh
|
||||
# --pseudo-channel_3/
|
||||
# ---startstop.sh
|
||||
# --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.
|
||||
|
||||
#----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" | 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
|
||||
# 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.
|
||||
sudo python ./Channel_Sorter.py ${CHANNEL_DIR_ARR[@]}
|
||||
|
||||
filename="./Channels_Sorted.txt"
|
||||
i=0
|
||||
while read -r line
|
||||
do
|
||||
name="$line"
|
||||
CHANNEL_DIR_SORTED[i]=$name
|
||||
i=$((i+1))
|
||||
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
|
||||
# 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[@]}"
|
||||
do
|
||||
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
|
||||
CHANNEL_DIR_NUMBERS[i]=0
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 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 being conducted"
|
||||
|
||||
FIRST_RUN=true
|
||||
|
||||
fi
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then read file, get prevchannel and nextchannel, and trigger next channel:
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
#NEXT_CHANNEL=$1
|
||||
|
||||
#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
|
||||
NEXT_CHANNEL=$(echo $1 | sed "s/^0*//")
|
||||
|
||||
if [ -z $NEXT_CHANNEL ]; then
|
||||
NEXT_CHANNEL=0
|
||||
fi
|
||||
|
||||
PREV_CHANNEL_FOUND=false
|
||||
|
||||
#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") )
|
||||
|
||||
# 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*//")
|
||||
if [ -z $PREV_CHANNEL ]; then
|
||||
PREV_CHANNEL=0
|
||||
fi
|
||||
|
||||
|
||||
echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"
|
||||
|
||||
echo "+++++ The next channel is: $NEXT_CHANNEL"
|
||||
|
||||
# This is our modified way of searching for the correct directory for the next channel
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $NEXT_CHANNEL ]; then
|
||||
echo "NEXT CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
NEXT_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# This is our modified way of searching for the correct directory for the previous channel
|
||||
for i in "${!CHANNEL_DIR_NUMBERS[@]}"
|
||||
do
|
||||
item_compare=${CHANNEL_DIR_NUMBERS[i]}
|
||||
if [ $item_compare -eq $PREV_CHANNEL ]; then
|
||||
echo "PREVIOUS CHANNEL MATCH: ${CHANNEL_DIR_SORTED[$i]}"
|
||||
PREV_CHANNEL_DIR=${CHANNEL_DIR_SORTED[$i]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Write next channel to previous channel file to reference later
|
||||
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.
|
||||
# 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_DIR" && ./"$SCRIPT_TO_EXECUTE"
|
||||
else
|
||||
|
||||
cd "$OUTPUT_PREV_CHANNEL_PATH"/"$NEXT_CHANNEL_DIR" && ./"$SCRIPT_TO_EXECUTE"
|
||||
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,4 +1,4 @@
|
||||
'''Change the values below, rename this file to "plex_token.py", and move this file just
|
||||
outside of this directory ("../pseudo-channel")'''
|
||||
token = "<your token>"
|
||||
baseurl = 'http://media.home:32400'
|
||||
'''Change the values below, rename this file to "plex_token.py", and move this file just
|
||||
outside of this directory ("../pseudo-channel")'''
|
||||
token = "<your token>"
|
||||
baseurl = 'http://media.home:32400'
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
#!/bin/bash
|
||||
|
||||
# file: stopall.sh
|
||||
|
||||
#----
|
||||
# Simple script to stop any/all channels by killing the processes/deleting the corresponding
|
||||
# .pid files/previouschannel file.
|
||||
#
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# This script needs to be placed on the same level as your channels.
|
||||
#----
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
OUTPUT_PREV_CHANNEL_PATH=.
|
||||
|
||||
OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
|
||||
|
||||
CHANNEL_DIR_INCREMENT_SYMBOL="_"
|
||||
|
||||
PID_FILE_NAME="running.pid"
|
||||
|
||||
# If using 'virtualenv' with python, specify the local virtualenv dir.
|
||||
VIRTUAL_ENV_DIR="env"
|
||||
|
||||
#----END EDITABLE VARS-------
|
||||
FIRST_RUN=false
|
||||
|
||||
# If the prevplaying file exists, delete it
|
||||
if [ -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
|
||||
|
||||
rm "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
|
||||
|
||||
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,
|
||||
# check each channel dir for running .pid file to kill the process/delete the file:
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
NEXT_CHANNEL=""
|
||||
|
||||
PREV_CHANNEL_FOUND=false
|
||||
|
||||
PREV_CHANNEL_DIR=""
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
# Loop through each Channel Dir, if .pid file exists, then kill pid and rm pid file.
|
||||
for channel in "${CHANNEL_DIR_ARR[@]}"
|
||||
do
|
||||
if [ -e "$channel/$PID_FILE_NAME" ]; then
|
||||
|
||||
the_pid=$(<$channel/$PID_FILE_NAME)
|
||||
|
||||
kill "$the_pid"
|
||||
|
||||
COUNTER=1
|
||||
|
||||
while [ -e /proc/$the_pid ]
|
||||
|
||||
do
|
||||
|
||||
echo "+++++ $the_pid is still running"
|
||||
|
||||
sleep .7
|
||||
|
||||
COUNTER=$[$COUNTER +1]
|
||||
|
||||
if [ $COUNTER -eq 20 ]; then
|
||||
|
||||
kill -9 "$the_pid"
|
||||
|
||||
fi
|
||||
|
||||
if [ $COUNTER -eq 40 ]; then
|
||||
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "+++++ $the_pid has finished"
|
||||
|
||||
echo "+++++ Removing $channel/$PID_FILE_NAME"
|
||||
|
||||
rm "$channel/$PID_FILE_NAME"
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "Exiting stop-all-channels.sh script."
|
||||
|
||||
fi
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# file: stopall.sh
|
||||
|
||||
#----
|
||||
# Simple script to stop any/all channels by killing the processes/deleting the corresponding
|
||||
# .pid files/previouschannel file.
|
||||
#
|
||||
#----
|
||||
|
||||
#----
|
||||
# To Use:
|
||||
# This script needs to be placed on the same level as your channels.
|
||||
#----
|
||||
|
||||
#----BEGIN EDITABLE VARS----
|
||||
|
||||
OUTPUT_PREV_CHANNEL_PATH=.
|
||||
|
||||
OUTPUT_PREV_CHANNEL_FILE=".prevplaying"
|
||||
|
||||
CHANNEL_DIR_INCREMENT_SYMBOL="_"
|
||||
|
||||
PID_FILE_NAME="running.pid"
|
||||
|
||||
# If using 'virtualenv' with python, specify the local virtualenv dir.
|
||||
VIRTUAL_ENV_DIR="env"
|
||||
|
||||
#----END EDITABLE VARS-------
|
||||
FIRST_RUN=false
|
||||
|
||||
# If the prevplaying file exists, delete it
|
||||
if [ -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
|
||||
|
||||
rm "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE"
|
||||
|
||||
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,
|
||||
# check each channel dir for running .pid file to kill the process/delete the file:
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then
|
||||
|
||||
NEXT_CHANNEL=""
|
||||
|
||||
PREV_CHANNEL_FOUND=false
|
||||
|
||||
PREV_CHANNEL_DIR=""
|
||||
|
||||
echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."
|
||||
|
||||
# Loop through each Channel Dir, if .pid file exists, then kill pid and rm pid file.
|
||||
for channel in "${CHANNEL_DIR_ARR[@]}"
|
||||
do
|
||||
if [ -e "$channel/$PID_FILE_NAME" ]; then
|
||||
|
||||
the_pid=$(<$channel/$PID_FILE_NAME)
|
||||
|
||||
kill "$the_pid"
|
||||
|
||||
COUNTER=1
|
||||
|
||||
while [ -e /proc/$the_pid ]
|
||||
|
||||
do
|
||||
|
||||
echo "+++++ $the_pid is still running"
|
||||
|
||||
sleep .7
|
||||
|
||||
COUNTER=$[$COUNTER +1]
|
||||
|
||||
if [ $COUNTER -eq 20 ]; then
|
||||
|
||||
kill -9 "$the_pid"
|
||||
|
||||
fi
|
||||
|
||||
if [ $COUNTER -eq 40 ]; then
|
||||
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "+++++ $the_pid has finished"
|
||||
|
||||
echo "+++++ Removing $channel/$PID_FILE_NAME"
|
||||
|
||||
rm "$channel/$PID_FILE_NAME"
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
echo "Exiting stop-all-channels.sh script."
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,77 +1,77 @@
|
||||
#!/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 virtualenv specified & exists at root of project, 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" | sort -t"$CHANNEL_DIR_INCREMENT_SYMBOL" -n) )
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then loop through each channel and run the updates
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 0 ]; 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
|
||||
|
||||
#!/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 virtualenv specified & exists at root of project, 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" | sort -t"$CHANNEL_DIR_INCREMENT_SYMBOL" -n) )
|
||||
|
||||
# If this script see's there are multiple channels,
|
||||
# then loop through each channel and run the updates
|
||||
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 0 ]; 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