Skip to content

Instantly share code, notes, and snippets.

@jeb5
Last active April 16, 2024 18:30
Show Gist options
  • Star 64 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jeb5/da22862e469dea21e873acabb562f638 to your computer and use it in GitHub Desktop.
Save jeb5/da22862e469dea21e873acabb562f638 to your computer and use it in GitHub Desktop.
Youtube Subscriptions to RSS/OPML
javascript:(function()%7Bconst%20e%3D%5B...document.querySelectorAll(%22%23main-link.channel-link%22)%5D.map((e%3D%3E%7Bconst%5B%2Ct%2Cn%5D%3De.href.match(%22%2F((%3F%3Auser)%7C(%3F%3Achannel))%2F(.*)%24%22)%3Breturn%5B%22https%3A%2F%2Fwww.youtube.com%2Ffeeds%2Fvideos.xml%3F%22%2B(%22user%22%3D%3D%3Dt%3F%22user%3D%22%3A%22channel_id%3D%22)%2Bn%2Ce.querySelector(%22yt-formatted-string.ytd-channel-name%22).innerText%5D%7D))%3Bif(0%3D%3De.length)alert(%22Couldn't%20find%20any%20subscriptions%22)%3Belse%7Bconsole.log(e.map(((%5Be%2Ct%5D)%3D%3Ee)).join(%22%5Cn%22))%3Blet%20t%3D%60%3Copml%20version%3D%221.0%22%3E%3Chead%3E%3Ctitle%3EYouTube%20Subscriptions%20as%20RSS%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E%3Coutline%20text%3D%22YouTube%20Subscriptions%22%20title%3D%22YouTube%20Subscriptions%22%3E%3C%2Foutline%3E%24%7Be.map(((%5Be%2Ct%5D)%3D%3E%60%3Coutline%20type%3D%22rss%22%20text%3D%22%24%7Bt%7D%22%20title%3D%22%24%7Bt%7D%22%20xmlUrl%3D%22%24%7Be%7D%22%2F%3E%60)).join(%22%22)%7D%3C%2Foutline%3E%3C%2Fbody%3E%3C%2Fopml%3E%60%3Bconst%20n%3Dnew%20Blob(%5Bt%5D%2C%7Btype%3A%22text%2Fplain%22%7D)%2Co%3Dwindow.URL.createObjectURL(n)%2Cl%3Ddocument.createElement(%22a%22)%3Bl.setAttribute(%22download%22%2C%22youtube_subs.opml%22)%2Cl.setAttribute(%22href%22%2Co)%2Cl.dataset.downloadurl%3D%60text%2Fplain%3Ayoutube_subs.opml%3A%24%7Bo%7D%60%2Cl.click()%7D%7D)()%3B
const channels = [...document.querySelectorAll("#main-link.channel-link")].map(e => {
const [, a, b] = e.href.match("/((?:user)|(?:channel))/(.*)$");
const feed = "https://www.youtube.com/feeds/videos.xml?" + (a === "user" ? "user=" : "channel_id=") + b;
const channelName = e.querySelector("yt-formatted-string.ytd-channel-name").innerText;
return [feed, channelName];
});
if (channels.length == 0) {
alert("Couldn't find any subscriptions");
} else {
console.log(channels.map(([feed, _]) => feed).join("\n"));
let opmlText = `<opml version="1.0"><head><title>YouTube Subscriptions as RSS</title></head><body><outline text="YouTube Subscriptions" title="YouTube Subscriptions"></outline>${channels
.map(([feed, channelName]) => `<outline type="rss" text="${channelName}" title="${channelName}" xmlUrl="${feed}"/>`)
.join("")}</outline></body></opml>`;
const blob = new Blob([opmlText], { type: "text/plain" });
const url = window.URL.createObjectURL(blob);
const anchorTag = document.createElement("a");
anchorTag.setAttribute("download", "youtube_subs.opml");
anchorTag.setAttribute("href", url);
anchorTag.dataset.downloadurl = `text/plain:youtube_subs.opml:${url}`;
anchorTag.click();
}

Update (June 2023):

Due to changes to the YouTube website, this script is now obsolete. An updated version is availaible here



YouTube Subscriptions to RSS feeds in OPML file

To generate an OPML file containing RSS feeds of your YouTube subscriptions:

  • Navigate to https://www.youtube.com/feed/channels, and scroll the page to make sure links to every channel are loaded.
  • Run the script or activate the bookmarklet. An OPML file will download, and a list of RSS feeds will be logged to the console if you need it.

Works in Chrome, Firefox and Safari as of May 2023.

@Edwin-Zarco
Copy link

opml-gen appears to be permanently down?

"Website unavailable

This site is currently suspended.
The site administrator has been informed. "

If it is, then may I suggest replacing or removing opml-gen in the .md file?

@Fooftilly
Copy link

Consider using this script: https://greasyfork.org/en/scripts/418574-export-youtube-subscriptions-to-rss-opml
It doesn't need third party site to export YouTube RSS.

@ciltocruz
Copy link

This method doesn't work today (23/05/2023)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment