--- original.php 2022-02-23 21:19:03.372266308 +0000 +++ patch.php 2022-02-24 01:57:21.075723211 +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,25 @@ return array($result, $extra); } - + // Get YouTube video info with Invidious API + private function GetYoutubeVideo($videoid) { + $result = array(); + $result["screen_name"] = "Invidious"; + $result["text"] = "https://" . phirce::INVIDIOUS_INSTANCE . "/watch?v=" . $videoid; + // Only get the title and author of the video + // TODO: you know what + /* + $resp = file_get_contents('http://' . 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: INSTANCE: " . phirce::INVIDIOUS_INSTANCE . " VIDEO_ID: " . $videoid . " RESP: " . $resp; + } + 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 +880,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.