Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Oh My Zsh
Commits
f5f630ff
Commit
f5f630ff
authored
May 09, 2019
by
DT
Committed by
Marc Cornellà
May 09, 2019
Browse files
osx: update spotify to v2.1 (#7820)
parent
10c1b7d2
Changes
2
Show whitespace changes
Inline
Side-by-side
plugins/osx/README.md
View file @
f5f630ff
...
@@ -18,7 +18,7 @@ This application makes use of the following third party scripts:
...
@@ -18,7 +18,7 @@ This application makes use of the following third party scripts:
[
shpotify
](
https://github.com/hnarayanan/shpotify
)
[
shpotify
](
https://github.com/hnarayanan/shpotify
)
Copyright (c) 2012–201
7
[
Harish Narayanan
](
https://harishnarayanan.org/
)
.
Copyright (c) 2012–201
9
[
Harish Narayanan
](
https://harishnarayanan.org/
)
.
Permission is hereby granted, free of charge, to any person obtaining
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
a copy of this software and associated documentation files (the
...
...
plugins/osx/spotify
View file @
f5f630ff
#!/usr/bin/env bash
#!/usr/bin/env bash
function
spotify
()
{
function
spotify
()
{
# Copyright (c) 2012--201
8
Harish Narayanan <mail@harishnarayanan.org>
# Copyright (c) 2012--201
9
Harish Narayanan <mail@harishnarayanan.org>
#
#
# Contains numerous helpful contributions from Jorge Colindres, Thomas
# Contains numerous helpful contributions from Jorge Colindres, Thomas
# Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
# Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
...
@@ -70,7 +70,7 @@ showHelp () {
...
@@ -70,7 +70,7 @@ showHelp () {
echo
;
echo
;
echo
" next # Skips to the next song in a playlist."
;
echo
" next # Skips to the next song in a playlist."
;
echo
" prev # Returns to the previous song in a playlist."
;
echo
" prev # Returns to the previous song in a playlist."
;
echo
" replay # Replays the current track from the begining."
;
echo
" replay # Replays the current track from the begin
n
ing."
;
echo
" pos <time> # Jumps to a time (in secs) in the current song."
;
echo
" pos <time> # Jumps to a time (in secs) in the current song."
;
echo
" pause # Pauses (or resumes) Spotify playback."
;
echo
" pause # Pauses (or resumes) Spotify playback."
;
echo
" stop # Stops playback."
;
echo
" stop # Stops playback."
;
...
@@ -82,6 +82,9 @@ showHelp () {
...
@@ -82,6 +82,9 @@ showHelp () {
echo
" vol [show] # Shows the current Spotify volume."
;
echo
" vol [show] # Shows the current Spotify volume."
;
echo
;
echo
;
echo
" status # Shows the current player status."
;
echo
" status # Shows the current player status."
;
echo
" status artist # Shows the currently playing artist."
;
echo
" status album # Shows the currently playing album."
;
echo
" status track # Shows the currently playing track."
;
echo
;
echo
;
echo
" share # Displays the current song's Spotify URL and URI."
echo
" share # Displays the current song's Spotify URL and URI."
echo
" share url # Displays the current song's Spotify URL and copies it to the clipboard."
echo
" share url # Displays the current song's Spotify URL and copies it to the clipboard."
...
@@ -99,12 +102,21 @@ cecho(){
...
@@ -99,12 +102,21 @@ cecho(){
echo
$bold$green
"
$1
"
$reset
;
echo
$bold$green
"
$1
"
$reset
;
}
}
showArtist
()
{
echo
`
osascript
-e
'tell application "Spotify" to artist of current track as string'
`
;
}
showAlbum
()
{
echo
`
osascript
-e
'tell application "Spotify" to album of current track as string'
`
;
}
showTrack
()
{
echo
`
osascript
-e
'tell application "Spotify" to name of current track as string'
`
;
}
showStatus
()
{
showStatus
()
{
state
=
`
osascript
-e
'tell application "Spotify" to player state as string'
`
;
state
=
`
osascript
-e
'tell application "Spotify" to player state as string'
`
;
cecho
"Spotify is currently
$state
."
;
cecho
"Spotify is currently
$state
."
;
artist
=
`
osascript
-e
'tell application "Spotify" to artist of current track as string'
`
;
album
=
`
osascript
-e
'tell application "Spotify" to album of current track as string'
`
;
track
=
`
osascript
-e
'tell application "Spotify" to name of current track as string'
`
;
duration
=
`
osascript
-e
'tell application "Spotify"
duration
=
`
osascript
-e
'tell application "Spotify"
set durSec to (duration of current track / 1000) as text
set durSec to (duration of current track / 1000) as text
set tM to (round (durSec / 60) rounding down) as text
set tM to (round (durSec / 60) rounding down) as text
...
@@ -128,7 +140,7 @@ showStatus () {
...
@@ -128,7 +140,7 @@ showStatus () {
end tell
end tell
return nowAt'
`
;
return nowAt'
`
;
echo
-e
$reset
"Artist:
$
a
rtist
\n
Album:
$
a
lbum
\n
Track:
$
t
rack
\n
Position:
$position
/
$duration
"
;
echo
-e
$reset
"Artist:
$
(
showA
rtist
)
\n
Album:
$
(
showA
lbum
)
\n
Track:
$
(
showT
rack
)
\n
Position:
$position
/
$duration
"
;
}
}
if
[
$#
=
0
]
;
then
if
[
$#
=
0
]
;
then
...
@@ -223,18 +235,18 @@ while [ $# -gt 0 ]; do
...
@@ -223,18 +235,18 @@ while [ $# -gt 0 ]; do
results
=
$(
\
results
=
$(
\
curl
-s
-G
$SPOTIFY_SEARCH_API
--data-urlencode
"q=
$Q
"
-d
"type=playlist&limit=10&offset=0"
-H
"Accept: application/json"
-H
"Authorization: Bearer
${
SPOTIFY_ACCESS_TOKEN
}
"
\
curl
-s
-G
$SPOTIFY_SEARCH_API
--data-urlencode
"q=
$Q
"
-d
"type=playlist&limit=10&offset=0"
-H
"Accept: application/json"
-H
"Authorization: Bearer
${
SPOTIFY_ACCESS_TOKEN
}
"
\
|
grep
-E
-o
"spotify:
user:[a-zA-Z0-9_]+:
playlist:[a-zA-Z0-9]+"
-m
10
\
|
grep
-E
-o
"spotify:playlist:[a-zA-Z0-9]+"
-m
10
\
)
)
count
=
$(
\
count
=
$(
\
echo
"
$results
"
|
grep
-c
"spotify:
user
"
\
echo
"
$results
"
|
grep
-c
"spotify:
playlist
"
\
)
)
if
[
"
$count
"
-gt
0
]
;
then
if
[
"
$count
"
-gt
0
]
;
then
random
=
$((
$RANDOM
%
$count
))
;
random
=
$((
$RANDOM
%
$count
))
;
SPOTIFY_PLAY_URI
=
$(
\
SPOTIFY_PLAY_URI
=
$(
\
echo
"
$results
"
|
awk
-v
random
=
"
$random
"
'/spotify:
user:[a-zA-Z0-9]+:
playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}'
\
echo
"
$results
"
|
awk
-v
random
=
"
$random
"
'/spotify:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}'
\
)
)
fi
;;
fi
;;
...
@@ -295,7 +307,7 @@ while [ $# -gt 0 ]; do
...
@@ -295,7 +307,7 @@ while [ $# -gt 0 ]; do
"quit"
)
cecho
"Quitting Spotify."
;
"quit"
)
cecho
"Quitting Spotify."
;
osascript
-e
'tell application "Spotify" to quit'
;
osascript
-e
'tell application "Spotify" to quit'
;
exit
1
;;
exit
0
;;
"next"
)
cecho
"Going to next track."
;
"next"
)
cecho
"Going to next track."
;
osascript
-e
'tell application "Spotify" to next track'
;
osascript
-e
'tell application "Spotify" to next track'
;
...
@@ -346,7 +358,7 @@ while [ $# -gt 0 ]; do
...
@@ -346,7 +358,7 @@ while [ $# -gt 0 ]; do
echo
" vol down # Decreases the volume by 10%."
;
echo
" vol down # Decreases the volume by 10%."
;
echo
" vol [amount] # Sets the volume to an amount between 0 and 100."
;
echo
" vol [amount] # Sets the volume to an amount between 0 and 100."
;
echo
" vol # Shows the current Spotify volume."
;
echo
" vol # Shows the current Spotify volume."
;
break
exit
1
;
fi
fi
osascript
-e
"tell application
\"
Spotify
\"
to set sound volume to
$newvol
"
;
osascript
-e
"tell application
\"
Spotify
\"
to set sound volume to
$newvol
"
;
...
@@ -365,7 +377,25 @@ while [ $# -gt 0 ]; do
...
@@ -365,7 +377,25 @@ while [ $# -gt 0 ]; do
break
;;
break
;;
"status"
)
"status"
)
if
[
$#
!=
1
]
;
then
# There are additional arguments, a status subcommand
case
$2
in
"artist"
)
showArtist
;
break
;;
"album"
)
showAlbum
;
break
;;
"track"
)
showTrack
;
break
;;
esac
else
# status is the only param
showStatus
;
showStatus
;
fi
break
;;
break
;;
"info"
)
"info"
)
...
@@ -428,16 +458,20 @@ while [ $# -gt 0 ]; do
...
@@ -428,16 +458,20 @@ while [ $# -gt 0 ]; do
cecho
"Spotify URI:
$uri
"
;
cecho
"Spotify URI:
$uri
"
;
echo
-n
$uri
| pbcopy
echo
-n
$uri
| pbcopy
fi
fi
break
;;
break
;;
"pos"
)
"pos"
)
cecho
"Adjusting Spotify play position."
cecho
"Adjusting Spotify play position."
osascript
-e
"tell application
\"
Spotify
\"
to set player position to
$2
"
;
osascript
-e
"tell application
\"
Spotify
\"
to set player position to
$2
"
;
break
;;
break
;;
"help"
|
*
)
"help"
)
showHelp
;
showHelp
;
break
;;
break
;;
*
)
showHelp
;
exit
1
;
esac
esac
done
done
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment