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

Script continues playing previous day's schedule after the midnight -g #47

Closed MoeFwacky closed 6 years ago

MoeFwacky commented 6 years ago

I have the config set up to generate a new schedule at 12:01 AM and the first show plays at 12:03, but what has happened the last few days is at 12:03, the show for the previous day plays. I usually have to run the startstop.sh script to get it to kick to the new one. Though today, when I did that, I got this error:

Traceback (most recent call last):
  File "PseudoChannel.py", line 957, in <module>
    trigger_what_should_be_playing_now()
  File "PseudoChannel.py", line 824, in trigger_what_should_be_playing_now
    closest_media = nearest(dates_list, now)
  File "PseudoChannel.py", line 818, in nearest
    return min(items, key=lambda x: abs(x - pivot))
ValueError: min() arg is an empty sequence

I had to run -g manually in order to clear it up.

justinemter commented 6 years ago

So this is tough to debug. I'm going to tell you what it's trying to do where it errored and that might help us narrow in. Right before the app tries to -g a new daily schedule (in your case at 12:01 AM), it quickly saves the previous days' schedule to a json file. Then when it updates the daily schedule it checks that json file to see if anything that was currently playing from the previous day finishes before triggering play() for the next day (which is now the current day). So if Seinfeld started at 11:50 PM, and the app updated at 12:00 AM, it is supposed to not interrupt that one Seinfeld episode until it finishes. This only works if the app was already running. If you are switching channels during this time the moment you stop/start the app (or in this case, the channel) it will disregard the previous days schedule and play what was newly generated for today... so if Seinfeld was playing on Channel 1 like in the previous example, then if you switch to Channel 2 at 12:05 then back to Channel 1 at 12:06, Seinfeld will no longer be playing but only what was newly scheduled. It needs to be rethought out now that we are using multiple channels... Anyway, that being said, maybe we can figure out how that error happened. Did you change the channel during that time? Also, it's important never to change the channel while the app is in -g mode - this is another issue that should be fixed in beta! Ideally "PsuedoChannel" or now, "PseudoCable" or whatever should feel like a real working thing. As of now there are so delicate moving parts only us - who are intimately involved would ever dare use it. haha. I may be wrong.

warrentc3 commented 6 years ago

hey guys, i haven't had a chance to test this out you, but have been following along pseudotv and now this, which is what i've sought after for a long time. what if the calendar structure was based off of day of year and 24hh:mm:ss? Is the media analysis that's stored in the plex db leveraged?

justinemter commented 6 years ago

what if the calendar structure was based off of day of year and 24hh:mm:ss

So here's my issue with this at the moment. One of my original goals was to make the app able to shift scheduled items around so that if there was an hour long episode of something where usually that series only plays ~24 min long episodes, rather than cutting it off by the next scheduled item - it would rather shift that next item back another 30 minutes...and all items after it. So the problem arises where since we want this to work with very little maintenance, it would just generate a daily schedule adjusting/shifting where needed. If the shifting results in episodes or movies ending past the scheduled 24 hour day, then so be it, just as long as it doesn't keep pushing content day after day until the intended daily schedule is completely off... It is possible to create a function to generate an entire year schedule, but the problem is when episodes or movies require shifting, ultimately it will just keep pushing content further and further out. So if my target time to watch the Simpsons is at around 5ish, then I create my schedule to kind of build up to it - taking in account time-shifts, and ideally, if done right, the Simpsons should ordinarily be scheduled for around 5ish. However, if I were to just let the app create a schedule for the entire week, month or year, using this time-shifting logic, it will surely push that scheduled target time of 5ish further and further out until the Simpsons is being scheduled at like 3am. Sorry, I hope that was the question you had, I might have misinterpreted it. Oh, and to summerize the issue, that 'touch time' when the new daily schedule is udpated (at 12:00 AM) is where all this becomes problematic. I supposed a solution is to make sure the user can specify and update time when they are surely not watching it (say 12:00 PM versus AM). I have that configurable, but remember Moe was having issues when changing the time.

