36 | 37 | GitHub. 38 |
39 | -------------------------------------------------------------------------------- /xExtension-Invidious/extension.php: -------------------------------------------------------------------------------- 1 | registerHook('entry_before_display', array($this, 'embedInvidiousVideo')); 39 | $this->registerTranslates(); 40 | } 41 | 42 | /** 43 | * Initializes the extension configuration, if the user context is available. 44 | * Do not call that in your extensions init() method, it can't be used there. 45 | */ 46 | public function loadConfigValues() 47 | { 48 | if (!class_exists('FreshRSS_Context', false) || null === FreshRSS_Context::$user_conf) { 49 | return; 50 | } 51 | 52 | if (FreshRSS_Context::$user_conf->in_player_width != '') { 53 | $this->width = FreshRSS_Context::$user_conf->in_player_width; 54 | } 55 | if (FreshRSS_Context::$user_conf->in_player_height != '') { 56 | $this->height = FreshRSS_Context::$user_conf->in_player_height; 57 | } 58 | if (FreshRSS_Context::$user_conf->in_show_content != '') { 59 | $this->showContent = (bool)FreshRSS_Context::$user_conf->in_show_content; 60 | } 61 | if (FreshRSS_Context::$user_conf->in_player_instance != '') { 62 | $this->instance = FreshRSS_Context::$user_conf->in_player_instance; 63 | } 64 | } 65 | 66 | /** 67 | * Returns the width in pixel for the invidious player iframe. 68 | * You have to call loadConfigValues() before this one, otherwise you get default values. 69 | * 70 | * @return int 71 | */ 72 | public function getWidth() 73 | { 74 | return $this->width; 75 | } 76 | 77 | /** 78 | * Returns the height in pixel for the invidious player iframe. 79 | * You have to call loadConfigValues() before this one, otherwise you get default values. 80 | * 81 | * @return int 82 | */ 83 | public function getHeight() 84 | { 85 | return $this->height; 86 | } 87 | 88 | /** 89 | * Returns whether this extensions displays the content of the invidious feed. 90 | * You have to call loadConfigValues() before this one, otherwise you get default values. 91 | * 92 | * @return bool 93 | */ 94 | public function isShowContent() 95 | { 96 | return $this->showContent; 97 | } 98 | 99 | /** 100 | * Returns which invidious instance is used by the extension. 101 | * You have to call loadConfigValues() before this one, otherwise you get default values. 102 | * 103 | * @return string 104 | */ 105 | public function getInstance() 106 | { 107 | return $this->instance; 108 | } 109 | 110 | /** 111 | * Inserts the Invidious video iframe into the content of an entry, if the entries link points to a Invidious watch URL. 112 | * 113 | * @param FreshRSS_Entry $entry 114 | * @return mixed 115 | */ 116 | public function embedInvidiousVideo($entry) 117 | { 118 | $link = $entry->link(); 119 | 120 | $html = $this->getIFrameForLink($link); 121 | if ($html === null) { 122 | return $entry; 123 | } 124 | 125 | if ($this->showContent) { 126 | $html .= $entry->content(); 127 | } 128 | 129 | $entry->_content($html); 130 | $in_url = $this->youtubeToInvidious($entry); 131 | $entry->_link($in_url); 132 | return $entry; 133 | } 134 | 135 | /** 136 | * Replaces all YouTube href links for Invidious links in RSS feeds 137 | * 138 | * @param FreshRSS_Feed $feed 139 | * @return $in_url 140 | */ 141 | public function youtubeToInvidious($entry) 142 | { 143 | $yt_url = $entry->link(); 144 | if (stripos($yt_url, 'www.youtube.com') != false) { 145 | $in_url = str_replace('//www.youtube.com/', '//' . $this->instance . '/', $yt_url); 146 | } else if (stripos($yt_url, 'invidio.us') != false) { 147 | $in_url = str_replace('//invidio.us/', '//' . $this->instance . '/', $yt_url); 148 | } 149 | $in_url = str_replace('http://', 'https://', $in_url); 150 | return $in_url; 151 | } 152 | 153 | /** 154 | * Returns an HTML