Spotify Quicklist สำหรับ Unity


10

ฉันจะเพิ่ม Unity "quicklist" สำหรับ Spotify (ติดตั้งจากเว็บไซต์ของพวกเขาได้อย่างไร) ดังนั้นเมื่อฉันคลิกขวาที่ไอคอนบน Dock ของฉันฉันจะได้รับ: "Next, Previous, Stop, Play" และอื่น ๆ

คำตอบ:


5

spotify (ไคลเอ็นต์ Linux แบบเนทีฟ)

เนื่องจาก spotify มีตัวบ่งชี้ในการควบคุมฟังก์ชั่นบางอย่างทำให้เราสามารถใช้dbusส่งกิจกรรม

มีสคริปต์ที่ดีในubuntuforumsที่ครอบคลุมนี้

ก่อนติดตั้งข้อกำหนดเบื้องต้น:

sudo apt-get install libnet-dbus-perl

ตอนนี้คัดลอกและวางสคริปต์ลงในไฟล์ข้อความที่เรียกว่าspcmdและบันทึกลงในโฮมโฟลเดอร์ของคุณ

ให้สิทธิดำเนินการ:

chmod +x ~/spcmd

ให้ย้ายสิ่งนี้ไปยังโฟลเดอร์ที่มีประโยชน์มากขึ้น:

mv ~/spcmd /usr/local/bin

ตอนนี้ให้สร้างรายการด่วน

ก่อนอื่นให้คัดลอกไฟล์ spotify บนเดสก์ท็อปของคุณ:

mkdir -p ~/.local/share/applications
cp /usr/share/applications/spotify.desktop ~/.local/share/applications

เปิดไฟล์และคัดลอกและวางรายการด่วนไปยังจุดสิ้นสุดของไฟล์ บันทึกไว้

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

spcmd

#!/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;
}

5

ฉันคิดว่าคำตอบที่ได้รับจนถึงสิ่งที่ซับซ้อนเกินไป ไม่มีสคริปต์แยกต่างหากจำเป็นต้องใช้คำสั่ง DBus dbus-sendที่เกี่ยวข้องสามารถส่งได้โดยตรงผ่านทาง เพียงตรวจสอบให้แน่ใจว่าdbusมีการติดตั้งแพคเกจและในบรรทัดคำสั่งจะมีคำสั่งต่อไปนี้:

mkdir -p ~/.local/share/applications
cp /usr/share/applications/spotify.desktop ~/.local/share/applications/

แก้ไขไฟล์ที่~/.local/share/applications/spotify.desktopจะอ่าน:

[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;

และคุณทำเสร็จแล้ว


นี่คือคำตอบที่ดีที่สุด อย่างไรก็ตามเมื่อฉันพยายามทำด้วยตนเองฉันพลาด--print-reply=literalและมันไม่ทำงาน คุณมีคำอธิบายไหม? ฉันไม่รู้อะไรเลยเกี่ยวกับ DBus
Tamás Barta

คำตอบที่ยอดเยี่ยม :) คำถามเพิ่มเติมเป็นไปได้หรือไม่ที่จะเพิ่มปุ่ม "ยกนิ้ว" และ "ยกนิ้ว" เช่นกัน (คำถามที่อยู่ในวิทยุ spotify :))?
Linus

2

spotify_cmdเป็นเครื่องมือในการควบคุมอินสแตนซ์ที่ใช้งานของ Spotify ภายใต้ ไวน์มันควรทำงานบน Windows เช่นกัน แต่ยังไม่ได้รับการทดสอบ

ดาวน์โหลดspotifycmd คัดลอกไปที่เดสก์ท็อป แล้วก็

cd ~/Desktop/
tar -xvjf spotifycmd-0.5.tar.bz2 
sudo cp -r spotifycmd /usr/bin/

ตอนนี้ใช้Exec=/usr/bin/spotifycmd/spotify_cmd.exe XXXXขณะสร้างรายการด่วน

นี่XXXXคือplaypause, next, prev, stop, voldown, volupฯลฯ

เพื่อเป็นแนวทางในการสร้างรายการด่วนดูที่คำตอบของฉัน


คำตอบนี้ยอดเยี่ยม !!!! ฉันมีปัญหากับ spotify_cmd.exe ที่ทำงาน จะส่งคืนCan not find spotify, is it running?ในเทอร์มินัล นี่เป็นเส้นทางที่ถูกต้องแล้ว!
Ryan McClure

Oof มีวิธีการพื้นเมือง?
MarkovCh1

@Syzygy ฉันไม่พบ :(
Rahul Virpara

hmmm - ได้รับข้อผิดพลาด - บางทีคุณต้องเรียกใช้ spotify ใต้ไวน์รุ่น windows เพื่อหา spotify_cmd ที่ทำงานด้วยไวน์
fossfreedom

@fossfreedom คุณพูดถูก ตรวจสอบแหล่งที่มา มันมีwindows.hห้องสมุดที่ให้ Win32 API
ราหุล Virpara

-1

Spotify จะมีไอคอนอยู่บนพาเนล เพียงคลิกที่และคุณจะได้รับเล่นหยุดหยุดชั่วคราว ฯลฯ ต่อไป (จำไม่ได้ทั้งหมด) ไม่แน่ใจว่าตอบคำถามของคุณหรือไม่


2
คำถามนี้ถามว่าจะใส่ฟังก์ชั่นนั้นไว้ในไอคอนของ Spotify ใน Unity launcher ได้อย่างไร
Eliah Kagan

ตกลงฉันแค่เข้าใจผิดคำถามของเขา
user66987
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.