Is the media analysis that's stored in the plex db leveraged?

I'm not sure what you mean here. Do you mean am I grabbing content based on what was viewed last according to Plex? I wanted to steer away from that and have the app act separately so that I (and the user) can decide to watch say, s03e04 of Seinfeld in Plex, and that wouldn't interrupt the queue in our channels for Seinfeld.

i haven't had a chance to test this out you, but have been following along pseudotv and now this, which is what i've sought after for a long time.

Cool to hear! And I am grateful for your input (and any future input). Unfortunately the code is almost already 'legacy code' so now we are adding all these features like multi channel, it's making things a little messy - but these features keep getting better and better so I am at a point where I need to just redo it! Anyway, tell me if that makes sense or if you have any suggestions. Also, if you do decided to play with it, use the develop branch. I need to merge! :)

MoeFwacky commented 6 years ago

Yeah, the issue I had with customizing the time was that the schedule would still generate from midnight to midnight. So, if I set mine to 5:00 AM, it would generate a schedule at 5am, but the schedule would still be from midnight to 11:59 instead of 5am to 4:59am.

justinemter commented 6 years ago

Ok cool. I'll try and fix it this week. :)

justinemter commented 6 years ago

So I was just tinkering with this, and I think it may be more of a conceptual issue. I may be wrong but I think you need to plan your schedule to work around "5:00 AM" as being the "touchy" update time... So when it generates the daily schedule all <time> entries will update as usual. So it shouldn't matter if it is 12 - 12 or 5 - 5 as all time entries will update nonetheless.

MoeFwacky commented 6 years ago

I see what you mean. So if 5am is the refresh time, the xml entries should be from 5am to 4:59am and it will treat each day as existing during those times (so if it's tuesday, the entries that are tecnically 1am wednesday should still fall under the tuesday section of the xml) and display on the webpage in the order entered in the xml. I'll work on getting the schedule set up this way. This should also help with the additional channels triggering schedule updates, since it's typically not running at that time (unless I forgot to click it off before heading to bed).

Speaking of remotes, and a bit off topic, I got my new one in with the number buttons. It works the same with openbox, so it's just a matter of having the right scripts in place.

justinemter commented 6 years ago

Speaking of remotes, and a bit off topic, I got my new one in with the number buttons. It works the same with openbox, so it's just a matter of having the right scripts in place.

Sorry I'm late to reply, how do you imagine this working with your new remote? I suppose I can write a script where you could trigger say, channel 2 by executing something like: ./channel.sh 2. Then, if possible using your remote library, setup each specific number to trigger that script followed by the corresponding number. Would that work?

MoeFwacky commented 6 years ago

Yeah that sounds pretty good. What I was thinking for mapping was using the 10 number buttons for channels, the channel up and down for channel up and down and mapping a button to turn it on and off (ideally turning on would launch and take it to the last played channel, but I could make do with an off button and use the number buttons as on buttons for each channel).

Something I'm thinking is that the number button scripts should only turn on, and not off (so if it's already on the channel, do nothing instead of turn off). It may even be good to have the channel scripts only work while it's running, so they don't act as on buttons at all but just change buttons.

Background on the remote. It acts as a USB keyboard. I mapped out what buttons each of them are attached to (most are pretty obvious, like the numbers being actual numbers) and used openbox to set up what buttons trigger what scripts. Something else I'm trying to figure out on my end with it are commands that can interact with my status screen to give visual feedback so that I have a way of knowing that the button press was recognized (especially given my setup's delay between starting the script and starting the media).

The remote also has a keyboard on the back, which I might use the map things like Alt+1, Alt+2, etc to trigger -xml updates and the like. I don't plan on using the keyboard often, but it could be useful for uncommon commands that I don't want to need to ssh in for.