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

Wrong variable in video ID: Error says "video youtube#liveBroadcastListResponse". #92

Open tfabris opened 6 months ago

tfabris commented 6 months ago

Intermittently, when there is some kind of problem with the stream and it has to be bounced or re-created, I sometimes see an error message in the log output that looks similar to this:

2024-05-24 11:21:40   CrowCam Controller - The streamStatus is not active. Value retrieved was: inactive.
2024-05-24 11:21:41   CrowCam Controller - The healthStatus is not good. Value retrieved was: noData.
2024-05-24 11:21:41   CrowCam Controller - The lifeCycleStatus is not good. Value retrieved was: complete.
2024-05-24 11:21:41   CrowCam Controller - The recordingStatus is not good. Value retrieved was: recorded.
2024-05-24 11:21:41   CrowCam Controller - The lifeCycleStatus and recordingStatus indicate that it's time to create a new livestream from scratch. Creating a new livestream now.
2024-05-24 11:21:42   CrowCam Controller - Creating new YouTube Live Broadcast.
2024-05-24 11:21:58   CrowCam Controller - New video is live. Video ID: L06IKYHbC6Q Status: active Key: x80q-nnnn-nnnn-nnnn-nnnn.
2024-05-24 11:22:06   CrowCam Controller - Live stream came back up.
2024-05-24 11:22:28    CrowCam Controller - Error retrieving categoryId from the video youtube#liveBroadcastListResponse - Output was { "error": { "code": 403, "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.", "errors": [ { "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" }}.
2024-05-24 11:22:29    CrowCam Controller - The video youtube#liveBroadcastListResponse titled CrowCam was not found at the top of playlist PL8Fzg-YTf-GbfOHNxAAZEW9dixstuSztl titled CrowCam Archives - Instead the video L06IKYHbC6Q was found in that slot - Fixing the playlist now.

Somehow, in the code, after creating the new video ID. we see that the system has the value youtube#liveBroadcastListResponse in the variable `$thisStreamId which should be containing the video ID instead. This likely means that the code mis-parsed some response from the YouTube API. Check and see if it somehow blindly accepted an errored-out API response (likely a query to liveBroadcast - List) and didn't do enough bullet-proofing on the response.

This appears to be a very similar bug, possibly the same bug, as issue #88 - But I thought I fixed that one with some code changes. Review the changes you made in 88 and see if there's a flaw in your thinking or if perhaps it needs to be improved. For example, at line 1534 we're retrieving $thisStreamId thusly:

thisStreamId=$(echo $liveBroadcastOutput | sed 's/"id"/\'$'\n&/g' | grep -m 1 "id" | cut -d '"' -f4)
LogMessage "dbg" "thisStreamId: $thisStreamId"
if test -z "$thisStreamId"; then safeToFixStreamKey=false; fi

We test to see if the value is empty, but we don't test to ensure that it looks like a YouTube Video ID before pushing onward. I could simply test that and error out if it doesn't match the style of a video ID, but that would be a bandaid on the problem without knowing the root cause.

I'm going to start with the bandaid but then I will add a log entry with the details of the entire $liveBroadcastOutput variable printed to the log and see if I can identify the root cause.

tfabris commented 6 months ago

Checkin 010619b should detect when the variable is the wrong format, and print an error message to the log.

To do:

tfabris commented 6 months ago

Issue could be in the parser, or, it could be that sometimes (intermittently) youTube doesn't put the XML results in pretty print on multiple lines. The log entry contained this:

The liveBroadcastOutput was { "kind": "youtube#liveBroadcastListResponse", "etag": "nnnnnnnnnnnnnnnn", "nextPageToken": "CAUQAA", "pageInfo": { "totalResults": 36, "resultsPerPage": 5 }, "items": [ { "kind": "youtube#liveBroadcast", "etag": "nnnnnnnnnnnnnnnn", "id": "EOPfl7R69mc", "snippet": { "publishedAt": "2024-05-25T20:03:01Z", "channelId": "UCUxIqdJJpXBnjaEy5yq1wZQ", "title": "CrowCam", "description": "Here is a permanent link to the most current live stream: https://www.youtube.com/channel/UCUxIqdJJpXBnjaEy5yq1wZQ/liveVideo history highlights: http://vixyandtony.com/crowcam.html--- Live view of backyard crows and squirrels, Seattle, Washington. The video feed is only live from sunrise to sunset each day, since crows and squirrels are diurnal. The most common species we see at t

The log condenses multiple lines when it prints the log, so I don't know if the liveBroadcastOutput was on multiple lines or not. But I think the behavior indicates that it was indeed on just one line so it grabbed the first variable it found instead of the variable "id" by itself on a line.

To do:

tfabris commented 6 months ago

No, looks like the code already uses sed to split the string. I think it's because the "sed" command intermittently fails to split the string at the "id" string. Wow.