Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neofetch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
neofetch
Commits
bb3fd97a
Commit
bb3fd97a
authored
Dec 16, 2016
by
Dylan Araps
Committed by
GitHub
Dec 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #536 from dylanaraps/song_dbus
Song: Cleanup get_song()
parents
bbfe31d2
571a5459
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
90 deletions
+25
-90
neofetch
neofetch
+25
-90
No files found.
neofetch
View file @
bb3fd97a
...
@@ -1141,70 +1141,53 @@ get_song() {
...
@@ -1141,70 +1141,53 @@ get_song() {
# This is absurdly long.
# This is absurdly long.
player
=
"
$(
ps x |
awk
'!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious|gnome-music|lollypop|clementine|pragha/ {printf $5 " " $6; exit}'
)
"
player
=
"
$(
ps x |
awk
'!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious|gnome-music|lollypop|clementine|pragha/ {printf $5 " " $6; exit}'
)
"
case
"
${
player
/*\/
}
"
in
get_song_dbus
()
{
"mpd"
*
)
# Multiple players use an almost identical dbus command to get the information.
song
=
"
$(
mpc current
)
"
# This function saves us including the same command throughtout the function.
state
=
"
$(
mpc |
awk
-F
'\\[|\\]'
'/\[/ {printf $2}'
)
"
;;
"cmus"
*
)
IFS
=
$'
\n
'
cmus
=(
$(
cmus-remote
-Q
|
grep
-F
-e
"tag artist "
-e
"tag title"
-e
"status"
|
sort
)
)
song
=
"
${
cmus
[1]/tag artist
}
-
${
cmus
[2]/tag title
}
"
state
=
"
${
cmus
[0]/status
}
"
;;
"mocp"
*
)
song
=
"
$(
mocp
-Q
"%artist - %song"
)
"
state
=
"
$(
mocp
-Q
"%state"
)
"
;;
"spotify"
*
)
case
"
$os
"
in
"Linux"
)
# Thanks dbus
song
=
"
$(
\
song
=
"
$(
\
dbus-send
--print-reply
--dest
=
org.mpris.MediaPlayer2.spotify
/org/mpris/MediaPlayer2
\
dbus-send
--print-reply
--dest
=
org.mpris.MediaPlayer2.
"
${
1
}
"
/org/mpris/MediaPlayer2
\
org.freedesktop.DBus.Properties.Get string:
'org.mpris.MediaPlayer2.Player'
string:
'Metadata'
|
\
org.freedesktop.DBus.Properties.Get string:
'org.mpris.MediaPlayer2.Player'
string:
'Metadata'
|
\
awk
-F
'string "'
'/string|array/ {printf "%s",$2; next}{print ""}'
|
\
awk
-F
'string "'
'/string|array/ {printf "%s",$2; next}{print ""}'
|
\
awk
-F
'"'
'/artist|title/ {printf $2 " - "}'
awk
-F
'"'
'/artist|title/ {printf $2 " - "}'
)
"
)
"
song
=
"
${
song
% -
}
"
song
=
"
${
song
% -
}
"
song
=
"
${
song
/
'('
*
}
"
}
song
=
"
${
song
//
'['
*
}
"
case
"
${
player
/*\/
}
"
in
"mpd"
*
)
song
=
"
$(
mpc current
)
"
;;
"mocp"
*
)
song
=
"
$(
mocp
-Q
"%artist - %song"
)
"
;;
"google play"
*
)
song
=
"
$(
gpmdp-remote current
)
"
;;
"rhythmbox"
*
)
song
=
"
$(
rhythmbox-client
--print-playing
)
"
;;
"deadbeef"
*
)
song
=
"
$(
deadbeef
--nowplaying
'%a - %t'
)
"
;;
"audacious"
*
)
song
=
"
$(
audtool current-song
)
"
;;
"gnome-music"
*
)
get_song_dbus
"GnomeMusic"
;;
"lollypop"
*
)
get_song_dbus
"Lollypop"
;;
"clementine"
*
)
get_song_dbus
"clementine"
;;
"cmus"
*
)
artist
=
"
$(
cmus-remote
-Q
|
grep
-F
"tag artist "
)
"
title
=
"
$(
cmus-remote
-Q
|
grep
-F
"tag title"
)
"
song
=
"
${
artist
/tag artist
}
-
${
title
/tag title
}
"
;;
;;
"spotify"
*
)
case
"
$os
"
in
"Linux"
)
get_song_dbus
"spotify"
;;
"Mac OS X"
)
"Mac OS X"
)
song
=
"
$(
osascript
-e
'tell application "Spotify" to artist of current track as string & " - " & name of current track as string'
)
"
song
=
"
$(
osascript
-e
'tell application "Spotify" to artist of current track as string & " - " & name of current track as string'
)
"
state
=
"
$(
osascript
-e
'tell application "Spotify" to player state as string'
)
"
;;
;;
esac
esac
;;
;;
"google play"
*
)
song
=
"
$(
gpmdp-remote current
)
"
state
=
"
$(
gpmdp-remote status
)
"
;;
"itunes"
*
)
"itunes"
*
)
song
=
"
$(
osascript
-e
'tell application "iTunes" to artist of current track as string & " - " & name of current track as string'
)
"
song
=
"
$(
osascript
-e
'tell application "iTunes" to artist of current track as string & " - " & name of current track as string'
)
"
state
=
"
$(
osascript
-e
'tell application "iTunes" to player state as string'
)
"
;;
"rhythmbox"
*
)
song
=
"
$(
rhythmbox-client
--print-playing
)
"
# Thanks dbus
state
=
"
$(
dbus-send
--print-reply
--dest
=
org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2
\
org.freedesktop.DBus.Properties.Get string:
'org.mpris.MediaPlayer2.Player'
string:
'PlayBackStatus'
|
\
awk
-F
'string "'
'{printf $2}'
)
"
state
=
"
$(
trim_quotes
"
$state
"
)
"
;;
;;
"banshee"
*
)
"banshee"
*
)
artist
=
"
$(
banshee
--query-artist
|
awk
-F
':'
'{print $2}'
)
"
artist
=
"
$(
banshee
--query-artist
|
awk
-F
':'
'{print $2}'
)
"
title
=
"
$(
banshee
--query-title
|
awk
-F
':'
'{print $2}'
)
"
title
=
"
$(
banshee
--query-title
|
awk
-F
':'
'{print $2}'
)
"
song
=
"
$artist
-
$title
"
song
=
"
$artist
-
$title
"
state
=
"
$(
banshee
--query-current-state
|
awk
-F
':'
'{print $2}'
)
"
;;
;;
"amarok"
*
)
"amarok"
*
)
...
@@ -1213,59 +1196,11 @@ get_song() {
...
@@ -1213,59 +1196,11 @@ get_song() {
song
=
"
$artist
-
$title
"
song
=
"
$artist
-
$title
"
;;
;;
"deadbeef"
*
)
song
=
"
$(
deadbeef
--nowplaying
'%a - %t'
)
"
;;
"audacious"
*
)
song
=
"
$(
audtool current-song
)
"
;;
"gnome-music"
*
)
# Hello dbus my old friend.
song
=
"
$(
\
dbus-send
--print-reply
--dest
=
org.mpris.MediaPlayer2.GnomeMusic /org/mpris/MediaPlayer2
\
org.freedesktop.DBus.Properties.Get string:
'org.mpris.MediaPlayer2.Player'
string:
'Metadata'
|
\
awk
-F
'string "'
'/string|array/ {printf "%s",$2; next}{print ""}'
|
\
awk
-F
'"'
'/artist|title/ {printf $2 " - "}'
)
"
song
=
"
${
song
% -
}
"
;;
"lollypop"
*
)
# Hello dbus my old friend.
song
=
"
$(
\
dbus-send
--print-reply
--dest
=
org.mpris.MediaPlayer2.Lollypop /org/mpris/MediaPlayer2
\
org.freedesktop.DBus.Properties.Get string:
'org.mpris.MediaPlayer2.Player'
string:
'Metadata'
|
\
awk
-F
'string "'
'/string|array/ {printf "%s",$2; next}{print ""}'
|
\
awk
-F
'"'
'/artist|title/ {printf $2 " - "}'
)
"
song
=
"
${
song
% -
}
"
;;
"clementine"
*
)
# dbus
song
=
"
$(
dbus-send
--print-reply
--dest
=
org.mpris.clementine /org/mpris/MediaPlayer2
\
org.freedesktop.DBus.Properties.Get string:
'org.mpris.MediaPlayer2.Player'
string:
'Metadata'
|
\
awk
-F
'string "'
'/string|array/ {printf "%s",$2; next}{print ""}'
|
\
awk
-F
'"'
'/artist|title/ {printf $2 " - "}'
)
"
song
=
"
${
song
% -
}
"
;;
"pragha"
*
)
"pragha"
*
)
artist
=
"
$(
pragha
-c
|
awk
-F
':'
'/artist/ {print $2}'
)
"
artist
=
"
$(
pragha
-c
|
awk
-F
':'
'/artist/ {print $2}'
)
"
title
=
"
$(
pragha
-c
|
awk
-F
':'
'/title/ {print $2}'
)
"
title
=
"
$(
pragha
-c
|
awk
-F
':'
'/title/ {print $2}'
)
"
song
=
"
$artist
-
$title
"
song
=
"
$artist
-
$title
"
;;
;;
*
)
song
=
"Not Playing"
;;
esac
case
"
$state
"
in
"pau"
*
)
song
=
"Paused"
;;
"sto"
*
)
song
=
"Stopped"
;;
esac
esac
# Display Artist and Title on seperate lines.
# Display Artist and Title on seperate lines.
...
...
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