Loads of major changes, deprecated config file system. Entered beta phase

This commit is contained in:
Mirko Di 2021-10-19 22:21:39 +02:00
parent df648151a8
commit eeeb80bb8c
3 changed files with 123 additions and 115 deletions

View File

@ -1,6 +1,8 @@
# Contributing
If you wanted to make any contributions to the project, I'd be glad to receive them!
If you find any bugs or things that aren't really good, just open up an issue or send me a PR.
And, if you have any ideas or suggestions, feel free to send them to me :D
If you wanted to make any contributions to the project, I'd be glad to receive
them! If you find any bugs or things that aren't really good, just open up an
issue or send me a PR. And, if you have any ideas or suggestions, feel free to
send them to me :D.
Please do keep in mind that the program is meant to never exceed 200 SLOC.

View File

@ -1,5 +1,5 @@
Copyright (C) 2021 mirk0dex
<gitlab.com/mirk0dex>
<mirk0dex.gitlab.io>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -16,78 +16,113 @@
# SONARiS
SONARiS is a script that lets you consoom SoundCloud from the terminal.
Its name was chosen rather randomly, so just ignore how it sounds like *Solaris™*, its **100%** not wanted please Oracle™ do not sue me thanks.
SONARiS is a script that lets you consoom SoundCloud from the terminal. Its name
was chosen rather randomly, so just ignore how it sounds like *Solaris™*, it's
**100%** not wanted please Oracle™ do not sue me thanks.
It makes use of the amazing MPV program as well as the even more amazing youtube-dl to deliver you a high-quality SoundCloud listening experience directly from your terminal/CLI.
It, by default, makes use of the amazing
[MPV](https://github.com/mpv-player/mpv) program as well as the portentous
[youtube-dl](https://github.com/ytdl-org/youtube-dl) to deliver you a
high-quality SoundCloud listening experience directly from your terminal/CLI.
The script is meant to never exceed 200 SLOC.
The script is meant to never exceed *200 SLOC*.
## Installation
To install SONARiS, simply don't install it, lol. Just ``git clone https://gitlab.com/mirk0dex/sonaris`` and ``cd`` into the new folder, which will probably be called "sonaris" or something like that.
Now you can run the script by doing ``./sonaris.sh``, but please make sure that:
To install SONARiS, simply don't install it, lol. Just ``git clone
https://gitlab.com/mirk0dex/sonaris`` and ``cd`` into the new folder, which will
probably be called "sonaris" or something like that. Now you can run the script
by doing ``./sonaris.sh``, but please make sure that:
1. you have installed all deps listed below,
2. you have run ``chmod +x sonaris.sh`` to ensure that the script is executable.
## Dependencies
The script needs the following (amazing, I shall add) programs to be installed to work properly.
They are:
The script needs the following (amazing, I shall add) programs to be installed
to work properly. They are:
- git, to clone the repo;
- a UNIX-like system with a home folder and a '.config' dir inside it, this basically means that there is no Boomer OS (Windows) support, install GNU/Linux folks (but you might be able to run it WSL if you really wanted to);
- bash;
- yq & jq, needed for the configuration file;
- a UNIX-like system with a home folder; basically means that there is no Boomer
OS (Windows) support, install GNU/Linux folks (still, you might be able to get
it running inside WSL if you really wanted to);
- bash (bloat alert);
- sed (GNU sed is recommended);
- grep (replaceable with ripgrep);
- fzf;
- a command line finder, default is fzf;
- curl;
- mpv (of course);
- youtube-dl (I'd just like to interject for a moment: what you're referring to as 'youtube-dl', is in fact 'youtube/soundcloud-dl', or, as I've recently taken to calling it, 'youtube + soundcloud-dl'.).
- youtube-dl (I'd just like to interject for a moment: what you're referring to
as 'youtube-dl', is in fact 'youtube/soundcloud-dl', or, as I've recently
taken to calling it, 'youtube + soundcloud-dl'.);
- a media/music/audio player that supports youtube-dl (of course), default is mpv.
To quickly install alle these, you can use one of the following commands, feel free to pick the one that suits your distro (or OS) the better.
To quickly install alle these, you can use one of the following commands, feel
free to pick the one that suits your distro (or OS) the better.
*Ubuntu*/*Debian*/*Elementary OS*/*Linux Mint*/Any Ubuntu or Debian-based distro:
```
su -c "apt-get update -y && apt-get upgrade -y && apt-get install -y git bash yq jq sed grep fzf curl mpv youtube-dl"
su -c "apt-get update -y && apt-get upgrade && apt-get install -y git bash sed grep fzf curl mpv youtube-dl"
```
*Arch Linux*/*Manjaro*/*Artix Linux*/*Endeavour OS*/*Parabola GNU/Linux*/Any Arch-based distro:
```
su -c "pacman -Syu --noconfirm && pacman -S --noconfirm git bash yq jq sed grep fzf curl mpv youtube-dl"
su -c "pacman -Syu && pacman -S --noconfirm git bash sed grep fzf curl mpv youtube-dl"
```
*Void GNU/Linux*:
```
su -c "xbps-install -Syu && xbps-install git bash yq jq sed grep fzf curl mpv youtube-dl"
```
*MacOS* with *brew*:
```
brew install git bash yq jq gnu-sed fzf curl mpv youtube-dl
su -c "xbps-install -Su && xbps-install git bash sed grep fzf curl mpv youtube-dl"
```
*FreeBSD*:
```
su -c "pkg install git bash yq jq gsed fzf curl mpv youtube_dl"
su -c "pkg install git bash gsed fzf curl mpv youtube_dl"
```
*OpenBSD*:
```
doas pkg_add git bash yq jq gsed fzf curl mpv youtube-dl"
doas pkg_add git bash gsed fzf curl mpv youtube-dl"
```
### Proprietary systems
**Ouch, looks like you accidentally wasted $10,000 on that non-free piece of
poop!**
Don't worry, we got you covered too, although it is highly recommended to never
use proprietary software. Remember to digit [gnu.org](https://gnu.org) in the
address bar rather than
[appel.com](https://img.memecdn.com/wow-such-apple_o_2675543), next time.
*MacOS* with *brew*:
```
brew install git bash gnu-sed fzf curl mpv youtube-dl
```
## Usage
See './sonaris.sh --help' for info on SONARiS and how to use it.
Generally speaking, you just have to run './sonaris.sh' and enter what you want it to look for on SoundCloud, then pick one of the results.
Generally speaking, you just have to run './sonaris.sh' and enter what you want
it to look for on SoundCloud, then pick one of the results.
## Contributing
See 'CONTRIBUTING.md'.
See '[CONTRIBUTING.md](CONTRIBUTING.md)'.
## Hacking & configuring
Just open up the script in your favoUrite text editor and start hacking on it.
To change options such as the default player, you just have to change a
variable. Since this is free software, feel free to fork this repo and do
whatever you want to this script (except, of course, killing it: don't you dare
killing my creation!).
## Known bugs
The program's song downloading feature is still buggy and using it is not
recommended (yet).
## To-Do
- Make the program support downloading songs from SoundCloud
- Enable "favourite artists" support
- [x] Make the program support downloading songs from SoundCloud
- [ ] Make the program REALLY support downloading songs from SoundCloud
- [x] Enable "favourite artists" support

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Copyright (C) 2021 mirk0dex
# <gitlab.com/mirk0dex>
# <mirk0dex.gitlab.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -21,39 +21,45 @@
# Deps:
# bash, sed, grep (replaceable with rg), fzf, curl, mpv, youtube-dl and yq & jq for configurating the program (it needs tomlq to read the config file, which is written in Tom's Obvious Minimal Language)
## SETTINGS ######################################################################################
# folders
downloadDir="$HOME/Music/SoundCloud-downloads" # default is/was $HOME/Music/SoundCloud-downloads
# default stuffs
player="mpv" # default is mpv
finder="fzf" # default is fzf
favArtists() {
# under the following non-comment line (echo "), you may add as many artists as
# you want. You should use the name which you can see in the artist's page,
# example: if my fav artist's page URL were 'https://soundcloud.com/s3rl', I'd
# add 's3rl' to the list below
echo "
s3rl
"
}
##################################################################################################
## MAIN VARIABLES ################################################################################
# this is the current version of the program
version="Alpha 1.0"
version="Beta 1 - Codename sus"
# define a couple coloUrs
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # no colour
# create the temp-config file template, needed later on
configPrepare() {
echo "# Edit me to configure SONARiS
# You can use TOML (Tom's Obvious Minimal Language).
##################################################################################################
# PREFERENCES:
favtexteditor = 'vi' # this is mainly used when you run './sonaris.sh --edit-config'
# FAVO(U)RITE ARTISTS: (please insert the name you can find in the SoundCloud URL, example: URL: 'https://soundcloud.com/S3RL', artist you have to insert: 'S3RL'. You can add as many as you want.)
favartists = '''
favArtist1='null'
favArtist2='null'
favArtist3='null'
'''
# FOLDERS:
downloaddir = '$HOME/Music/SoundCloud-downloads/'
" > "/tmp/sonarisrc-template-temp"
}
configPrepare
# print help screen
helpCreate() {
echo "
SONARiS - BASED CLI SoundCloud client and downloader [Version $version]
# print help screen if needed
helpMe() {
echo "SONARiS - BASED CLI SoundCloud client and downloader [Version $version]
Usage: ./sonaris.sh
./sonaris.sh [options] [option stuffs...]
@ -61,7 +67,7 @@ Usage: ./sonaris.sh
SONARiS is a script which allows you to listen to your favourite songs, albums made by the artists you love.
It does so using the amazing MPV and youtube-dl programs and some other nice tools.
To make it your own and configure it, just check out '~/.config/sonaris/sonarisrc' :D.
To make it your own and configure it, just open up 'sonaris.sh' in your favoUrite text editor :D.
This is free software licensed under the GPL 3.0 license. If you didn't receive a copy of it along with this program, check out <https://www.gnu.org/licenses/>.
@ -69,42 +75,22 @@ Options:
-h, --help prints this help screen and exits
-s, --search [query] search on SoundCloud
-d, --download download a song instead of listening to it
-f, --favs pick an artist from a list (you can choose which to show in ~/.config/sonaris/sonarisrc
-n, --clean-config creates a clean config file in ~/.config/sonaris/
-e, --edit-config opens up the config file in your favo(u)rite text editor
-f, --favs pick an artist from a list (you can choose which to show by editing the script, trust me, it's ez af)
-v, --version prints program version and exits
[Author: mirk0dex <gitlab.com/mirk0dex>]" > "/tmp/sonaris-help-temp"
[Author: mirk0dex <gitlab.com/mirk0dex>]"
}
helpCreate
# create config directory and file if not already there
dirCreate() {
if test -d "$HOME/.config/sonaris/"; then
:
else
mkdir "$HOME/.config/sonaris/"
fi
}
configCreate() {
if test -f "$HOME/.config/sonaris/sonarisrc"; then
:
else
cp "/tmp/sonarisrc-template-temp" "$HOME/.config/sonaris/sonarisrc"
fi
}
dirCreate
configCreate
configFile="$HOME/.config/sonaris/sonarisrc"
## FLAGS #######################################################################################################
# if user runs program with help flag:
# -h, --help
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat "/tmp/sonaris-help-temp"
helpMe
exit
fi
# if user runs program with search flag:
# -s, --search
if [ "$1" = "--search" ] || [ "$1" = "-s" ]; then
if [ -z "$2" ]; then
echo "${RED}Error${NC}: please specify what to search for. See ${YELLOW}--help${NC} for more info."
@ -114,45 +100,30 @@ if [ "$1" = "--search" ] || [ "$1" = "-s" ]; then
fi
fi
# if user runs program with download flag make sure song gets downloaded later on, else, use mpv
# different modes
if [ "$1" = "--download" ] || [ "$1" = "-d" ]; then
playThing="youtube-dl"
else
playThing="mpv"
playThing="$player"
fi
# if user runs program with favs flag:
# -f, --favs
if [ "$1" = "--favs" ] || [ "$1" = "-f" ]; then
favArtists=$(tomlq -r .favartists "$configFile")
choice=$(favArtists | $finder)
if [ -z "$choice" ]; then echo "Goodbye!"; exit; fi # if no choice then exit
$player "https://soundcloud.com/$choice"
echo "Goodbye!" && exit
fi
# if user runs program with clean-config flag:
if [ "$1" = "--clean-config" ] || [ "$1" = "-n" ]; then
echo "
Cleaning up the configuration of SONARiS.
This will completely get rid of all your changes to your sonarisrc file.
Don't worry though, I'll make a backup of it (if it's there)!
"
if test -f "$configFile"; then
cp "$configFile" "$configFile.bak"
fi
cp "/tmp/sonarisrc-template-temp" "$configFile"
exit
fi
# if user runs program with edit-config flag:
if [ "$1" = "--edit-config" ] || [ "$1" = "-e" ]; then
favEditor=$(tomlq -r .favtexteditor "$configFile")
$favEditor "$configFile"
exit
fi
# if user runs program with version flag:
# -v, --version
if [ "$1" = "--version" ] || [ "$1" = "-v" ]; then
echo "The program is currently in version:"; echo "$version"
exit
fi
################################################################################################################
# if no query is specified using -s or --search, ask for one
enterQuery() {
if [ -z "$query" ]; then
@ -162,7 +133,7 @@ enterQuery() {
}
enterQuery
# if user doesn't enter anything or enters q, Q, wq, WQ, exit, quit, :q or :wq, exit
# exit when necessary/asked to
if [ -z "$query" ] || [ "$query" = "q" ] || [ "$query" = "Q" ] || [ "$query" = "wq" ] || [ "$query" = "WQ" ] || [ "$query" = "exit" ] || [ "$query" = "quit" ] || [ "$query" = ":q" ] || [ "$query" = ":wq" ]; then
echo "Goodbye!"
exit
@ -185,11 +156,11 @@ getResults() {
}
getResults
chooseNPlay() { # let user choose and play/download what they asked for
choice=$(echo "$results" | fzf)
# let user choose and play/download what they asked for
chooseNPlay() {
choice=$(echo "$results" | $finder)
if [ -z "$choice" ]; then echo "Goodbye!"; exit; fi # if no choice then exit
if [ "$playThing" = "youtube-dl" ]; then
downloadDir=$(tomlq -r .downloaddir "$configFile")
echo " "; echo -e "Downloaded song(s) will be placed in:${YELLOW} $downloadDir ${NC}"; echo " "
$playThing "https://soundcloud.com$choice" -o "$downloadDir/$choice.mp3"
else echo " "; echo -e "Press ${YELLOW}CTRL + C${NC} at any moment to abort and go back to the song picking screen."; echo " "