Comment puis-je ajouter une "liste rapide" Unity pour Spotify (installée à partir de leur site Web), de sorte que lorsque je clique avec le bouton droit de la souris sur l'icône de mon dock, j'obtienne: "Suivant, Précédent, Arrêter, Lire", etc.?
Puisque spotify inclut un indicateur pour contrôler certaines de ses fonctions, cela nous permet d’utiliser dbus
pour envoyer des événements.
Il y a un excellent script sur buntuforums qui couvre cela.
Commencez par installer un préalable:
Sudo apt-get install libnet-dbus-Perl
Maintenant, copiez et collez le script dans un fichier texte appelé spcmd
et enregistrez-le dans votre dossier personnel.
Donnez-lui des droits d'exécution:
chmod +x ~/spcmd
Permet de déplacer ceci dans un dossier plus utile:
mv ~/spcmd /usr/local/bin
Maintenant, créons une liste rapide.
Commencez par copier le fichier de bureau Spotify dans votre dossier de départ:
mkdir -p ~/.local/share/applications
cp /usr/share/applications/spotify.desktop ~/.local/share/applications
Ouvrez le fichier, copiez et collez la liste rapide à la fin du fichier. Sauvegarde le.
gedit ~/.local/share/applications/spotify.desktop
X-Ayatana-Desktop-Shortcuts=PlayPause;Next;Previous;Stop;
[PlayPause Shortcut Group]
Name=PlayPause
Exec=spcmd playpause
TargetEnvironment=Unity
[Next Shortcut Group]
Name=Next
Exec=spcmd next
TargetEnvironment=Unity
[Previous Shortcut Group]
Name=Previous
Exec=spcmd previous
TargetEnvironment=Unity
[Stop Shortcut Group]
Name=Stop
Exec=spcmd stop
TargetEnvironment=Unity
#!/usr/bin/Perl
use 5.010;
use strict;
use warnings;
use File::Basename;
use Net::DBus;
# Figure out some dbus stuff
unless ( defined $ENV{'DBUS_SESSION_BUS_ADDRESS'} ) {
&set_DBUS_SESSION_BUS_ADDRESS;
#die "Don't know which dbus to attach to.\nMake sure environment variable DBUS_SESSION_BUS_ADDRESS is set.";
}
#my $bus = Net::DBus->find;
my $bus = Net::DBus->session;
my $spotify = $bus->get_service("org.mpris.MediaPlayer2.spotify");
my $player = $spotify->get_object("/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player");
my $application = $spotify->get_object("/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2");
my $getorset = $spotify->get_object("/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties");
# Handle command line argument
if (scalar @ARGV == 0) { &print_help; }
given ($ARGV[0]) {
# when ('play') { $player->Play(); } #Does not work for some reason.
when ('pause') { $player->Pause(); }
when ('playpause') { $player->PlayPause(); }
when ('next') { $player->Next(); }
when ('previous') { $player->Previous(); }
when ('stop') { $player->Stop(); }
when ('playstatus') { print $getorset->Get("org.mpris.MediaPlayer2.Player", "PlaybackStatus") . "\n"; }
when (m/\bspotify:(artist|album|track):[0-9a-zA-z]{22}\b/) { $player->OpenUri($_); }
when ('metadata-debug') { &print_debug_metadata; }
default { &print_help; }
}
# Print the help text
sub print_help {
print "USAGE: " . basename($0) . " {pause|playpause|next|previous|stop|playstatus|met adata-debug|<spotify URI>}\n\n";
print "\t" . "pause" . "\t\t" . "Causes spotify to pause current playback." . "\n";
print "\t" . "playpause" . "\t" . "Causes spotify to pause or play current playback." . "\n";
print "\t" . "next" . "\t\t" . "Goes to next song." . "\n";
print "\t" . "previous" . "\t" . "Goes to previous song." . "\n";
print "\t" . "stop" . "\t\t" . "Stops playback." . "\n";
print "\t" . "playstatus" . "\t" . "Prints current playstatus (Playing/Paused)." . "\n";
print "\t" . "<spotify URI>" . "\t" . "Starts playing supplied URI." . "\n";
print "\t" . "metadata-debug" . "\t" . "Shows available data on currently playing song." . "\n";
print "\t" . "\t\t" . "Fairly unformatted, thus \"debug\" data." . "\n";
print "\n";
print "EXAMPLES:\t" . basename($0) . " playpause" . "\n";
print "\t\t" . basename($0) . " spotify:track:5XXAq1r5r73ZyBS0XAiGw0" . "\n";
exit;
}
# Print some raw metadata
sub print_debug_metadata {
# Dereference the metadata hashref by copying it to a local hash
my %metadata = %{ $getorset->Get("org.mpris.MediaPlayer2.Player", "Metadata") };
# Print all metadata
print "Now Playing:\n";
for (keys %metadata) {
print $_ . ":\t" . $metadata{$_} . "\n" unless ($_ eq 'xesam:artist');
}
# Dereference the artist arrayref by copying it to local array
my @artistarray = @{ $metadata{'xesam:artist'} };
# Print all artists.
foreach my $artist (@artistarray) {
print "artist: \t" . $artist . "\n";
}
}
sub set_DBUS_SESSION_BUS_ADDRESS {
my $curruser = `whoami`; chomp $curruser;
my $procname = 'spotify';
my $pid = `pgrep -o -u $curruser $procname`; chomp $pid;
my $environ = '/proc/' . $pid . '/environ';
my $dbussession = `grep -z DBUS_SESSION_BUS_ADDRESS $environ`; $dbussession =~ s/^DBUS_SESSION_BUS_ADDRESS=//;
$ENV{'DBUS_SESSION_BUS_ADDRESS'} = $dbussession;
}
Je pense que les réponses données jusqu'ici compliquent un peu les choses. Aucun script séparé n'est requis, les commandes DBus correspondantes peuvent être envoyées directement via dbus-send
. Assurez-vous simplement que le paquetage dbus
est installé et en ligne de commande, exécutez les commandes suivantes:
mkdir -p ~/.local/share/applications
cp /usr/share/applications/spotify.desktop ~/.local/share/applications/
Editez le fichier ~/.local/share/applications/spotify.desktop
comme suit:
[Desktop Entry]
Name=Spotify
GenericName=Music Player
Comment=Listen to music using Spotify
Icon=spotify-client
Exec=spotify %U
TryExec=spotify
Terminal=false
Type=Application
Categories=Qt;Audio;Music;Player;AudioVideo
MimeType=x-scheme-handler/spotify
# ====> MODIFICATIONS START HERE <=====
Actions=PlayPause;Next;Previous
[Desktop Action PlayPause]
Name=Play/Pause
Exec=dbus-send --print-reply=literal --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
OnlyShowIn=Messaging Menu;Unity;
[Desktop Action Next]
Name=Next
Exec=dbus-send --print-reply=literal --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
OnlyShowIn=Messaging Menu;Unity;
[Desktop Action Previous]
Name=Previous
Exec=dbus-send --print-reply=literal --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
OnlyShowIn=Messaging Menu;Unity;
Et tu as fini.
spotify_cmd est un outil pour contrôler une instance en cours de Spotify sous wine , il devrait également fonctionner sous Windows, mais n'a pas été utilisé. testé.
Télécharger spotifycmd . Copier sur le bureau. ensuite
cd ~/Desktop/
tar -xvjf spotifycmd-0.5.tar.bz2
Sudo cp -r spotifycmd /usr/bin/
utilisez maintenant Exec=/usr/bin/spotifycmd/spotify_cmd.exe XXXX
lors de la création de la liste rapide.
Ici XXXX
est playpause
, next
, prev
, stop
, voldown
, volup
, etc.
pour guide pour créer la liste rapide regardez ma réponse