--- original.php 2022-02-23 21:19:03.372266308 +0000 +++ patch.php 2022-02-24 00:51:21.305693273 +0000 @@ -56,6 +56,9 @@ const MAGENTABG = "\033[45m"; const CYANBG = "\033[46m"; + // Set this to the domain of your preferred Invidious instance + const INVIDIOUS_INSTANCE = "yewtu.be"; + public function __construct($nick, $pass, $ident, $realname, $host, $port, $chan, $tmppath, $useragent, $logpath, $log, $arcpath, $archive, $modpath) { @@ -842,7 +845,20 @@ return array($result, $extra); } - + // Get YouTube video info with Invidious API + private function GetYoutubeVideo($videoid) { + $result = array(); + // Only get the title and author of the video + $resp = file_get_contents('https://' . phirce::INVIDIOUS_INSTANCE . '/api/v1/videos/' . $videoid . '?fields=title,author'); + if ($resp && ($json = json_decode($resp))){ + $result['text'] = $json->title; + $result['screen_name'] = $json->author; + }else{ + $result['error'] = "An error has occured: https://" . phirce::INVIDIOUS_INSTANCE . "/api/v1/videos/" . $videoid . "?fields=title,author"; + } + return $result; + } + private function ProcessURL($url, $archive, $shorten, $depth = 0) { if(isset($this->url_seen[$url]) && $this->url_seen[$url] > $this->line_count-phirce::HISTORY_SCREENFUL) { echo "Ignoring $url which was processed ", $this->line_count - $this->url_seen[$url], " lines ago\r\n"; @@ -859,6 +875,10 @@ else if(preg_match('%^https?://identi\.ca/notice/%', $url, $dent)){ return array($this->GetDent($url), array()); } + // Special case for Youtube + else if(preg_match('%^https?://youtube\.com/watch\?v=([\w-]{11})%', $url, $youtubeid)){ + return array($this->GetYoutubeVideo($youtubeid[1]), array()); + } // Special case for joindiaspora.com // joindiaspora.com changes content-type to text/html // based on user agent, even if the content is actually xml.