Per tivo audio video bitrates
[pyTivo.git] / Config.py
blob3309597c0a02bddcf4efe00b887dd537a4c55bc5
1 import ConfigParser, os
2 import re
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):
12 if not tsn:
13 return True
15 if config.has_section('_tivo_' + tsn):
16 if config.has_option('_tivo_' + tsn, 'aspect169'):
17 if config.get('_tivo_' + tsn, 'aspect169').lower() == 'true':
18 return True
19 else:
20 return False
22 if tsn[:3] in BLACKLIST_169:
23 return False
25 return True
27 def getShares():
28 return filter( lambda x: not(x.startswith('_tivo_') or x == 'Server'), config.sections())
30 def getDebug():
31 try:
32 debug = config.get('Server', 'debug')
33 if debug.lower() == 'true':
34 return True
35 else:
36 return False
37 except NoOptionError:
38 return False
40 def get(section, key):
41 return config.get(section, key)
43 def getValidWidths():
44 return [1440, 720, 704, 544, 480, 352]
46 def getValidHeights():
47 return [720, 480] # Technically 240 is also supported
49 # Return the number in list that is nearest to x
50 # if two values are equidistant, return the larger
51 def nearest(x, list):
52 return reduce(lambda a, b: closest(x,a,b), list)
54 def closest(x,a, b):
55 if abs(x-a) < abs(x-b) or (abs(x-a) == abs(x-b)and a>b):
56 return a
57 else:
58 return b
60 def nearestTivoWidth(width):
61 return nearest(width, getValidWidths())
63 def getTivoHeight():
64 try:
65 height = int(config.get('Server', 'height'))
66 print nearest(height, getValidHeights())
67 return nearest(height, getValidHeights())
68 except NoOptionError: #default
69 return 480
71 def getTivoWidth():
72 try:
73 width = int(config.get('Server', 'width'))
74 print nearestTivoWidth(width)
75 return nearestTivoWidth(width)
76 except NoOptionError: #default
77 return 544
79 def getAudioBR(tsn = None):
80 if tsn and config.has_section('_tivo_' + tsn):
81 try:
82 return config.get('_tivo_' + tsn, 'audio_br')
83 except NoOptionError:
84 pass
86 try:
87 return config.get('Server', 'audio_br')
88 except NoOptionError: #default to 192
89 return '192K'
91 def getVideoBR(tsn = None):
92 if tsn and config.has_section('_tivo_' + tsn):
93 try:
94 return config.get('_tivo_' + tsn, 'video_br')
95 except NoOptionError:
96 pass
98 try:
99 return config.get('Server', 'video_br')
100 except NoOptionError: #default to 4096K
101 return '4096K'
103 def getMaxVideoBR():
104 try:
105 return config.get('Server', 'max_video_br')
106 except NoOptionError: #default to 17M
107 return '17M'
109 def getBuffSize():
110 try:
111 return config.get('Server', 'bufsize')
112 except NoOptionError: #default 1024k
113 return '1024k'