-
-
Save aaronclimbs/091232147cca7c43349d3800695be21b to your computer and use it in GitHub Desktop.
// Apologies for the hacky nature of the below - it was just bothering me so I threw this together for myself. | |
// I used this in firefox, just go to the manage subscriptions page in youtube and run it in the developer console. It should work in chrome as well, I forget if there is a different browser function to copy to the clipboard. | |
// After running it, just paste it into a file and save it with a '.ompl' extension. | |
function youTubeToOPML() { | |
output = '<?xml version="1.0" encoding="UTF-8"?>\n<opml version="1.0">\n<head>\n<title>Feed Subscriptions</title>\n</head>\n<body>\n<outline title="Youtube Subscriptions" text="Youtube Subscriptions">'; | |
arrOfATags = [...document.querySelectorAll('a#main-link')]; | |
rss = arrOfATags.forEach(item => { | |
const {href, innerText} = item; | |
const data = { | |
channelID: "", | |
title: "", | |
userID: "", | |
} | |
if (href.includes('channel')) { | |
data.channelID = href.replace("https://www.youtube.com/channel/","https://www.youtube.com/feeds/videos.xml?channel_id="); | |
} else if (href.includes('user')) { | |
data.userID = href.replace('https://www.youtube.com/user/',"https://www.youtube.com/feeds/videos.xml?user="); | |
} | |
data.title = innerText.split('\n')[0]; | |
OPMLLine = `<outline type="rss" xmlUrl="${data.channelID + data.userID}"/>\n`; | |
output += OPMLLine; | |
}) | |
output += '</outline>\n</body>\n</opml>' | |
return output; | |
} | |
copy(youTubeToOPML()); |
Hi! Thanks for the feedback. I had noticed that if the channel defaulted to a 'user' rather than a 'channelID' I could use the https://www.youtube.com/feeds/videos.xml?user={USER}
format for the RSS, rather than the more standard https://www.youtube.com/feeds/videos.xml?channel_id={CHANNEL}
. I hadn't seen more formats for the subscription URLs besides those.
Let me know if I'm missing something, but for the channel you mention above, the RSS feed should be https://www.youtube.com/feeds/videos.xml?user=Ammochannel. This seems to work for me.
That does seem to work, yes. Thanks.
Hmm, after trying again it seems like your script does grab both the 'user' and 'channelID' URLs, however for whatever reason my Feedbro extension for Firefox doesn't import anything after I upload the text file. Which extension are you using?
Looks like it was a problem with how I formatted the OPML output. Try it again please.
Seems to work now--the only nitpick I'd have left is that the feeds aren't sorted into a folder the way they were before. Thanks again for putting this together!
Yep, that's actually what I've been doing since my last comment. The HTML tag needed seems to be. <outline title="Youtube Subscriptions" text="Youtube Subscriptions"> </outline>,
wrapped around the feeds.
After some testing manually adding those tags to the output of your script does seem to work fine, so if you want to add that to your script feel free.
Thanks for throwing this together. One issue I noticed, however--if the URL for a given subscription is a name or nickname instead of the channel ID, your script won't process it correctly. This channel, for instance, defaults to a URL that doesn't contain the channel ID, and is processed by your script like this: , which isn't recognized as a valid RSS feed. This channel's ID is UCfctRLXLbhoTIevEVrpsdIQ (which I found using invidious), meaning that the appropriate RSS URL would be: . Not sure if there's an automated way for you to get the channel ID, but it's something to keep in mind as a limitation of the script.