justinemter / pseudo-channel

This is a python based cli-app using the python-plex-api to control a plex-client and act like a real TV channel with show scheduling, commercial breaks, movie nights, etc. "Home-Brewed TV Channel(s) for Hackers"
GNU General Public License v3.0
128 stars 18 forks source link

Stop playback with startstop script #45

Closed irodimus closed 6 years ago

irodimus commented 6 years ago

Is it possible to have the playback stop on the client when running the startstop.sh script after using it to start PseudoChannel? I understand the process quits but am not sure why the playback would still need to be running on the client. With resuming playback on start, there is not really a reason to having the media playing as starting PseudoChannel again will just continue the video. Maybe I'm missing something.

justinemter commented 6 years ago

Is it possible to have the playback stop on the client when running the startstop.sh script after using it to start PseudoChannel?

Ahh I see, yes it's possible. It doesn't seem that important though so I haven't implemented it.

MoeFwacky commented 6 years ago

I was thinking of putting in the same request, because with using the remote control to start and stop the script, there's no immediate way to know for sure that it's been shut off short of waiting for the end of the item or using pgrep. Not a priority, but would be a nice QOL addition.

justinemter commented 6 years ago

Ok cool, I just pushed a version to develop that implements this. Man, the play function is so much snappier using my very old minimal laptop versus my raspberry pi... something to think about if you want this to feel more like a real channel... there are beefier raspberry pi alternatives.

justinemter commented 6 years ago

Also, for debugging... I've implemented a debug log that is created in the pseudo-channel dir. It's extremely helpful to open a new terminal, ssh into the controller pseudo-channel dir, and run: tail -f ./pseudo-channel.log. I haven't gone through the app and ported my print statements over entirely, but there is some output there for when running ./startstop.sh so you're not completely blind. Try it out. :)

justinemter commented 6 years ago

Moe, I just added a bash script called channelup.sh in ./bash-scripts dir. I have not tested this with multiple channels yet, but I have tested that it does cycle through properly named dirs, pseudo-channel_1, pseudo-channle_2, etc. and tries to execute the startstop.sh script if it exists. So, in theory, it should work! You just need to cp the file from the bash-scripts dir to where the plex_token.py file is for it to see all the channels & know where to find the channels. There are editable vars but I'd keep it default / get it working as-is before messing with it. Tell me if you need help.

justinemter commented 6 years ago

Ok, I just tested the channelup.sh script and it seems to work well, however, as of now there is no stop... it will just cycle. Also if you mess up you need to delete the new generated .prevchannel file and make sure you delete any existing, running.pid files within each channel dir. You will mess up at first, no problem, just go ahead and delete all those files I mentioned and run the script again. Here are some steps to get the multichannel functionality working quickly for you:

1) Go to your home dir and make a new dir where your channels can live:

% cd ~/ && mkdir ~/channels

2) Copy your original channel over a couple times to create your new channels:

% cp -r ~/pseudo-channel ~/channels/pseudo-channel_1 && cp -r ./pseudo-channel ~/channels/pseudo-channel_2 && cp -r ./pseudo-channel ~/channels/pseudo-channel_3

now you have 3 independent "channels" in the /channels dir (you can skip these commands and just do it however it makes sense to you too)

3) Go to the new ~/channels dir and cp the new channelup.sh script + the old plex_token.py scripts over:

% cp ~/plex_token.py ~/channels && cp ~/pseudo-channel/bash-scripts/channelup.sh ~/channels

4) Now just cd into the ~/channels dir and make the new channelup.sh script executable & run it:

% cd ~/channels && chmod +x ./channelup.sh && ./channelup.sh

Finally to see it change channels, just go into each channel directory and run the -g flag to generate different schedules for each channel. That way you can see it actually switching content:

% cd pseudo-channel_1 && python PseudoChannel.py -g
% cd pseudo-channel_2 && python PseudoChannel.py -g

# ... etc. for each channel to get different schedules going.

It isn't very user-friendly, especially at first so just ask me if you can't get it working. I think you'll be happy with it though. Again, it might be easier to just open up filezilla or whatever ftp program you use and do all of the copying/creatiing channels stuff manually.

MoeFwacky commented 6 years ago

This is pretty great. I moved the running.pid file into the channels/ directory and pointed the configs of each to point to that file. This way, so matter which startstop.sh I run, it will shut it off if running. I've assigned buttons on the remote and I can now flip through channels (in one direction) and turn the script (and playback) on and off. Right now it always turns back to channel 1 when starting up, but that's pretty good for right now/

justinemter commented 6 years ago

I moved the running.pid file into the channels/ directory and pointed the configs of each to point to that file. This way, so matter which startstop.sh I run, it will shut it off if running.

