-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyfoobar.py
221 lines (172 loc) · 6.64 KB
/
pyfoobar.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
__module_name__ = "fb2kcomtest"
__module_version__ = "1.0"
__module_description__ = "Controls foobar2000 audio player through COM"
__module_author__ = "Holger stenger <[email protected]>"
import win32gui
import time
import pywinauto
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
spec = "[%artist% - ]$if2(%title%,%_filename_ext%)' ['$if(%album%,%album%[ '('%date%')'],$if(%date%,%date%[ / %venue%]))[ #[%disc%/]$num(%tracknumber%,2)]']'[ '['%_length%', '%__bitrate%kbps $codec()']']"
testArtist = "Skillet"
#
# def test():
# try:
# ProgID = "Foobar2000.Application.0.7"
# fb2k = win32com.client.Dispatch(ProgID)
# print "- Testing playback interface..."
# try:
# playback = fb2k.Playback
# print "-- Testing playback orders interface..."
# try:
# pos = playback.Settings.PlaybackOrders
# print "--- Enumerating available playback orders:"
# for po in pos:
# print po
# print "--- Converting name to GUID:"
# if pos.Count > 0:
# name = pos[0]
# guid = "<not retrieved>"
# try:
# guid = pos.GuidFromName(name)
# except:
# pass
# print name, "->", guid
# except:
# print "There was an error."
# except:
# print "There was an error."
# print "- Testing media library interface..."
# try:
# ml = fb2k.MediaLibrary
# print "--- Rescanning media library."
# ml.Rescan()
# print "--- Getting all tracks:"
# tl = ml.GetTracks()
# print "There are", tl.Count, "tracks in the media library."
# print "--- Searching tracks:"
# tl2 = ml.GetTracks("artist IS " + testArtist)
# print "There are", tl2.Count, "tracks by " + testArtist + " in the media library."
# print "-- Testing track list interface..."
# try:
# tl3 = tl.GetTracks("artist IS " + testArtist)
# print "There are", tl3.Count, "tracks by " + testArtist + " in the track list retrieved from the media library."
# except:
# print "There was an error."
# except:
# print "There was an error."
# except:
# pass
#
# #test()
pwa_app = pywinauto.Application()
w_handle = pywinauto.findwindows.find_windows(class_name='{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}')[0]
window = pwa_app.window_(handle=w_handle)
ProgID = "Foobar2000.Application.0.7"
foobar_COM_object = win32com.client.Dispatch(ProgID)
playback = foobar_COM_object.Playback
class fooBar():
def change_trackanddelete_currentone(self):
window.Click()
window.SetFocus()
window.TypeKeys('^d')
self.next()
time.sleep(0.5)
shell.SendKeys("{DELETE}") # Delete selected text? Depends on context. :P
time.sleep(0.5)
shell.SendKeys("{ENTER}") # Delete selected text? Depends on context. :P
def change_trackandadd_tomusicdirectorythen_delete(self):
window.Click()
window.SetFocus()
window.TypeKeys('^d')
self.next()
time.sleep(0.5)
shell.SendKeys('%{f}')
time.sleep(0.1)
shell.SendKeys('n')
time.sleep(0.1)
shell.SendKeys('n')
time.sleep(0.1)
shell.SendKeys('n')
time.sleep(0.1)
shell.SendKeys('n')
time.sleep(0.1)
shell.SendKeys("{ENTER}") # Delete selected text? Depends on context. :P
time.sleep(0.5)
shell.SendKeys("m") # Delete selected text? Depends on context. :P
time.sleep(0.5)
shell.SendKeys("{DELETE}") # Delete selected text? Depends on context. :P
time.sleep(0.5)
shell.SendKeys("{ENTER}") # Delete selected text? Depends on context. :P
def isPlaying(self):
return playback.IsPlaying
def seekToPosition(self,seconds):
if self.isPlaying():
playback.Seek(seconds)
def jumpForward10Seconds(self):
if self.isPlaying():
playback.Seek(playback.Position+10)
def jumpBackward10Seconds(self):
if self.isPlaying():
playback.Seek(playback.Position-10)
def play(self):
playback.Start()
def stop(self):
playback.Stop()
def pauseplay(self):
playback.Pause()
def isPaused(self):
return playback.IsPaused
def next(self):
playback.Next()
def previous(self):
playback.Previous()
def playRandom(self):
playback.Random()
def seekPosition(self):
return playback.Position
def lengthOfTrack(self):
return str(playback.FormatTitle("[%length%]"))
def currentVolumeLevel(self):
return str(playback.Settings.Volume) + "dB"
def mute(self):
playback.Settings.Volume = -100
def setVolumeLevel(self,value):
'''Set volume level to given value
0dB corresponds to MAX_VALUE and -100dB corresponds to MIN_VALUE
So, -100 <= value <= 0'''
playback.Settings.Volume = value
def currentActivePlaylist(self):
return str(foobar_COM_object.Playlists.ActivePlaylist.Name)
def getCurrentTrack(self):
if self.isPlaying():
track = str(playback.FormatTitle("[%title%]"))
if len(track) == 0:
return "check metadata"
else:
return track
else:
return "Check foobar running or not"
def getCurrentArtist(self):
if self.isPlaying():
artist = str(playback.FormatTitle("[%artist%]"))
if len(artist) == 0:
return "check metadata"
else:
return artist
else:
return "Check foobar running or not"
def getCurrentAlbum(self):
if self.isPlaying():
album = str(playback.FormatTitle("[%album%]"))
if len(album) == 0:
return "check metadata"
else:
return album
else:
return "Check foobar running or not"
def isCurrentlyPlaying(self):
return 'Currently playing "{0}" by "{1}"'.format(self.getCurrentTrack(),self.getCurrentArtist())
f = fooBar()
print f.getCurrentTrack()
print f.seekPosition()