diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-11-23 20:21:59 -0600 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-11-23 20:21:59 -0600 |
commit | c5cf1359762274a17fb139944405c02618996700 (patch) | |
tree | 69e48f19a6d187eccb8cc50740aadf534781a0de /youtube.js | |
parent | a0dad259a6c767487be08afc666dbf2c923a6e25 (diff) |
Fix youtube feeds
Diffstat (limited to 'youtube.js')
-rw-r--r-- | youtube.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/youtube.js b/youtube.js new file mode 100644 index 0000000..0f095e8 --- /dev/null +++ b/youtube.js @@ -0,0 +1,60 @@ +function get_native_playlist_feed(playlistId){ + return `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}` +} + +function get_native_channel_feed(channelId){ + return `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}` +} + +async function get_youtube(url) { + let patternVideo = /youtube.com\/watch\?v=\w+/ + let matchVideo = url.match(patternVideo) + + let patternUser = /youtube.com\/user\/(\w+).*/ + let matchUser = url.match(patternUser) + + let patternChannel = /youtube.com\/channel\/(\w+).*/ + let matchChannel = url.match(patternChannel) + + let patternPlaylist = /youtube.com\/playlist\?list=(\w+)/ + let matchPlaylist = url.match(patternPlaylist) + + if (matchVideo) { + let channel_url = document.querySelector("[role='main'] #channel-name a")["href"] + let matchChannel2 = channel_url.match(patternChannel) + let channelId = matchChannel2[1] + let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+channel+id&c=${channelId}&duration_min=&duration_max=&format=` + let native_url = get_native_channel_feed(channelId) + let feeds = get_all_types(feed_url, "channel").concat([{ type: `native (channel): Rss`, url: native_url }]) + + let patternListInVideo = /youtube.com\/watch\?v=\w+\&list=(\w+)/ + let matchListInVideo = url.match(patternListInVideo) + if(matchListInVideo){ + let playlistId = matchListInVideo[1] + let playlist_feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+playlist+Id&p=${playlistId}&duration_min=&duration_max=&format=` + let native_url = get_native_playlist_feed(playlistId) + let rb_feeds = get_all_types(playlist_feed_url, "playlist") + feeds = feeds.concat(rb_feeds.concat([{ type: `native (playlist): Rss`, url: native_url }])) + } + + return feeds + } + if (matchUser) { + let user = matchUser[1]; + let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+username&u=${user}&duration_min=&duration_max=&format=` + return get_all_types(feed_url) + } + if (matchChannel) { + let channelId = matchChannel[1] + let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+channel+id&c=${channelId}&duration_min=&duration_max=&format=` + return get_all_types(feed_url) + } + if (matchPlaylist) { + let playlistId = matchPlaylist[1] + let native_url = get_native_playlist_feed(playlistId) + let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+playlist+Id&p=${playlistId}&duration_min=&duration_max=&format=` + let rb_feeds = get_all_types(feed_url) + return rb_feeds.concat([{ type: `native: Rss`, url: native_url }]) + } + return [] +} |