dotfiles

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

rplayer (998B)


      1 #!/usr/bin/env ruby
      2 require 'rest-client'
      3 require 'json'
      4 
      5 mpv_options = "--no-video --volume=50"
      6 
      7 def posts_of sub
      8   url="https://www.reddit.com/r/#{sub}/top.json?t=week&limit=100&show=all"
      9   puts "Requesting posts from #{url}..."
     10   response = RestClient.get(url)
     11   data = JSON.parse(response)["data"]
     12   data["children"]
     13 end
     14 
     15 print "Enter subreddit name: "
     16 sub = gets.chomp
     17 posts = posts_of sub
     18 
     19 while posts.length == 0
     20   puts "Subreddit has no music posts or does not exist."
     21   print "Enter subreddit name: "
     22   sub = gets.chomp
     23   posts = posts_of sub
     24 end
     25 
     26 links = []
     27 posts.each do |post|
     28   p = post["data"]
     29   if not p["is_self"] and p["post_hint"] != "image"
     30     links.append(title: p["title"], url: p["url"], reddit: "https://reddit.com#{p["permalink"]}")
     31   end
     32 end
     33 
     34 links.each do |link|
     35   puts "\n-----\n"
     36   puts "# #{link[:title]}"
     37   puts "Reddit: #{link[:reddit]}"
     38   puts "(press q to skip)"
     39   if not system("mpv #{mpv_options} '#{link[:url]}'")
     40     puts "Cannot play #{link[:url]}"
     41   end
     42 end