pub / yt2html

Fetches Youtube content via RSS and provides a chronological timeline
git clone https://src.jayvii.de/pub/yt2html.git
Home | Log | Files | Exports | Refs | README | RSS

commit 2157eabab3c42cd59bf1124473818aa0b5d29fac
parent 16eb2d3e94dc723ea75853193d812b5e6f3db05f
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Tue, 10 Nov 2026 19:04:24 +0100

fix: handle errors on fetch

Diffstat:
Massets/js/yt.js | 12+++++++++---
Mlib/fetch_feed.php | 2+-
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/assets/js/yt.js b/assets/js/yt.js @@ -149,7 +149,7 @@ function create_video_box(data) { } -function fetch_and_insert_yt(channel) { +async function fetch_and_insert_yt(channel) { // gather feed information from API endpoint const videos_raw = await fetch('/lib/fetch_feed.php?channel=' + channel); @@ -157,7 +157,13 @@ function fetch_and_insert_yt(channel) { var videos = await videos_raw.json(); // Update Channel List Name - document.querySelector("#channellist_" + channel).innerText = videos[0]["author"]; + if (videos.length > 0) { + document.querySelector("#channellist_" + channel).innerText = videos[0]["author"]; + } else { + document.querySelector("#channellist_" + channel).innerHTML = "<mark>ERROR</mark>"; + document.querySelector("#channellist_" + channel).classList.add("error") + return null; // exit immediately + } // create and insert each video into the feed for (let i=0; i < videos.length; i++) { @@ -180,5 +186,5 @@ function fetch_and_insert_yt(channel) { } // Update loaded channels global - loaded_channels.append(channel); + loaded_channels.push(channel); } diff --git a/lib/fetch_feed.php b/lib/fetch_feed.php @@ -1,7 +1,7 @@ <?php /* Fetch XML Feed Channel */ -// $channel = $_GET["channel"]; +$channel = $_GET["channel"]; $channel_xml = file( "https://www.youtube.com/feeds/videos.xml?channel_id=" . $channel );