From d714a37953728f47bf9afeb63acbf32fa44a0740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sat, 4 Apr 2020 13:23:31 +0200 Subject: [PATCH] Initial commit. --- LICENSE | 20 +++++++++++++ README | 15 ++++++++++ play-lofi | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 LICENSE create mode 100644 README create mode 100755 play-lofi diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d357790 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (C) 2020 Ortega Froysa, Nicolás All rights reserved. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + +3. This notice may not be removed or altered from any source + distribution. diff --git a/README b/README new file mode 100644 index 0000000..11d5ea3 --- /dev/null +++ b/README @@ -0,0 +1,15 @@ +================= +*** play-lofi *** +================= +A small script that plays lofi music from Invidious[0], a YouTube +proxy. You can choose what stream you'd like to listen to and it saves +it to the file `$XDG_CONFIG_HOME/lofi-link`. + +To use this script you will require the following: + - curl + - mpv + +# License +--------- +This script is licensed with the ZLib license. Basically, don't +misrepresent where you got the script from. diff --git a/play-lofi b/play-lofi new file mode 100755 index 0000000..9986cb6 --- /dev/null +++ b/play-lofi @@ -0,0 +1,89 @@ +#!/bin/sh +# Copyright (C) 2020 Ortega Froysa, Nicolás All rights reserved. +# Author: Ortega Froysa, Nicolás +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# +# 2. Altered source versions must be plainly marked as such, and must not be +# misrepresented as being the original software. +# +# 3. This notice may not be removed or altered from any source +# distribution. + +link_file="$XDG_CONFIG_HOME/lofi-link" + +new_link() { + local results=$(curl -s "https://invidio.us/search?q=lofi+radio" | + grep "

.*watch" | tr -d "\n" | tr -s " ") + results=${results//\\/\" \"} + results=${results//\<\/a\>\<\/p\>/\" æ } + results=${results::-2} # remove that last separator + + # NOTE: I chose æ because never in a million years will that + # character be in the title of a lofi video stream. + IFS="æ" read -r -a streams <<< $results + + echo "Streams:" + local id=1 + for i in "${streams[@]}" + do + title=${i//*\" \"/\"} + echo "$id) ${title:1:-2}" + ((id++)) + done + opt=0 + while [ "$opt" -gt "${#streams[@]}" ] || [ "$opt" -lt "1" ] + do + printf "Selection: " + read opt + done + link=${streams[$opt]} + link=${link//\" \"*/} + link=${link//*\"/} + echo $link > $link_file +} + +# check for link file +if ! [ -e "$link_file" ] +then + echo "No link file found in '$link_file'." + while [ "$option" != "y" ] && [ "$option" != "n" ] + do + printf "Would you like to create one? [y/n] " + read option + done + [ "$option" = "n" ] && exit 1 + new_link + echo "New link file created." +fi + +link=$(cat $link_file) + +# check if video is available +output=$(curl -s $link | grep "This video is unavailable.") +if [ -n "$output" ] +then + echo "The stream link '$link' is unavailable." + while [ "$option" != "y" ] && [ "$option" != "n" ] + do + printf "Would you like to find a new one? [y/n] " + read option + done + [ "$option" = "n" ] && exit 1 + new_link + echo "New link saved." +fi + +mpv --no-video --msg-level=ffmpeg=no $link