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':
40 def get(section
, key
):
41 return config
.get(section
, key
)
43 def getFFMPEGTemplate(tsn
):
44 if tsn
and config
.has_section('_tivo_' + tsn
):
46 return config
.get('_tivo_' + tsn
, 'ffmpeg_prams', raw
= True)
51 return config
.get('Server', 'ffmpeg_prams', raw
= True)
52 except NoOptionError
: #default
53 return '-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py -ac 2 -ab %(audio_br)s -ar 44100 -f vob -'
56 return [1440, 720, 704, 544, 480, 352]
58 def getValidHeights():
59 return [720, 480] # Technically 240 is also supported
61 # Return the number in list that is nearest to x
62 # if two values are equidistant, return the larger
64 return reduce(lambda a
, b
: closest(x
,a
,b
), list)
67 if abs(x
-a
) < abs(x
-b
) or (abs(x
-a
) == abs(x
-b
)and a
>b
):
72 def nearestTivoWidth(width
):
73 return nearest(width
, getValidWidths())
75 def getTivoHeight(tsn
):
76 if tsn
and config
.has_section('_tivo_' + tsn
):
78 height
= int(config
.get('_tivo_' + tsn
, 'height_br'))
79 return nearest(height
, getValidHeights())
84 height
= int(config
.get('Server', 'height'))
85 return nearest(height
, getValidHeights())
86 except NoOptionError
: #default
89 def getTivoWidth(tsn
):
90 if tsn
and config
.has_section('_tivo_' + tsn
):
92 return config
.get('_tivo_' + tsn
, 'width')
97 width
= int(config
.get('Server', 'width'))
98 return nearestTivoWidth(width
)
99 except NoOptionError
: #default
102 def getAudioBR(tsn
= None):
103 if tsn
and config
.has_section('_tivo_' + tsn
):
105 return config
.get('_tivo_' + tsn
, 'audio_br')
106 except NoOptionError
:
110 return config
.get('Server', 'audio_br')
111 except NoOptionError
: #default to 192
114 def getVideoBR(tsn
= None):
115 if tsn
and config
.has_section('_tivo_' + tsn
):
117 return config
.get('_tivo_' + tsn
, 'video_br')
118 except NoOptionError
:
122 return config
.get('Server', 'video_br')
123 except NoOptionError
: #default to 4096K
128 return config
.get('Server', 'max_video_br')
129 except NoOptionError
: #default to 17M
134 return config
.get('Server', 'bufsize')
135 except NoOptionError
: #default 1024k