foobar2000.py
1.48 KB
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
import appModuleHandler
import api
import ui
import time
import calendar
def getFormat(s):
s=s.split(":")
if len(s) ==1:
return "%S"
elif len(s)==2:
return "%M:%S"
else: return "%H:%M:%S"
def getOutputFormat(t):
if t<60:
return "%S"
elif t<3600:
return "%M:%S"
else:
return "%H:%M:%S"
class AppModule(appModuleHandler.AppModule):
statusBar=None
def event_gainFocus(self, obj, nextHandler):
if not self.statusBar: self.statusBar=api.getStatusBar()
nextHandler()
def getElapsedAndTotal(self):
if not self.statusBar: return None
text = self.statusBar.firstChild.name
try:
ltime = text.split("|")[4].split(" / ")
except IndexError:
return None
elapsedTime = calendar.timegm(time.strptime(ltime[0].strip(),getFormat(ltime[0])))
totalTime = calendar.timegm(time.strptime(ltime[1].strip(),getFormat(ltime[1])))
return elapsedTime,totalTime
def script_reportRemainingTime(self,gesture):
times=self.getElapsedAndTotal()
if times is None:
# Translators: Reported when no track is playing in Foobar 2000.
ui.message(_("No track playing"))
return
elapsedTime,totalTime = times
remainingTime = totalTime-elapsedTime
msg = time.strftime(getOutputFormat(remainingTime),time.gmtime(remainingTime))
ui.message(msg)
# Translators: The description of an NVDA command for Foobar 2000.
script_reportRemainingTime.__doc__ = _("Reports the remaining time of the currently playing track, if any")
__gestures = {
"kb:control+shift+r": "reportRemainingTime",
}