11# A part of NonVisual Desktop Access (NVDA)
2- # Copyright (C) 2009-2018 NV Access Limited, Aleksey Sadovoy, James Teh, Joseph Lee, Tuukka Ojala
2+ # Copyright (C) 2009-2020 NV Access Limited, Aleksey Sadovoy, James Teh, Joseph Lee, Tuukka Ojala,
3+ # Bram Duvigneau
34# This file is covered by the GNU General Public License.
45# See the file COPYING for more details.
56
@@ -54,9 +55,14 @@ def getElapsedAndTotal(self):
5455 statusBarContents = self ._statusBar .firstChild .name
5556 try :
5657 playingTimes = statusBarContents .split ("|" )[4 ].split ("/" )
57- return statusBarTimes (playingTimes [0 ], playingTimes [1 ])
5858 except IndexError :
5959 return empty
60+ elapsed = playingTimes [0 ]
61+ if len (playingTimes ) > 1 :
62+ remaining = playingTimes [1 ]
63+ else :
64+ remaining = None
65+ return statusBarTimes (elapsed , remaining )
6066
6167 def getElapsedAndTotalIfPlaying (self ):
6268 elapsedAndTotalTime = self .getElapsedAndTotal ()
@@ -67,12 +73,14 @@ def getElapsedAndTotalIfPlaying(self):
6773
6874 def script_reportRemainingTime (self ,gesture ):
6975 elapsedTime , totalTime = self .getElapsedAndTotalIfPlaying ()
70- if elapsedTime is not None and totalTime is not None :
76+ if elapsedTime is None or totalTime is None :
77+ msg = _ ("Unable to determine remaining time" )
78+ else :
7179 parsedElapsedTime = parseIntervalToTimestamp (elapsedTime )
7280 parsedTotalTime = parseIntervalToTimestamp (totalTime )
7381 remainingTime = parsedTotalTime - parsedElapsedTime
7482 msg = time .strftime (getOutputFormat (remainingTime ), time .gmtime (remainingTime ))
75- ui .message (msg )
83+ ui .message (msg )
7684 # Translators: The description of an NVDA command for reading the remaining time of the currently playing track in Foobar 2000.
7785 script_reportRemainingTime .__doc__ = _ ("Reports the remaining time of the currently playing track, if any" )
7886
@@ -87,6 +95,8 @@ def script_reportTotalTime(self,gesture):
8795 totalTime = self .getElapsedAndTotalIfPlaying ()[1 ]
8896 if totalTime is not None :
8997 ui .message (totalTime )
98+ else :
99+ ui .message (_ ("Total time not available" ))
90100 # Translators: The description of an NVDA command for reading the length of the currently playing track in Foobar 2000.
91101 script_reportTotalTime .__doc__ = _ ("Reports the length of the currently playing track, if any" )
92102
0 commit comments