Benjamin-Loison / YouTube-operational-API

YouTube operational API works when YouTube Data API v3 fails.
400 stars 50 forks source link

`channels?part=approval` not working sometimes #291

Closed Benjamin-Loison closed 3 months ago

Benjamin-Loison commented 3 months ago

As someone raised this issue on Discord.

56e448faa7be84bb9f8420b50dcb4e94f5d0ff15

Benjamin-Loison commented 3 months ago
YOUTUBE_OPERATIONAL_API_INSTANCE_URL='https://yt.lemnoslife.com'
CHANNEL_IDS=(
    'id=UC0aMaqIs997ggjDs_Q9UYiw'
    'id=UCX6OQ3DkcsbYNE6H8uQQuVA'
    'handle=@korivrc'
    'handle=@evie'
    'id=UCt5USYpzzMCYhkirVQGHwKQ'
)
for channelId in "${CHANNEL_IDS[@]}"
do
    echo $channelId
    curl -s "$YOUTUBE_OPERATIONAL_API_INSTANCE_URL/channels?part=approval&$channelId" | jq .items[0].approval
done

Currently returns:

id=UC0aMaqIs997ggjDs_Q9UYiw
"Official Artist Channel"
id=UCX6OQ3DkcsbYNE6H8uQQuVA
"Verified"
handle=@korivrc
""
handle=@evie
"Verified"
id=UCt5USYpzzMCYhkirVQGHwKQ
""

While should be it seems:

id=UC0aMaqIs997ggjDs_Q9UYiw
"Official Artist Channel"
id=UCX6OQ3DkcsbYNE6H8uQQuVA
"Verified"
handle=@korivrc
"Official Artist Channel"
handle=@evie
"Verified"
id=UCt5USYpzzMCYhkirVQGHwKQ
""
Benjamin-Loison commented 3 months ago
diff --git a/channels.php b/channels.php
index 15ea9fc..070f20d 100644
--- a/channels.php
+++ b/channels.php
@@ -368,8 +368,7 @@

         if ($options['approval']) {
             $result = getJSONFromHTMLForcingLanguage("https://www.youtube.com/channel/$id", true);
-            $badgeTooltipPath = 'contents/twoColumnBrowseResultsRenderer/tabs/0/tabRenderer/content/sectionListRenderer/contents/1/itemSectionRenderer/contents/0/shelfRenderer/content/horizontalListRenderer/items/0/gridVideoRenderer/ownerBadges/0/metadataBadgeRenderer/tooltip';
-            $item['approval'] = doesPathExist($result, $badgeTooltipPath) ? getValue($result, $badgeTooltipPath) : '';
+            $item['approval'] = end(explode(', ', $result['header']['pageHeaderRenderer']['content']['pageHeaderViewModel']['title']['dynamicTextViewModel']['rendererContext']['accessibilityContext']['label']));
         }

         if ($options['snippet']) {

should do the trick but let us make sure that @evie is correctly already working and I am not missing something.