fix: Regex bug when parsing time.

This commit is contained in:
Terry Geng 2020-07-07 21:44:10 +08:00
parent 892fa502e6
commit c9b170d865
No known key found for this signature in database
GPG Key ID: F982F8EA1DF720E7
2 changed files with 3 additions and 3 deletions

View File

@ -279,7 +279,7 @@ help = <h3>Commands</h3>
<b>Control</b>
<ul>
<li> <b>!<u>w</u>eb</b> - get the URL of the web interface, if enabled. </li>
<li> <b>!play </b> (or <b>!p</b>) [{num}] - resume from pausing / start to play (the num-th song is num if given) </li>
<li> <b>!play </b> (or <b>!p</b>) [{num}] [{start_from}] - resume from pausing / start to play (the num-th song is num if given) </li>
<li> <b>!<u>pa</u>use </b> - pause </li>
<li> <b>!<u>st</u>op </b> - stop playing </li>
<li> <b>!<u>sk</u>ip </b> - jump to the next song </li>

View File

@ -366,14 +366,14 @@ def get_media_duration(path):
def parse_time(human):
match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d\d(?:\.\d*)?)", human, flags=re.IGNORECASE)
match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d+(?:\.\d*)?)", human, flags=re.IGNORECASE)
if match:
if match[1] is None and match[2] is None:
return float(match[3])
elif match[2] is None:
return float(match[3]) + 60 * int(match[1])
else:
return float(match[3]) + 60 * int(match[2]) + 3600 * int(match[2])
return float(match[3]) + 60 * int(match[2]) + 3600 * int(match[1])
else:
raise ValueError("Invalid time string given.")