dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

newsboatify-youtube-subscriptions (678B)


      1 #!/usr/bin/env ruby
      2 # Convert a youtube subscriptions HTML file to a newsboat URLs file.
      3 require 'nokogiri'
      4 doc = Nokogiri::HTML File.read("source.html")
      5 hrefs = doc.css("a.channel-link").inject([]) { |arr,c| arr << c.attr("href") unless c.attr("href").nil? }.uniq!
      6 names = doc.css("yt-formatted-string.style-scope.ytd-channel-name").reduce([]) { |arr, x| arr << x.content unless x.content.nil? }
      7 h = names.zip(hrefs).to_h
      8 h.transform_values! { |v| v.gsub("/channel/", "") unless v.nil? }
      9 File.open("output.txt", "w") do |f|
     10   h.each { |name,id| f.puts "https://youtube.com/feeds/videos.xml?channel_id=#{id}\t\"~#{name}\"\t\"yt-videos\"" }
     11 end
     12 puts "Output saved in output.txt"