tfabris / CrowCam

A set of Bash scripts to control and maintain a YouTube live cam from a Synology NAS.
GNU General Public License v3.0
4 stars 3 forks source link

Stream keys fail if they start with four base-10 digits #91

Closed tfabris closed 6 months ago

tfabris commented 6 months ago

The crowCam got into a situation today where YouTube showed that there was a scheduled stream waiting to start, but no stream was forthcoming, it just sat there in the Scheduled state all day. Logs looked like this:

2024-04-30 05:45:05 CrowCam Controller - Creating new YouTube Live Broadcast.
2024-04-30 05:45:20 CrowCam Controller - The streamStatus is not active. Value retrieved was: ready.
2024-04-30 05:46:19 CrowCam Controller - Local Synology stream key does not match YouTube stream name/key.
2024-04-30 05:46:19 CrowCam Controller - Local Key: 9470.
2024-04-30 05:46:19 CrowCam Controller - YouTube Key: 9470-rk**-****-****-****.
2024-04-30 05:46:19 CrowCam Controller - Updating local Synology stream name/key to be 9470-rk**-****-****-****.
2024-04-30 05:46:22 CrowCam Controller - The streamStatus is not active. Value retrieved was: ready.
2024-04-30 05:46:22 CrowCam Controller - The healthStatus is not good. Value retrieved was: noData.
2024-04-30 05:46:22 CrowCam Controller - The lifeCycleStatus is not good. Value retrieved was: ready.
2024-04-30 05:46:22 CrowCam Controller - The recordingStatus is not good. Value retrieved was: notRecording.
2024-04-30 05:46:31 CrowCam Controller - The streamStatus is not active. Value retrieved was: ready.
2024-04-30 05:46:31 CrowCam Controller - The healthStatus is not good. Value retrieved was: noData.
2024-04-30 05:46:31 CrowCam Controller - The lifeCycleStatus is not good. Value retrieved was: ready.
2024-04-30 05:46:31 CrowCam Controller - The recordingStatus is not good. Value retrieved was: notRecording.
2024-04-30 05:46:31 CrowCam Controller - Bouncing the YouTube stream for 4 seconds, because the stream was unexpectedly down during the quick test in the main code after having run the Test_Network function.

The above repeated all day.

After the first creation of the Live Broadcast, it did not try to create a new one, it just kept updating the key, but the key is wrong every time, local key is just the first four digits.

Investigating.

tfabris commented 6 months ago

Checked:

I wonder if I need to quote-enclose or escape that key somehow?

NOTE: It's not the "-r" in the key, I tried it at the command line and even if I replaced the key with just numbers, it still failed, and got only the first four digits:

wget -qO- --load-cookies wgetcookies.txt --timeout=10 "http://localhost:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.YoutubeLive&method=Save&version=1&key=1234-1234-1234-1234-1234"

tfabris commented 6 months ago

Fails, gets only the first four digits:

Works:

So it is something to do with the key, but I know not what yet, exactly. Some keys fail others succeed.

Even URL-encoding every single digit in the string (including safe digits) like this, causes only the first four digits to be saved:

tfabris commented 6 months ago

It's got something to do with the fact that the first group of the key is four base-10 digits. For instance, using the API to save this key fails:

But saving this key works:

Note that the issue with saving the key only exists when using the API to save the key. The keys which fail only fail with the WGET api command that I'm using. If I paste the key directly into the Surveillance Station Web UI (into the Live Broadcast widget) then it works.

tfabris commented 6 months ago

I temporarily worked around the problem by hand-updating the key in Surveillance Station, and it worked and the stream started going again. Shortly thereafter, the system decided that it needed to split the stream at midday and created a new live broadcast with a new key, this time the key didn't have four pure decimal digits at the front, so it also worked as expected.

I don't know what this is?

I think the latter is more likely, but it seems to me like the workaround will be the same regardless of the bug's root cause.

To do:

tfabris commented 6 months ago

I have done the following:

To do:

tfabris commented 6 months ago

I got a response from Synology support about my bugreport. They suggested a workaround of putting double quotes around the key, something I hadn't tried. I had already tried single quotes around the key, but that had only partially worked; the full key did save, but it also saved the single quotes into the key itself, thus making the key invalid. I hadn't thought to go forward and try double quotes around the key. Turns out that fixes it.

Though instead of doing double quotes in my script (since other parts of the code which touch that string are already using double quotes as other delimiters), I am using %22 instead, which also works successfully: &key=%221234-1234-1234-1234-1234%22

This should permanently fix the issue. Checkin 1e7904a adds the %22's around the key. I believe this is the true workaround to the bug so that it should never recur.

The prior checkin bcd0859, where it double-checks that the key got saved and creates a new stream if it didn't save correctly, that code is still in there as belt-and-suspenders protection if something else goes wrong with the key. But that code theoretically shouldn't get hit any more except in extreme emergencies. So I don't need to do my other "to do" items from above because the orphaned stream and the additional error messages shouldn't be hit regularly any more.