59e6b12ec37c677806c4d472118815ffb85f0e06
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

1) #! /usr/bin/env python
2) 
Stefan Schuermans add copyright, remove statu...

Stefan Schuermans authored 10 years ago

3) # BlinkenArea Sync GUI
4) # version 0.1.0 date 2013-11-23
5) # Copyright 2013 Stefan Schuermans <stefan@blinkenarea.org>
6) # Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
7) # a blinkenarea.org project - https://www.blinkenarea.org/
8) 
Stefan Schuermans start making player work -...

Stefan Schuermans authored 10 years ago

9) """time format converter
10) 
11) converts between time in seconds as floating point value and time as
12) human-readable string in hours, minutes and seconds
13) 
14) <time string> = ((<hours>:)?<minutes>:)?<seconds>
15) <hours> = [0-9]+
16) <minutes> = [0-9]+
17) <seconds> = [0-9]+(.[0-9]+)"""
18) 
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

19) def sec2str(sec):
Stefan Schuermans start making player work -...

Stefan Schuermans authored 10 years ago

20)   """convert time in seconds to human-readable time string"""
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

21)   sign = ""
Stefan Schuermans start making player work -...

Stefan Schuermans authored 10 years ago

22)   sec100 = round(sec * 100)
23)   if sec100 < 0:
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

24)     sign = "-";
Stefan Schuermans start making player work -...

Stefan Schuermans authored 10 years ago

25)     sec100 = -sec100;
26)   sec1 = sec100 // 100
27)   sec100 = sec100 % 100
Stefan Schuermans show current position as h:...

Stefan Schuermans authored 10 years ago

28)   minu = sec1 // 60
29)   sec1 = sec1 % 60
30)   hour = minu // 60
31)   minu = minu % 60
32)   return "%s%u:%02u:%02u.%02u" % (sign, hour, minu, sec1, sec100)
33) 
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

34) def str2sec(str):
Stefan Schuermans start making player work -...

Stefan Schuermans authored 10 years ago

35)   """convert a human readable time string into time in seconds"""
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

36)   total = 0
37)   section = 0
38)   sign = 1
39)   decimal = 1
40)   for c in str:
41)     if c == ":":
42)       total = (total + sign * section) * 60
43)       section = 0
44)       sign = 1
45)       decimal = 1
46)     elif c == "-":
47)       sign = -sign
48)     elif c == ".":
49)       decimal = 0.1
50)     elif c >= "0" and c <= "9":
51)       if decimal < 1:
52)         section = section + int(c) * decimal
53)         decimal = decimal * 0.1
54)       else:
55)         section = section * 10 + int(c)
56)   total = total + sign * section
57)   return total