Fix youtube shorts thumbnail
This commit is contained in:
		
							parent
							
								
									85e199e550
								
							
						
					
					
						commit
						7edae7fa58
					
				
					 1 changed files with 28 additions and 18 deletions
				
			
		|  | @ -1,23 +1,33 @@ | |||
| <?php | ||||
| class Af_Youtube_Thumbnail extends Plugin { | ||||
|   function about() { | ||||
|     return array(0.1, | ||||
|       "Add the thumbnail for Youtube videos", | ||||
|       "gdott9"); | ||||
|   } | ||||
| 
 | ||||
|   function init($host) { | ||||
|     $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | ||||
|   } | ||||
| 
 | ||||
|   function hook_article_filter($article) { | ||||
|     if(strpos($article["link"], "youtube.com") !== FALSE) { | ||||
|       $video_id = str_replace('https://www.youtube.com/watch?v=', '', $article["link"]); | ||||
|       $article["content"] = '<img src="https://img.youtube.com/vi/'.$video_id.'/hqdefault.jpg" alt="'.$article["title"].'" />'; | ||||
| class Af_Youtube_Thumbnail extends Plugin | ||||
| { | ||||
|     function about() | ||||
|     { | ||||
|         return array(0.1, | ||||
|         "Add the thumbnail for Youtube videos", | ||||
|         "gdott9"); | ||||
|     } | ||||
| 
 | ||||
|     return $article; | ||||
|   } | ||||
|     function init($host) | ||||
|     { | ||||
|         $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | ||||
|     } | ||||
| 
 | ||||
|   function api_version() { return 2; } | ||||
|     function hook_article_filter($article) | ||||
|     { | ||||
|         if (strpos($article["link"], "youtube.com") !== false) { | ||||
|             $video_url_prefix = 'https://www.youtube.com/watch?v='; | ||||
|             $short_url_prefix = 'https://www.youtube.com/shorts/'; | ||||
|             $is_short = substr($article["link"], 0, strlen($short_url_prefix)) === $short_url_prefix; | ||||
|             $video_id = str_replace($is_short ? $short_url_prefix : $video_url_prefix, '', $article["link"]); | ||||
|             $article["content"] = '<img src="https://i.ytimg.com/vi/'.$video_id.'/hqdefault.jpg" alt="'.$article["title"].'" />'; | ||||
|         } | ||||
| 
 | ||||
|         return $article; | ||||
|     } | ||||
| 
 | ||||
|     function api_version() | ||||
|     { | ||||
|         return 2; | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue