Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Merging develop and tagging another release - almost alpha.
  • Loading branch information
Justin Emter committed Sep 17, 2017
2 parents e6ee453 + 091dcdd commit 7a0f832
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 28 deletions.
27 changes: 18 additions & 9 deletions PseudoChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,15 @@ def generate_daily_schedule(self):
print "++++ NOT strict-time: {}".format(str(entry.title).encode(sys.stdout.encoding, errors='replace'))
except:
pass
new_starttime = self.calculate_start_time(
previous_episode.end_time,
entry.natural_start_time,
previous_episode.time_shift,
previous_episode.overlap_max
)
try:
new_starttime = self.calculate_start_time(
previous_episode.end_time,
entry.natural_start_time,
previous_episode.time_shift,
""
)
except:
print("Error in calculate_start_time")
print "++++ New start time:", new_starttime
entry.start_time = datetime.datetime.strptime(new_starttime, self.APP_TIME_FORMAT_STR).strftime('%I:%M:%S %p')
entry.end_time = self.get_end_time_from_duration(entry.start_time, entry.duration)
Expand All @@ -530,7 +533,7 @@ def generate_daily_schedule(self):
else:
self.db.add_media_to_daily_schedule(entry)
previous_episode = entry
self.make_xml_schedule()
#self.make_xml_schedule()

def run_commercial_injection(self):

Expand Down Expand Up @@ -729,7 +732,10 @@ def exit_app(self):
if args.google_calendar:
pseudo_channel.update_schedule_from_google_calendar()
if args.generate_schedule:
pseudo_channel.generate_daily_schedule()
try:
pseudo_channel.generate_daily_schedule()
except:
print("----- Recieved error when running generate_daily_schedule()")
if args.show_clients:
pseudo_channel.show_clients()
if args.show_schedule:
Expand Down Expand Up @@ -878,7 +884,10 @@ def go_generate_daily_sched():
pseudo_channel.save_daily_schedule_as_json()

schedule.clear('daily-tasks')
pseudo_channel.generate_daily_schedule()
try:
pseudo_channel.generate_daily_schedule()
except:
print("----- Recieved error when running generate_daily_schedule()")
generate_memory_schedule(pseudo_channel.db.get_daily_schedule(), True)

schedule.every().day.at(daily_update_time).do(
Expand Down
13 changes: 0 additions & 13 deletions bash-scripts/generate-channels-daily-schedules.sh

This file was deleted.

35 changes: 35 additions & 0 deletions multi-channel-bash-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +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_1/
---pseudo-channel.db
---PseudoChannel.py
---...etc.
--channel_2/
---pseudo-channel.db
---PseudoChannel.py
---...etc.
--channel_3/
---pseudo-channel.db
---PseudoChannel.py
---...etc.
--channelup.sh
--channeldown.sh
--generate-channels-daily-schedule.sh
--updatechannels.sh
```

*Note: this functionality is still being tweaked as are the bash scripts so only attempt this implementation if you are somewhat confident to tinker with bash/crontabs, etc. Or feel free to contact us at github or the discord chat room dedicated to PseudoChannel.tv. Just check the repo for more info.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CHANNEL_DIR_INCREMENT_SYMBOL="_"
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") )
CHANNEL_DIR_ARR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL"'[[:digit:]]*' -printf "%P\n") )

# If the previous channel txt file doesn't exist already create it (first run?)
if [ ! -e "$OUTPUT_PREV_CHANNEL_PATH/$OUTPUT_PREV_CHANNEL_FILE" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ 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") )
CHANNEL_DIR_ARR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL"'[[:digit:]]*' -printf "%P\n") )

# If this script see's there are multiple channels,
# then read file, get prevchannel, increment, and trigger next channel:
Expand Down
72 changes: 72 additions & 0 deletions multi-channel-bash-scripts/generate-channels-daily-schedules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +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") )

# 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
99 changes: 99 additions & 0 deletions multi-channel-bash-scripts/manual.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/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") )

# 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 and nextchannel, and trigger next channel:
if [ "${#CHANNEL_DIR_ARR[@]}" -gt 1 ]; then

NEXT_CHANNEL=$1

NEXT_CHANNEL_DIR=( $(find . -maxdepth 1 -type d -name '*'"$CHANNEL_DIR_INCREMENT_SYMBOL""$NEXT_CHANNEL" -printf "%P\n") )

PREV_CHANNEL_FOUND=false

echo "+++++ There are ${#CHANNEL_DIR_ARR[@]} channels detected."

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") )

echo "+++++ It looks like the previous channel was: $PREV_CHANNEL"

echo "+++++ The next channel is: $NEXT_CHANNEL"

# 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
Loading

0 comments on commit 7a0f832

Please sign in to comment.