1 import ConfigParser
, os
3 from ConfigParser
import NoOptionError
5 BLACKLIST_169
= ('540', '649')
7 config
= ConfigParser
.ConfigParser()
8 p
= os
.path
.dirname(__file__
)
9 config
.read(os
.path
.join(p
, 'pyTivo.conf'))
11 def get169Setting(tsn
):
15 if config
.has_section('_tivo_' + tsn
):
16 if config
.has_option('_tivo_' + tsn
, 'aspect169'):
17 if config
.get('_tivo_' + tsn
, 'aspect169').lower() == 'true':
22 if tsn
[:3] in BLACKLIST_169
:
28 return filter( lambda x
: not(x
.startswith('_tivo_') or x
== 'Server'), config
.sections())
32 debug
= config
.get('Server', 'debug')
33 if debug
.lower() == 'true':
42 debug
= config
.get('Server', 'hack83')
43 if debug
.lower() == 'true':
50 def get(section
, key
):
51 return config
.get(section
, key
)
54 return [1440, 720, 704, 544, 480, 352]
56 def getValidHeights():
57 return [720, 480] # Technically 240 is also supported
59 # Return the number in list that is nearest to x
60 # if two values are equidistant, return the larger
62 return reduce(lambda a
, b
: closest(x
,a
,b
), list)
65 if abs(x
-a
) < abs(x
-b
) or (abs(x
-a
) == abs(x
-b
)and a
>b
):
71 def nearestTivoWidth(width
):
72 return nearest(width
, getValidWidths())
76 height
= int(config
.get('Server', 'height'))
77 print nearest(height
, getValidHeights())
78 return nearest(height
, getValidHeights())
79 except NoOptionError
: #default
84 width
= int(config
.get('Server', 'width'))
85 print nearestTivoWidth(width
)
86 return nearestTivoWidth(width
)
87 except NoOptionError
: #default
92 return config
.get('Server', 'audio_br')
93 except NoOptionError
: #default to 192
98 return config
.get('Server', 'video_br')
99 except NoOptionError
: #default to 4096K