dotfiles

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

commit ac6ec94efdc943b85b9107c6ed456fae05589fc4
parent fc8dcb7c6b2dd395669f254101d1fbdfd86b6717
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun, 16 Dec 2018 15:04:19 +0100

Radio from subreddits

You can now play music from any subreddit using the radio script, along
with other internet radios.


Former-commit-id: 1ac41bd3089bc38acd823d66239564ded3e90430
Diffstat:
Mbin/radio | 50+++++++++++++++++++++++++++++---------------------
Abin/rplayer | 41+++++++++++++++++++++++++++++++++++++++++
Mother-scripts/radio-config | 5+++++
3 files changed, 75 insertions(+), 21 deletions(-)

diff --git a/bin/radio b/bin/radio @@ -2,12 +2,12 @@ # Initial config, setting $radios and $radio_names if [ -e ~/.radio-config ]; then - source ~/.radio-config + source ~/.radio-config elif [ -e ~/.config/radio-config ]; then - source ~/.config/radio-config + source ~/.config/radio-config else - echo "No radios set up. Please create a config file." - exit 1 + echo "No radios set up. Please create a config file." + exit 1 fi ## MAIN SCRIPT ## @@ -16,7 +16,7 @@ VISUALISER=true while getopts ":n" opt; do case ${opt} in n ) - VISUALISER=false + VISUALISER=false esac done @@ -25,22 +25,30 @@ echo "Welcome to the command line radio player." PS3="Select a radio, or type q to exit: " select RADIO in "${radio_names[@]}" do - if [[ $RADIO = "q" ]]; then - break + if [[ $RADIO = "q" ]]; then + break + else + for i in "${!radio_names[@]}"; do + if [[ "${radio_names[$i]}" = "${RADIO}" ]]; then + if [[ "$RADIO" = "Play from music subreddit" ]]; then + if command -v rplayer &> /dev/null; then + rplayer + else + echo "rplayer not in path." + fi else - for i in "${!radio_names[@]}"; do - if [[ "${radio_names[$i]}" = "${RADIO}" ]]; then - clear - echo "Now playing $RADIO" - echo "Loading..." - if $VISUALISER; then - nice -n 20 mpv ${radios[$i]} --volume=50 --script="/Users/alex/.config/mpv/visualizer.lua" --really-quiet -vo caca - else - nice -n 20 mpv ${radios[$i]} --volume=50 - fi - break - fi - done - break + clear + echo "Now playing $RADIO" + echo "Loading..." + if $VISUALISER; then + nice -n 20 mpv ${radios[$i]} --volume=50 --script="/Users/alex/.config/mpv/visualizer.lua" --really-quiet -vo caca + else + nice -n 20 mpv ${radios[$i]} --volume=50 + fi + break fi + fi + done + break + fi done diff --git a/bin/rplayer b/bin/rplayer @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby +require 'rest-client' +require 'json' + +mpv_options = "--no-video --volume=50" + +def posts_of sub + url="https://www.reddit.com/r/#{sub}/top.json?t=week&limit=100&show=all" + puts "Requesting posts from #{url}..." + response = RestClient.get(url) + data = JSON.parse(response)["data"] + data["children"] +end + +print "Enter subreddit name: " +sub = gets.chomp +posts = posts_of sub + +while posts.length == 0 + puts "Subreddit has no music posts or does not exist." + print "Enter subreddit name: " + sub = gets.chomp + posts = posts_of sub +end + +links = [] +posts.each do |post| + p = post["data"] + if not p["is_self"] and p["post_hint"] != "image" + links.append(title: p["title"], url: p["url"]) + end +end + +links.each do |link| + puts "\n-----\n" + puts "# #{link[:title]}" + puts "(press q to skip)" + if not system("mpv #{mpv_options} '#{link[:url]}'") + puts "Cannot play #{link[:url]}" + end +end diff --git a/other-scripts/radio-config b/other-scripts/radio-config @@ -21,6 +21,9 @@ dub_step="https://somafm.com/dubstep256.pls" # Dubstep, dub defcon="https://somafm.com/defcon256.pls" # Music for hacking deep_space="https://somafm.com/deepspaceone.pls" # Deep ambient electronic/experimental +# Subreddit +subreddit="" + #### END LIST ### # Initialising the arrays radios=( @@ -36,6 +39,7 @@ radios=( $classic_goa $prog_psy_trance $six_forty + $subreddit ) radio_names=( "Drive Radio" @@ -50,4 +54,5 @@ radio_names=( "PSYSTATION - Classic Goa" "PSYSTATION - Progressive Psy Trance" "6forty radio - Post Rock" + "Play from music subreddit" )