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

Orphaned video was created due to YouTube throwing an unexpected authentication error. #93

Open tfabris opened 4 months ago

tfabris commented 4 months ago

An issue with VideoID lsx7QDXooWU occurred on 2024-06-28. The video stream for that video was created under normal circumstances: The midday stream split came up as normal, and it created a new video like it does every day. However, this time, during part of the process, YouTube threw an authentication error unexpectedly. Other parts of the process seemed to have no trouble with the authentication up until that point, so it's not understood why there would have been an authentication problem at this point in the code.

The authentication failure resulted in a video waiting for a stream which never came. Additionally, the video had an incorrect CategoryID which the code cleaned up later during its regular fixing process. Still, the video in question was left orphaned, as an "upcoming" video which was waiting for a stream which never came.

Log messages preceding the error looked normal:

2024-06-27 13:09:29  CrowCam Controller - Current video length 08:04 exceeds maximum of 08:03, splitting stream.
2024-06-27 13:09:43  CrowCam Controller - Creating new YouTube Live Broadcast.

Three seconds later, the error occurred at CrowCamHelperFunctions.sh line 1568:

2024-06-27 13:09:46  CrowCam Controller - Error binding to broadcast. Output was 
{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [
      {
        "message": "Login Required.",
        "domain": "global",
        "reason": "required",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "CREDENTIALS_MISSING",
        "domain": "googleapis.com",
        "metadata": {
          "method": "youtube.api.v3.V3DataLiveBroadcastService.Bind",
          "service": "youtube.googleapis.com"
        }
      }
    ]
  }
}

Then it tried to fix up the categoryID after that:

2024-06-27 13:10:42  CrowCam Controller - The categoryId of the video lsx7QDXooWU titled CrowCam was 24 - This does not match the desired categoryId of 15 - Fixing the categoryId now.
2024-06-27 13:10:43  CrowCam Controller - CategoryId set to 15 on the video lsx7QDXooWU.

However since it never bound to the broadcast, the stream never worked and we got subsequent errors about the playlist and other things:

2024-06-27 13:10:44  CrowCam Controller - The video lsx7QDXooWU titled CrowCam was not found at the top of playlist PL8Fzg-YTf-GbfOHNxAAZEW9dixstuSztl titled CrowCam Archives - Instead the video d22EqUucakU was found in that slot - Fixing the playlist now.
2024-06-27 13:10:45  CrowCam Controller - Video lsx7QDXooWU added to playlist CrowCam Archives.
2024-06-27 13:10:48  CrowCam Controller - Thumbnail uploaded.
2024-06-27 13:10:51  CrowCam Controller - The lifeCycleStatus is not good. Value retrieved was: created.
2024-06-27 13:10:51  CrowCam Controller - The recordingStatus is not good. Value retrieved was: notRecording.

A new video was created which succeeded at all of its creation and streaming steps, leaving the orphaned lsx7QDXooWU video behind.

There is an additional bug, and I have created issue #94 to cover this secondary bug: After all of the above has occurred, the CrowCamCleanup routine keeps trying to deal with the orphaned video and repeats the cache miss in the log infinitely.