File tree 1 file changed +25
-8
lines changed
1 file changed +25
-8
lines changed Original file line number Diff line number Diff line change 9
9
10
10
log = logging .getLogger ('overcast-sonos' )
11
11
12
+ # We used to look for a 'hh:mm:ss' string and then parse that to seconds, but now overcast only returns minutes :(
13
+ # def duration_in_seconds(str):
14
+ # seconds = -1
15
+ # try:
16
+ # strings = str.split(' ')
17
+ # for string in strings:
18
+ # if ":" in string:
19
+ # list = string.split(":")
20
+ # list.reverse()
21
+ # for i, x in enumerate(list):
22
+ # seconds += int(x) * (60**i)
23
+ # break
24
+ # except:
25
+ # log.debug('''Couldn't parse the episode's duration in seconds from the string %s.''', str)
26
+ # pass
27
+ #
28
+ # log.debug('''Parsed the episode's duration in seconds from the string %s -> %d''', str, seconds)
29
+ #
30
+ # return seconds
31
+
32
+ # turns a string like 'Feb 24 - 36 min left' into seconds
33
+
12
34
13
35
def duration_in_seconds (str ):
14
36
seconds = - 1
15
37
try :
16
- strings = str .split (' ' )
17
- for string in strings :
18
- if ":" in string :
19
- list = string .split (":" )
20
- list .reverse ()
21
- for i , x in enumerate (list ):
22
- seconds += int (x ) * (60 ** i )
23
- break
38
+ strings = str .split ()
39
+ minuteIndex = strings .index ('min' ) - 1
40
+ seconds = int (strings [minuteIndex ]) * 60
24
41
except :
25
42
log .debug ('''Couldn't parse the episode's duration in seconds from the string %s.''' , str )
26
43
pass
You can’t perform that action at this time.
0 commit comments