YouTube Feeds

An Eccentric Anomaly: Ed Davies's Blog

At the beginning of 2019 I wrote about a little bookmarklet, Show All Feeds, which finds RSS and Atom feeds associated with web pages, blogs mostly.

A few months later I found out that YouTube has feeds for its users and channels. They're not linked or advertised but they can be composed knowing the user or channel identification so I added the ability to do that to the bookmarklet.

The supposed advantage of using the feeds, rather than subscribing directly on YouTube, is that you're not subject the whims of YouTube's “algorithms” on what you get pointed at. I admit I've not used YouTube subscriptions so I'm not sure how much this is actually a problem. Also, you just see new videos in with all the other media you find via feeds and can use any tagging or grouping you use for the rest and the scan gets done at the same time.

Here's the Mercurial diff:

diff -r 8ab5e0fcd142 -r 87773887fe19 show-feeds.js
--- a/show-feeds.js    Mon Dec 31 16:31:08 2018 +0000
+++ b/show-feeds.js    Sat Apr 27 18:24:33 2019 +0100
@@ -36,6 +36,7 @@

     var ul=tag('ul');
     var found=false;
+    var associated=false;
     var links=document.getElementsByTagName('link');

     for(var i=0,link;link=links[i];i++){
@@ -49,10 +50,27 @@
             found=true;
         }
     }
+
+    if (!found) {
+        const l = new URL(location);
+        if ((l.protocol.toLowerCase() in { 'http:': 0, 'https:': 0 }) &&
+            (l.host.toLowerCase() === 'www.youtube.com')) {
+            const p = l.pathname.split('/');
+            const q = ({channel: 'channel_id', user: 'user'})[p[1]];
+            if (q !== undefined) {
+                const href = 'https://www.youtube.com/feeds/videos.xml?' + q + '=' + p[2];
+                ul.appendChild(tag('li', a(href, href)));
+                associated = true;
+            }
+        }
+    }

     if(found){
         el.appendChild(p(txt('The current page links to these feeds:')));
         el.appendChild(ul);
+    }else if (associated) {
+        el.appendChild(p(txt('The current page is associated with these feeds:')));
+        el.appendChild(ul);
     }else{
         el.appendChild(p(txt('The current page does not link to any feeds.')));
     }

The new version in full: show-feeds.js; and squished down for direct copy and paste as a bookmarklet:

javascript:(function(){function%20txt(str){return%20document.createTextNode(str)}function%20tag(n,c){var%20e=document.createElement(n);e.style.fontFamily='Arial,sans-serif';e.style.color='#000';if(c)e.appendChild(c);return%20e}function%20p(c){return%20tag('p',c)}function%20a(href,desc){e=tag('a',txt(desc));e.href=href;e.style.color='#00c';e.style.textDecoration='underline';return%20e}var%20el=tag('div');el.style.zIndex=100000;el.style.position='absolute';el.style.padding='20px';el.style.top='10px';el.style.left='10px';el.style.backgroundColor='#ffffcc';el.style.border='1px%20solid%20#333333';el.style.textAlign='left';var%20ul=tag('ul');var%20found=false;var%20associated=false;var%20links=document.getElementsByTagName('link');for(var%20i=0,link;link=links[i];i++){var%20type=link.getAttribute('type');var%20rel=link.getAttribute('rel');if(type&&(type=='application/rss+xml'||type=='application/atom+xml')&&rel&&rel=='alternate'){var%20href=link.getAttribute('href');href%20=%20(new%20URL(href,%20location)).href;var%20title=link.getAttribute('title');ul.appendChild(tag('li',a(href,((title)%20?%20title+'%20-%20'%20:%20'')+href)));found=true;}}if%20(!found)%20{const%20l%20=%20new%20URL(location);if%20((l.protocol.toLowerCase()%20in%20{%20'http:':%200,%20'https:':%200%20})%20&&(l.host.toLowerCase()%20===%20'www.youtube.com'))%20{const%20p%20=%20l.pathname.split('/');const%20q%20=%20({channel:%20'channel_id',%20user:%20'user'})[p[1]];if%20(q%20!==%20undefined)%20{const%20href%20=%20'https://www.youtube.com/feeds/videos.xml?'%20+%20q%20+%20'='%20+%20p[2];ul.appendChild(tag('li',%20a(href,%20href)));associated%20=%20true;}}}if(found){el.appendChild(p(txt('The%20current%20page%20links%20to%20these%20feeds:')));el.appendChild(ul);}else%20if%20(associated)%20{el.appendChild(p(txt('The%20current%20page%20is%20associated%20with%20these%20feeds:')));el.appendChild(ul);}else{el.appendChild(p(txt('The%20current%20page%20does%20not%20link%20to%20any%20feeds.')));}var%20close=a('#','Close');close.onclick=function(){el.style.display='none';return%20false;};el.appendChild(p(close));function%20addFeedBox(){document.body.appendChild(el);y=window.scroll(0,0);}void(z=addFeedBox());})();