From b0e05249ccdb3b76deaa7b6c2336d9a27afc38fd Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 11 Aug 2020 11:32:39 +0800 Subject: [PATCH 1/6] formating --- play | 71 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/play b/play index d201d64..af6642d 100644 --- a/play +++ b/play @@ -1,72 +1,69 @@ #!/bin/bash -# https://github.com/BelkaDev/mustream +# https://github.com/BelkaDev/mustream # Requires a running Spotify desktop client -check::network() { - [[ $? != 0 ]] && echo "Network error: couldn't reach server." && exit 1 +check::network() { + [[ $? != 0 ]] && echo "Network error: couldn't reach server." && exit 1 } check::running() { -[[ -z $(pidof -s spotify) ]] && echo "Spotify is not running." && exit 1 + [[ -z $(pidof -s spotify) ]] && echo "Spotify is not running." && exit 1 } -_author_name(){ - echo $(echo $( echo "$1") | grep -oh -P '(?<=a playlist by ).*?"'| awk -F"on Spotify" '{print $1}') +_author_name() { + echo $(echo $(echo "$1") | grep -oh -P '(?<=a playlist by ).*?"' | awk -F"on Spotify" '{print $1}') } -_artist_name() -{ - echo $(echo $( echo "$1") | grep -oh -P '(?<=a song by ).*' | awk -F"on Spotify" '{print $1}') +_artist_name() { + echo $(echo $(echo "$1") | grep -oh -P '(?<=a song by ).*' | awk -F"on Spotify" '{print $1}') } -_album_artist_name(){ - echo $(echo $( echo "$1") | grep -oh -P '(?<=an album by ).*?"'| awk -F"on Spotify" '{print $1}' | head -1) +_album_artist_name() { + echo $(echo $(echo "$1") | grep -oh -P '(?<=an album by ).*?"' | awk -F"on Spotify" '{print $1}' | head -1) } -_current_list() -{ -echo $(echo $( echo "$1") | grep -oh -P '(?<="name":").*(?=","description")' ) +_current_list() { + echo $(echo $(echo "$1") | grep -oh -P '(?<="name":").*(?=","description")') } -_tracks_number() -{ - echo $(echo $( echo "$1") | grep -oh -P '(?<="track_number").*?}'|sed s'/.$//' | sed 's/^/"track_id": /' | cut -d, -f1,3 | wc -l) +_tracks_number() { + echo $(echo $(echo "$1") | grep -oh -P '(?<="track_number").*?}' | sed s'/.$//' | sed 's/^/"track_id": /' | cut -d, -f1,3 | wc -l) } - + check::running arg=track engine=https://www.google.com ###### Parsing arguments ###### if [[ ${1^^} =~ ^(-A|--ALBUM|ALBUM)$ ]]; then -arg=album && shift + arg=album && shift elif [[ ${1^^} =~ ^(-P|--PLAYLIST|PLAYLIST|SOME)$ ]]; then -arg=playlist && shift + arg=playlist && shift fi if [[ $* == *"open.spotify.com/playlist/"* ]]; then -arg=playlist -key=$(echo $* | sed 's:.*/::' | cut -c 1-22) + arg=playlist + key=$(echo $* | sed 's:.*/::' | cut -c 1-22) else -###### Preparing request ###### -req=$engine"/search?hl=en&q=$(echo $* | sed 's/ /+/g')"+"site:open.spotify.com/"$arg -###### Fetching key ###### -key=$(curl -sA "FF" $req | \ - grep -o '/dev/null +dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null ###### Output ###### echo "###### Queued ${arg^} ######" if [[ $arg = "track" ]]; then @@ -78,7 +75,7 @@ elif [[ $arg = "album" ]]; then echo "Album : $(_current_list "$curr")" echo "added $(_tracks_number "$curr") tracks to queue." elif [[ $arg = "playlist" ]]; then -###echo "Playlist author : $(author_name "$curr")" #useless info + ###echo "Playlist author : $(author_name "$curr")" #useless info echo "Playlist name : $(_current_list "$curr")" echo "Playlist URL : $link" echo "added $(_tracks_number "$curr") tracks to queue." From 05ed163847650f3b768e1a718371f3612b3662a1 Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 11 Aug 2020 14:06:59 +0800 Subject: [PATCH 2/6] added spotifyd support --- play | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) mode change 100644 => 100755 play diff --git a/play b/play old mode 100644 new mode 100755 index af6642d..9d74100 --- a/play +++ b/play @@ -7,7 +7,13 @@ check::network() { } check::running() { - [[ -z $(pidof -s spotify) ]] && echo "Spotify is not running." && exit 1 + if [[ $(pidof -s spotifyd) ]]; then + client=spotifyd + elif [[ $(pidof -s spotify) ]]; then + : # client=spotify (redundancy, as currently it has only two possible outcomes) + else + echo "Spotify is not running." && exit 1 + fi } _author_name() { @@ -63,7 +69,11 @@ check::network $(echo "$curr" | grep -m 1 -o "Moved Permanently") = "Moved Permanently" ]] && echo "Couldn't find any $arg with given data." && exit 1 ###### Sending D-Bus Event ###### -dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null +if [[ "$client" == "spotifyd" ]]; then + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null +else # elif [[ "$client" == "spotify" ]]; then (redundancy, as currently it has only two possible outcomes) + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null +fi ###### Output ###### echo "###### Queued ${arg^} ######" if [[ $arg = "track" ]]; then From 49c4f2320a625989514a2aa99e57e21feb959735 Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 11 Aug 2020 14:08:21 +0800 Subject: [PATCH 3/6] user defind client instead of auto detection --- play | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/play b/play index 9d74100..b617256 100755 --- a/play +++ b/play @@ -2,16 +2,22 @@ # https://github.com/BelkaDev/mustream # Requires a running Spotify desktop client +client= # spotify or spotifyd (leave it blank for auto detection) + check::network() { [[ $? != 0 ]] && echo "Network error: couldn't reach server." && exit 1 } check::running() { - if [[ $(pidof -s spotifyd) ]]; then - client=spotifyd - elif [[ $(pidof -s spotify) ]]; then - : # client=spotify (redundancy, as currently it has only two possible outcomes) - else + if [[ -z "$client" ]]; then + if [[ $(pidof -s spotifyd) ]]; then + client=spotifyd + elif [[ $(pidof -s spotify) ]]; then + : # client=spotify (redundancy, as currently it has only two possible options) + else + echo "No supported Spotify client running." && exit 1 + fi + elif [[ $(pidof -s spotifyd) ]] || [[ $(pidof -s spotify) ]]; then echo "Spotify is not running." && exit 1 fi } @@ -71,7 +77,7 @@ $(echo "$curr" | grep -m 1 -o "Moved Permanently") = "Moved Permanently" ]] && ###### Sending D-Bus Event ###### if [[ "$client" == "spotifyd" ]]; then dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null -else # elif [[ "$client" == "spotify" ]]; then (redundancy, as currently it has only two possible outcomes) +else # elif [[ "$client" == "spotify" ]]; then (redundancy, as currently it has only two possible options) dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null fi ###### Output ###### From 20a04f5453278d155756c89aa2a3a2e66aee39e8 Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 11 Aug 2020 14:10:43 +0800 Subject: [PATCH 4/6] favours spotify over spotifyd --- play | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/play b/play index b617256..bd85554 100755 --- a/play +++ b/play @@ -10,9 +10,9 @@ check::network() { check::running() { if [[ -z "$client" ]]; then - if [[ $(pidof -s spotifyd) ]]; then - client=spotifyd - elif [[ $(pidof -s spotify) ]]; then + if [[ $(pidof -s spotify) ]]; then + client=spotify + elif [[ $(pidof -s spotifyd) ]]; then : # client=spotify (redundancy, as currently it has only two possible options) else echo "No supported Spotify client running." && exit 1 @@ -75,10 +75,10 @@ check::network $(echo "$curr" | grep -m 1 -o "Moved Permanently") = "Moved Permanently" ]] && echo "Couldn't find any $arg with given data." && exit 1 ###### Sending D-Bus Event ###### -if [[ "$client" == "spotifyd" ]]; then - dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null -else # elif [[ "$client" == "spotify" ]]; then (redundancy, as currently it has only two possible options) +if [[ "$client" == "spotify" ]]; then dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null +else # elif [[ "$client" == "spotifyd" ]]; then (redundancy, as currently it has only two possible options) + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:$arg:$key &>/dev/null fi ###### Output ###### echo "###### Queued ${arg^} ######" From f218587fbab6a8a8ffa30f1cd41f544ab4395388 Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 11 Aug 2020 14:15:39 +0800 Subject: [PATCH 5/6] commented out user defined --- play | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/play b/play index bd85554..824d953 100755 --- a/play +++ b/play @@ -1,8 +1,9 @@ #!/bin/bash # https://github.com/BelkaDev/mustream -# Requires a running Spotify desktop client +# Requires a running Spotify desktop client or spotifyd -client= # spotify or spotifyd (leave it blank for auto detection) +#client= +# spotify or spotifyd (leave it blank for auto detection) check::network() { [[ $? != 0 ]] && echo "Network error: couldn't reach server." && exit 1 From 4a08118a6bdaeff4e71836d93416efc29a6d5a34 Mon Sep 17 00:00:00 2001 From: timescam <45168541+timescam@users.noreply.github.com> Date: Tue, 11 Aug 2020 14:22:14 +0800 Subject: [PATCH 6/6] Update README on Spotifyd support --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 28844fe..2a34bc5 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ acronyms are valid for most cases:
* To hide the Spotify GUI you can try out these commands. (will work better on a WM)
- `xdotool search --name spotify windowunmap` - `wmctrl -r "spotify" -b toggle,hidden` +* This script also supports [Spotifyd](https://github.com/Spotifyd/spotifyd) as Spotify client, you can defind which to use when both are running. (default being the official client) * Some songs may not start due to country restrictions. ## Installation :