Fix functionality to report remaining time on an audio file over one day long#14451
Fix functionality to report remaining time on an audio file over one day long#14451saurabhanand03 wants to merge 1 commit into
Conversation
See test results for failed build of commit 57910c3caa |
| """Attempts to find a suitable parsing format string for a HH:MM:SS, MM:SS or SS -style time interval.""" | ||
| timeParts = len(interval.split(":")) | ||
|
|
||
| def parseIntervalToTimestamp(interval): |
There was a problem hiding this comment.
please add type hints
| def parseIntervalToTimestamp(interval): | |
| def parseIntervalToTimestamp(interval: str): -> Optional[int] |
| elapsedTime = self.getElapsedAndTotalIfPlaying()[0] | ||
| if elapsedTime is not None: | ||
| ui.message(elapsedTime) | ||
| ui.message(elapsedTime + " elapsed") |
There was a problem hiding this comment.
This needs to be a translation string, otherwise elapsed won't be translated
| ui.message(elapsedTime + " elapsed") | |
| # Translators: The time elapsed time of a currently playing track in Foobar 2000. | |
| # %s is replaced with the time elapsed. | |
| ui.message(_("%s elapsed" % elapsedTime) |
| totalTime = self.getElapsedAndTotalIfPlaying()[1] | ||
| if totalTime is not None: | ||
| ui.message(totalTime) | ||
| ui.message(totalTime + " total") |
There was a problem hiding this comment.
same here with respect to translations
| # A named tuple for holding the elapsed and total playing times from Foobar2000's status bar | ||
| statusBarTimes = collections.namedtuple('StatusBarTimes', ['elapsed', 'total']) | ||
|
|
||
| def getParsingFormat(interval): |
There was a problem hiding this comment.
removing this function breaks the add-on API. Please follow steps outlined in devDocs/deprecations.md to deprecate the function.
There was a problem hiding this comment.
alternatively, keep the function
| else: | ||
| return None | ||
|
|
||
| def getOutputFormat(seconds): |
There was a problem hiding this comment.
same here with respect to add-on API compatibility
| remainingTime = parsedTotalTime - parsedElapsedTime | ||
| msg = time.strftime(getOutputFormat(remainingTime), time.gmtime(remainingTime)) | ||
| parsedElapsedTime = parseIntervalToTimestamp(elapsedTime) | ||
| msg = getRemainingTime(parsedElapsedTime, parsedTotalTime) + " remaining" |
There was a problem hiding this comment.
same here with regards to translations for "remaining"
| elif seconds < 3600: | ||
| return "%M:%S" | ||
|
|
||
| def getRemainingTime(parsedElapsedTime, parsedTotalTime): |
There was a problem hiding this comment.
same here in respect to typing hints
|
Thanks for fixing this @saurabhanand03, just a few minor issues remaining. |
| return time.strftime("%#d day %H:%M:%S", time.gmtime(remainingTime - 86400)) | ||
| else: | ||
| return "%H:%M:%S" | ||
| return time.strftime("%#d days %H:%M:%S", time.gmtime(remainingTime - 86400)) |
There was a problem hiding this comment.
"day"/"days" should also be translatable. the time format in general would be good to be translatable in general if possible.
I wonder if we have existing code in NVDA to make a localised timestamp announcement
|
Closing in favour of #14127 |
Fixes #14127 Supersedes #14451 Summary of the issue: When using the foobar2000 audio player, the ctrl+shift+r command should report the remaining time in the audio file in the SS, MM:SS, HH:MM:SS, or D HH:MM:SS format depending on the remaining time length. However, using the command on audio files over a day long produces an error as the code attempts to read the time string in the HH:MM:SS format instead of the D HH:MM:SS format. Description of user facing changes Time calculation is now processed correctly for all audio length up to 31 days. After this point, it is uncertain how foobar reports time. In addition to fixing the time calculations, the spoken UI message was also amended to say "[time] total", "[time] elapsed", or "[time] remaining", rather than just "[time]" so as to be more understandable for the listener. Description of development approach Created a collection of translatable time string output formats. Created a generic way to parse timedeltas to localised formatted strings. Created internal functions for foobar appModule to parse foobar time strings to localised formatted strings. --------- Co-authored-by: saurabhanand03 <asaurabh2003@gmail.com>
Link to issue number:
Fixes #14127
Summary of the issue:
When using the foobar2000 audio player, the ctrl + shift + R command should report the remaining time in the audio file in the SS, MM:SS, HH:MM:SS, or D HH:MM:SS format depending on the remaining time length.
However, using the command on audio files over a day long produces an error as the code attempts to read the time string in the HH:MM:SS format instead of the D HH:MM:SS format.
Description of user facing changes
Time calculation is now processed correctly for all audio file lengths. Shortcuts for total time, elapsed time, and remaining time all report accurate values rather than returning errors.
Description of development approach
The elapsedTime and totalTime variables are read from the foobar2000 application directly, then the remainingTime variable is calculated based on the difference between totalTime and elapsedTime. However, since the totalTime and elapsedTime strings were not being parsed into "time" objects properly, the remainingTime calculation was returning an error.
In order to fix this, the getParsingFormat() and getOutputFormat() functions were merged into the parseIntervalToTimestamp() and script_reportRemainingTime() functions, respectively, since the two former functions were only called once in their respective latter functions.
The two former functions served to determine a given time string's format, so that said time string could be properly parsed in the two latter functions. However, it was also necessary to know the time string format so that the "remaining time" calculation could be done properly.
In addition to fixing the time calculations, the spoken UI message was also amended to say "[time] total", "[time] elapsed", or "[time] remaining", rather than just "[time]" so as to be more understandable for the listener.
Testing strategy:
Known issues with pull request:
If time is in MM:SS or SS format, reported message will not be spoken in time format. For example, if the remaining time is 5:34, the reported message will be "five colon thirty-four remaining" rather than "five minutes and thirty-four seconds remaining". I believe this issue has to do with how the UI message is read rather than the foobar2000 application, so it was not in the domain of this pull request.
Change log entries:
Bug fixes
New features
Code Review Checklist: