commit 886e30cedb79ef50998c8132822c2a615432e633
parent 55e389c24cee059be9b2cb93c65dbd1effcc6c68
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Mon, 22 Sep 2025 18:37:00 +0200
fix: fetch stream descriptions properly again
Twitch changed the way they return stream
descriptions to webbrowsers. This is not handled
entirely in Javascript. However, for the
Google-Bot, twitch makes an exception and returns
the stream description in HTML, just like before.
Hence, if we lie about who we are, twitch returns
the desired output.
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/lib/fetch_description.php b/lib/fetch_description.php
@@ -3,8 +3,22 @@
/* Build URL to fetch the description from */
$url = "https://www.twitch.tv/" . $_GET["stream"];
+/* Set useragent via URL context: Lie about who we are!
+ * Twitch.tv does not return the proper description to browsers anymore
+ * However, it does return the proper description to Google's crawler...
+ */
+$opts = array(
+ "http" => array(
+ "method" => "GET",
+ "header" => array(
+ "User-Agent: " . "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
+ )
+ )
+);
+$context = stream_context_create($opts);
+
/* Fetch HTML meta data (up until body starts) */
-$handle = fopen($url, "r");
+$handle = fopen($url, "r", false, $context);
if ($handle) {
$html = stream_get_line($handle, 0, "<body>");
fclose($handle);