diff --git a/NEWS.md b/NEWS.md index 5075c92951..2f1e6c175b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ - Added option `reading_speed_wpm` for showing estimated reading time. ([#1232](https://github.com/fossar/selfoss/pull/1232)) - Search query is now part of URL. ([#1216](https://github.com/fossar/selfoss/pull/1216)) - Search will be carried out using regular expressions when the search query is wrapped in forward slashes, e.g. `/regex/`. The expression syntax is database specific. ([#1205](https://github.com/fossar/selfoss/pull/1205)) +- YouTube spout now supports following playlists. ([#1260](https://github.com/fossar/selfoss/pull/1260)) ### Bug fixes - Reddit spout allows wider range of URLs, including absolute URLs and searches ([#1033](https://github.com/fossar/selfoss/pull/1033)) diff --git a/docs/api-description.json b/docs/api-description.json index a6f5a995c7..2ce1841a3a 100644 --- a/docs/api-description.json +++ b/docs/api-description.json @@ -1096,7 +1096,7 @@ "type": "string" }, "channel": { - "description": "Channel in YouTube spout", + "description": "YouTube URL or user name for YouTube spout", "type": "string" } } diff --git a/src/spouts/youtube/youtube.php b/src/spouts/youtube/youtube.php index de396fec09..18bc25d103 100644 --- a/src/spouts/youtube/youtube.php +++ b/src/spouts/youtube/youtube.php @@ -12,15 +12,15 @@ */ class youtube extends \spouts\rss\feed { /** @var string name of source */ - public $name = 'YouTube: channel'; + public $name = 'YouTube'; /** @var string description of this source type */ - public $description = 'Fetch posts from a YouTube channel.'; + public $description = 'Follow videos from a YouTube channel or a playlist.'; /** @var array configurable parameters */ public $params = [ 'channel' => [ - 'title' => 'Channel', + 'title' => 'URL or username', 'type' => 'text', 'default' => '', 'required' => true, @@ -34,25 +34,25 @@ public function load(array $params) { } public function getXmlUrl(array $params) { - $channel = $params['channel']; - if (preg_match('(^https?://www.youtube.com/channel/([a-zA-Z0-9_-]+)$)', $params['channel'], $matched)) { - $channel = $matched[1]; - $channel_type = 'channel_id'; - } elseif (preg_match('(^https?://www.youtube.com/user/([a-zA-Z0-9_]+)$)', $params['channel'], $matched)) { - $channel = $matched[1]; - $channel_type = 'username'; - } elseif (preg_match('(^https?://www.youtube.com/([a-zA-Z0-9_]+)$)', $params['channel'], $matched)) { - $channel = $matched[1]; - $channel_type = 'username'; + $urlOrUsername = $params['channel']; + if (preg_match('(^https?://www.youtube.com/channel/([a-zA-Z0-9_-]+)$)', $urlOrUsername, $matched)) { + $id = $matched[1]; + $feed_type = 'channel_id'; + } elseif (preg_match('(^https?://www.youtube.com/user/([a-zA-Z0-9_]+)$)', $urlOrUsername, $matched)) { + $id = $matched[1]; + $feed_type = 'user'; + } elseif (preg_match('(^https?://www.youtube.com/([a-zA-Z0-9_]+)$)', $urlOrUsername, $matched)) { + $id = $matched[1]; + $feed_type = 'user'; + } elseif (preg_match('(^https?://www.youtube.com/playlist\?list=([a-zA-Z0-9_]+)$)', $urlOrUsername, $matched)) { + $id = $matched[1]; + $feed_type = 'playlist_id'; } else { - $channel_type = 'username'; + $id = $urlOrUsername; + $feed_type = 'user'; } - if ($channel_type === 'username') { - return 'https://www.youtube.com/feeds/videos.xml?user=' . $channel; - } else { - return 'https://www.youtube.com/feeds/videos.xml?channel_id=' . $channel; - } + return 'https://www.youtube.com/feeds/videos.xml?' . $feed_type . '=' . $id; } public function getThumbnail() { diff --git a/tests/Spouts/YouTubeTest.php b/tests/Spouts/YouTubeTest.php index a6c53e9ed4..a2f624e440 100644 --- a/tests/Spouts/YouTubeTest.php +++ b/tests/Spouts/YouTubeTest.php @@ -96,6 +96,11 @@ public function dataProvider(): array { 'feedTitle' => 'Zogg from Betelgeuse', 'firstItemTitle' => 'Earthlings 101 - Channel Ad', ], + [ + 'url' => 'https://www.youtube.com/playlist?list=PLKhDkilF5o6_pFucn5JHd6xy7muHLK6pS', + 'feedTitle' => 'BeeKeeping', + 'firstItemTitle' => 'Year of BeeKeeping Episode 15, Finding Queen', + ], ]; } } diff --git a/tests/Spouts/resources/YouTube/https___www.youtube.com_playlist_list_PLKhDkilF5o6_pFucn5JHd6xy7muHLK6pS.xml b/tests/Spouts/resources/YouTube/https___www.youtube.com_playlist_list_PLKhDkilF5o6_pFucn5JHd6xy7muHLK6pS.xml new file mode 100644 index 0000000000..cd8674b1af --- /dev/null +++ b/tests/Spouts/resources/YouTube/https___www.youtube.com_playlist_list_PLKhDkilF5o6_pFucn5JHd6xy7muHLK6pS.xml @@ -0,0 +1,372 @@ + + + + yt:playlist:PLKhDkilF5o6_pFucn5JHd6xy7muHLK6pS + PLKhDkilF5o6_pFucn5JHd6xy7muHLK6pS + UCu6mSoMNzHQiBIOCkHUa2Aw + BeeKeeping + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-09T03:46:37+00:00 + + yt:video:w79-iEUhI1I + w79-iEUhI1I + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 1 + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-03T08:21:13+00:00 + 2021-04-18T07:03:33+00:00 + + Year of BeeKeeping Episode 1 + + + As described in the video I am starting a project where I take a camera every time I work on bee stuff so you can see what its like to be a bee keeper and learn as if you where doing it yourself, or at least closer to that than just reading about it or taking a class where you are hit with a huge amount of information all at once and then promptly forget it. + I do know quite a lot but I don't claim to know everything and I guarantee that I will be learning things even as I am filming but isn't that part of the fun? + I want to be very honest so I will do minimal editing and so probably some of the time the videos will be boring or rough; but I hope to get better as I go. + +for the year I am thinking March 1st 2013 (day this video was made) to March 1st 2014 + +if you have any suggestions I am always open to trying new things or just helping facilitate experiments, so please leave comments. + + + + + + + + yt:video:CfuQXa5rUP0 + CfuQXa5rUP0 + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 2 Building New Hives + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-03T10:29:54+00:00 + 2021-03-26T09:38:12+00:00 + + Year of BeeKeeping Episode 2 Building New Hives + + + A Beekeeper should have some wood working skills as... well bees like to live in wood. + +wow 22 minutes I better make that my rough time limit. I can already tell these episodes will have very variable length. + + + + + + + + yt:video:9Cd7IjdMpdI + 9Cd7IjdMpdI + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 3 Box Style Hive + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-03T12:22:35+00:00 + 2021-03-31T02:32:50+00:00 + + Year of BeeKeeping Episode 3 Box Style Hive + + + I really should not have opened the hive with the temperature bellow 40 degrees but I had to check on them and you cant always visit in good whether. besides I only got stung on my jacket ( the dark color attracts stings more than my pale skin) and I am not really counting that. I will keep a running total of the stings I receive to my body over the year. (I have never bothered counting and I am curious) + + + + + + + + yt:video:1MS6_-nveOA + 1MS6_-nveOA + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 4 Winter Loss + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-08T02:40:27+00:00 + 2021-03-30T08:40:01+00:00 + + Year of BeeKeeping Episode 4 Winter Loss + + + Unfortunately despite my efforts the Westminster bees did not make it through the winter. but no worries I have a plan bee. + + + + + + + + yt:video:lLJb-whedH4 + lLJb-whedH4 + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 5 First Full Inspection of the Season + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-11T06:56:04+00:00 + 2021-04-01T22:54:19+00:00 + + Year of BeeKeeping Episode 5 First Full Inspection of the Season + + + I managed to talk my sister into helping film, as I do a seasons first inspection of my strongest hive. + + + + + + + + yt:video:ghjNKB2eLXo + ghjNKB2eLXo + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 6 Slight Change of Plans + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-11T21:08:57+00:00 + 2021-03-29T13:21:20+00:00 + + Year of BeeKeeping Episode 6 Slight Change of Plans + + + the box hive hasn't quite come out of hibernation so i have to change my plans slightly. + + + + + + + + yt:video:cYlabYFg-pQ + cYlabYFg-pQ + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 7, I Need Drones + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-14T18:20:21+00:00 + 2021-03-30T12:28:17+00:00 + + Year of BeeKeeping Episode 7, I Need Drones + + + wherein I put extra drone comb into the hive to stimulate drone production. + + + + + + + + yt:video:GkLo2zxAxJo + GkLo2zxAxJo + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 8, Cleaning Hive for New Bees + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-15T03:18:34+00:00 + 2021-03-29T20:28:37+00:00 + + Year of BeeKeeping Episode 8, Cleaning Hive for New Bees + + + I cleaned the hive and replaced the screen in preparation for new bees. + + + + + + + + yt:video:y7_4Ze7WKC8 + y7_4Ze7WKC8 + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 9, Fixing vandalised hive + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-19T20:31:11+00:00 + 2021-03-28T01:48:34+00:00 + + Year of BeeKeeping Episode 9, Fixing vandalised hive + + + More proof that cold weather is not what kills bees. turns out the hive was open like that for most of the winter and the bees are just fine. + + + + + + + + yt:video:pJnIZG4Vvpw + pJnIZG4Vvpw + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 10, Compressing Conony to One Box + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-19T21:16:56+00:00 + 2021-03-26T13:29:51+00:00 + + Year of BeeKeeping Episode 10, Compressing Conony to One Box + + + Unfortunately they have somehow lost their queen and are not building back up after the winter so I compress the hive to a more manageable size. + + + + + + + + yt:video:sDELEmBQLGw + sDELEmBQLGw + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 11, Cheaking on Drone Production + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-19T22:48:59+00:00 + 2021-03-27T08:04:39+00:00 + + Year of BeeKeeping Episode 11, Cheaking on Drone Production + + + The bees have started bringing food to the hive and are on track for me to split them soon. + + + + + + + + yt:video:fMZyU126NnA + fMZyU126NnA + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 12, Combining 2 Hives to Make One + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-20T00:45:00+00:00 + 2021-03-31T19:50:55+00:00 + + Year of BeeKeeping Episode 12, Combining 2 Hives to Make One + + + I combine my queen-less colony with the colony that survived winter with no lid. + + + +10 + + + + + + + + yt:video:6EKp0dXl5QU + 6EKp0dXl5QU + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 13, Start Making Queens + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-26T02:37:35+00:00 + 2021-03-27T03:57:54+00:00 + + Year of BeeKeeping Episode 13, Start Making Queens + + + I make queen cups, make a nuc and graft larva to start the queen making process. it ended up kinda long... I guess I could have cut out the the boring bits but then you wouldn't get my funny concentration expressions. + + + + + + + + yt:video:IzNMmfyIRxg + IzNMmfyIRxg + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 14, Building 4 More Nucs + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-26T02:57:42+00:00 + 2021-03-27T20:48:44+00:00 + + Year of BeeKeeping Episode 14, Building 4 More Nucs + + + I build a few more nuc boxes to take on the extra packages of bees I ordered so I have more time to build full sized hives. + + + + + + + + yt:video:0dxi9ACUMh4 + 0dxi9ACUMh4 + UCu6mSoMNzHQiBIOCkHUa2Aw + Year of BeeKeeping Episode 15, Finding Queen + + + Cody'sLab + https://www.youtube.com/channel/UCu6mSoMNzHQiBIOCkHUa2Aw + + 2013-03-27T00:08:21+00:00 + 2021-04-01T22:06:05+00:00 + + Year of BeeKeeping Episode 15, Finding Queen + + + In this episode I find the queen, move her to a nuc box for transport, and put the queen cells I made into the now queenless hive. + +this video originally was over an hour and I cut out half so... I actually should do that more. + + + + + + +