-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spotify.py
101 lines (70 loc) · 2.22 KB
/
Spotify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import sublime_plugin
import subprocess
import os
import threading
class Runner(threading.Thread):
'''https://gist.github.com/duncan-bayne/3f7ef98a15b02b693bf47a03fda79b3a
'''
def __init__(self, command):
self.command = command
threading.Thread.__init__(self)
def run(self):
subprocess.Popen(
self.command,
env=os.environ.copy(),
shell=False,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
universal_newlines=True,
)
class Base(sublime_plugin.WindowCommand):
command = 'PlayPause'
base_command = [
'dbus-send',
'--print-reply=literal',
'--dest=org.mpris.MediaPlayer2.spotify',
'/org/mpris/MediaPlayer2',
'org.mpris.MediaPlayer2.Player.%s'
]
def get_command(self):
command = self.base_command[:]
command[-1] = command[-1] % self.command
return command
def run(self):
runner = Runner(self.get_command())
runner.start()
class PlaypausespotifyCommand(Base):
pass
class NextspotifyCommand(Base):
command = 'Next'
class PreviousspotifyCommand(Base):
command = 'Previous'
class StopspotifyCommand(Base):
command = 'Stop'
class OpenspotifyCommand(Base):
command = 'spotify'
base_command = ['%s']
class ClosespotifyCommand(Base):
base_command = ['kill', '-9', '%s']
def get_command(self):
command = self.base_command[:]
command[-1] = command[-1] % subprocess.check_output(["pidof", "-s", 'spotify'])
return command
class VolumeCommand(Base):
base_command = ['amixer', '-D', 'pulse', 'sset', 'Master', '%s']
input_text = ''
def set_volume(self, text):
self.command = "%s%%%s" % (text, self.signal)
runner = Runner(self.get_command())
runner.start()
def run(self):
self.window.show_input_panel(self.input_text, '', self.set_volume, None, None)
class VolumeupCommand(VolumeCommand):
signal = '+'
input_text = 'Aumentar Volume (%):'
class VolumedownCommand(VolumeCommand):
signal = '-'
input_text = 'Diminuir Volume (%):'
class VolumesetCommand(VolumeCommand):
signal = ''
input_text = 'Volume (%):'