Hmm, this is an interesting idea. I suppose the utility in this - other than having one centralized location for the .pid, is so you can assign numbers to your channel too, like the number 2 triggering channel "_2". Well, that and being able to just run the startstop scripts manually out of order.

I've assigned buttons on the remote and I can now flip through channels (in one direction) and turn the script (and playback) on and off.

That's really cool. I was hoping you would get it working today.

MoeFwacky commented 6 years ago

Yeah, I'm actually eyeballing this remote now, because it has buttons and can be used to control the TV as well (I've got six remotes right now, so I'd like to slim that down). If I get that, I think I may just set up 10 channels.

justinemter commented 6 years ago

...or the megatron

Seriously, though... keep me updated. I'm curious to see how you use the channel (and for bug fixes, etc.)

MoeFwacky commented 6 years ago

Yeah totally. The only thing, as you mentioned, is the delay when using the pi. I removed -m from startstop.sh and it brought the lag time down to about 10-11 seconds. I'm thinking on how I can set up some kind of feedback to indicate that input was received, maybe a countdown page that the status display can switch to for 10 seconds then switching back.

MoeFwacky commented 6 years ago

Here's something that popped up. Don't know if i should create a new issue for this, but it seems that only one of the channels schedules updated for the day. Best I can tell, the generate_daily_sched.sh instances in crontab detected that the script was running so didn't generate new schedules, and the only one that did generate was the channel that was running at the time.

justinemter commented 6 years ago

Oh no! I'll poke around with that. Unfortunately, my pi isn't allowing me to ssh into it! I've tinkered with it, but no luck. It's the tiny one and I don't have a micro hdmi cable to access it plugged into a monitor, so am probably just going to re-flash jessie on it/fresh install everything. I have an older backup of the db on my computer that I can hopefully salvage my queue from. That being said I haven't been able to configure my channels.

justinemter commented 6 years ago

I was thinking, if you found that removing the -m flag speeds up the changing of channels, it also makes sense to go to each channels config and make the controllerServerPath and empty string. When the app runs or when you run -m it should see you aren't trying to run a server and will default to the old html implementation where the html page refreshes every 30 seconds. So you could do something like this:

% ln -s /home/pi/channels/pseudo-channel_1/schedules/ /var/www/html/pseudo-channel_1

Since you already have apache running, this sort of thing - when done to each of your channels should serve up the static html to your controller ip/dir (i.e. http://192.168.1.144/pseudo-channel_1/)

The channels should switch faster, you won't have the python simple http server running and all your channels will have their own schedules served up to their respective directories you create in the apache folder.

MoeFwacky commented 6 years ago

I did set up the symbolic links last night, didn't think to change the config though. I'll do that though to save resources for sure. Right now the delay without -m is about 10 seconds.

MoeFwacky commented 6 years ago

I ran into a weird issue where the channelup and channeldown scripts would only flip between two of the three channels. I manually switched to the third by running its startstop script and it got stuck only recognizing that channel. I deleted the .prevplaying and running.pid files and it went back to flipping between the three, though it's recognizing them in reverse order now.

pi@controller:~/channels $ sudo ./channelup.sh
+++++ There are 3 channels detected.
+++++ It looks like the previous channel was: 3
+++++ Found previous channel, incrementing by 1.
+++++ The next channel is: pseudo-channel_2
justinemter commented 6 years ago

I manually switched to the third by running its startstop script and it got stuck only recognizing that channel.

Hmm, so do you mean that it was working until you manually switched to channel 3? Off the top of my head I'd say that that would be the cause... Without knowing for sure, and assuming that that was the cause, I think there needs to be a "manual.sh" script where you can run something like "./manual.sh 2" to switch to channel 2, so the script updates the ".prevchannel" file with whatever channel you manually switched to. To test that, when you manually switch to a channel, add the channel number to .prevchannel - the go back to channelup / channeldown. Ideally, that should solve it.

MoeFwacky commented 6 years ago

Initially it was working. Then somewhere in between, it started only recognizing the first two channels. Then when I manually switched to channel 3 and ran the up or down scripts, it only recognized channel 3. Though a manual.sh would be useful for when I get the remote with number buttons.

MoeFwacky commented 6 years ago

So it kicked back to just the two channels again. I haven't been flipping back and forth much the last few days, went to cycle through today and it was just hitting the first two again. I'm thinking about adding a few more channels and remapping the controller. Once I do that I'll watch the output and see what happens.

justinemter commented 6 years ago

I have a feeling it might be due to the channeldown.sh script but I need to play with it to confirm. I just got my hdmi adapter for my pi so can get back on this project. I'm going to set it up tomorrow.