support more urls

This commit is contained in:
Gilles Grandou 2018-08-25 16:31:37 +02:00
parent b078fbde7c
commit a5dd40a8d2

View File

@ -13,8 +13,15 @@ class Youtube_Subscription extends Plugin {
$host->add_hook($host::HOOK_SUBSCRIBE_FEED, $this);
}
// url samples:
// https://www.youtube.com/channel/UCH6rAZUDfVIoVSJjm3vlcnw/featured
// https://www.youtube.com/channel/UCH6rAZUDfVIoVSJjm3vlcnw/videos
// https://www.youtube.com/user/epenser1
// https://www.youtube.com/user/epenser1/videos
// https://www.youtube.com/channel/UC5X4e8ScZI2AFd_vkjSoyoQ
//
function hook_subscribe_feed($contents, $url, $auth_login, $auth_pass) {
if (preg_match("/youtube\.com\/channel\/(UC.*)$/", $url, $matches) === 1) {
if (preg_match("/youtube\.com\/channel\/(UC[^\/]*)(\/.*)?$/", $url, $matches) === 1) {
$channel_id = $matches[1];
$contents = "<html><head><link rel=\"alternate\" type=\"application/atom+xml\" href=\"https://www.youtube.com/feeds/videos.xml?channel_id=$channel_id\" /></head><body></body></html>";
}