jeb5 / YouTube-Subscriptions-RSS

Generate an OPML file of RSS feeds for your YouTube subscriptions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add channel URL

huzhifeng opened this issue · comments

Thank you for creating and sharing this project, it's really helpful!

I'd love it if you could export channel URL in addition to RSS URL.

Here is my patch for it.

@@ -16,13 +16,14 @@
                        label.innerText = `Fetching URLS... (${progress.value}/${progress.max})`;
                        try {
                                const channelName = e.querySelector("yt-formatted-string.ytd-channel-name").innerText;
+                               const channelUrl = e.href;
                                const channelReq = await fetch(e.href);
                                if (!channelReq.ok) { console.error(`Couldn't fetch channel page for ${channelName}`); continue; }
                                const channelPageDoc = new DOMParser().parseFromString(await channelReq.text(), "text/html");
                                const links = channelPageDoc.querySelectorAll("body > link[rel=alternate], body > link[rel=canonical]");
                                const channelIdMatch = [...links].map(e => e.href.match("/channel/([a-zA-Z0-9_\-]+?)$")).find(e => e != null);
                                if (channelIdMatch == null) { console.error(`Couldn't find channel id for ${channelName}`); continue; }
-                               channels.push([`https://www.youtube.com/feeds/videos.xml?channel_id=${channelIdMatch[1]}`, channelName]);
+                               channels.push([`https://www.youtube.com/feeds/videos.xml?channel_id=${channelIdMatch[1]}`, channelName, channelUrl]);
                        } finally {
                                progress.value++;
                                progress.replaceWith(progress);
@@ -35,8 +36,8 @@
                        console.log(channels.map(([feed, _]) => feed).join("\n"));
                        let opmlText = `<opml version="1.0">\n\t<head>\n\t\t<title>YouTube Subscriptions as RSS</title>\n\t</head>\n\t<body>\n\t\t<outline text="YouTube Subscriptions">${channels
         .map(
-          ([feed, channelName]) =>
-            `\n\t\t\t<outline type="rss" text="${channelName}" xmlUrl="${feed}"/>`
+          ([feed, channelName, channelUrl]) =>
+            `\n\t\t\t<outline type="rss" text="${channelName}" xmlUrl="${feed}" htmlUrl="${channelUrl}"/>`
         )
         .join("")}\n\t\t</outline>\n\t</body>\n</opml>`;
                        const url = window.URL.createObjectURL(new Blob([opmlText], { type: "text/plain" }));

Thanks @huzhifeng. I've added it