commit ab81d7036ffd616ab64ee2b8e4353ddb73292daa
parent 06653b42c11122a0d25915bd796dfa0099e99445
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Wed, 19 Feb 2020 01:55:37 +0100
script to convert youtube HTML to newsboat-style subscriptions
Former-commit-id: 0ff599628dab749f88fe5401454ea6488fcf0c12
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/scripts/newsboatify-youtube-subscriptions b/scripts/newsboatify-youtube-subscriptions
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+require 'nokogiri'
+doc = Nokogiri::HTML File.read("source.html")
+hrefs = doc.css("a.channel-link").inject([]) { |arr,c| arr << c.attr("href") unless c.attr("href").nil? }.uniq!
+names = doc.css("yt-formatted-string.style-scope.ytd-channel-name").reduce([]) { |arr, x| arr << x.content unless x.content.nil? }
+h = names.zip(hrefs).to_h
+h.transform_values! { |v| v.gsub("/channel/", "") unless v.nil? }
+File.open("output.txt", "w") do |f|
+ h.each { |name,id| f.puts "https://youtube.com/feeds/videos.xml?channel_id=#{id}\t\"~#{name}\"\t\"yt-videos\"" }
+end
+puts "Output saved in output.txt"