From 76c4b62d1adf6df7fc523ee982a238a7e9bb635f Mon Sep 17 00:00:00 2001 From: lolcat Date: Tue, 1 Sep 2026 01:31:51 -0400 Subject: [PATCH] handle youtube age gate --- scraper/yt.php | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/scraper/yt.php b/scraper/yt.php index 40c31a4..fcdd8af 100644 --- a/scraper/yt.php +++ b/scraper/yt.php @@ -533,7 +533,8 @@ class yt{ "videoRenderer" => [], "shortsLockupViewModel" => [], "lockupViewModel" => [], // playlists - "continuationItemRenderer" => [] // pagination + "continuationItemRenderer" => [], // pagination + "backgroundPromoRenderer" => [] // errors ]; $search = [ @@ -541,11 +542,50 @@ class yt{ "videoRenderer", "shortsLockupViewModel", "lockupViewModel", - "continuationItemRenderer" + "continuationItemRenderer", + "backgroundPromoRenderer" ]; $this->recursive_search($search, $items, $json); + // check for errors + if(count($items["backgroundPromoRenderer"]) !== 0){ + + foreach($items["backgroundPromoRenderer"] as $popup){ + + if( + isset( + $popup + ["title"] + ["runs"] + ) && + isset( + $popup + ["bodyText"] + ["runs"] + ) + ){ + + $error = + $this->assemble_runs($popup["title"]) . ". " . + $this->assemble_runs($popup["bodyText"]); + + if(str_contains(strtolower($error), "no results found")){ + + // no results + return $out; + } + + // other error + throw new Exception( + "YouTube returned an error: " . + $this->assemble_runs($popup["title"]) . ". " . + $this->assemble_runs($popup["bodyText"]) + ); + } + } + } + // add normal videos foreach($items["videoRenderer"] as $video){