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'))
12 if config
.has_option('Server', 'GUID'):
13 guid
= config
.get('Server', 'GUID')
18 def getBeaconAddreses():
19 if config
.has_option('Server', 'beacon'):
20 beacon_ips
= config
.get('Server', 'beacon')
22 beacon_ips
= '255.255.255.255'
26 return config
.get('Server', 'Port')
28 def get169Setting(tsn
):
32 if config
.has_section('_tivo_' + tsn
):
33 if config
.has_option('_tivo_' + tsn
, 'aspect169'):
34 if config
.get('_tivo_' + tsn
, 'aspect169').lower() == 'true':
39 if tsn
[:3] in BLACKLIST_169
:
45 return ( (section
, dict(config
.items(section
))) for section
in config
.sections() if not(section
.startswith('_tivo_') or section
== 'Server') )
49 debug
= config
.get('Server', 'debug')
50 if debug
.lower() == 'true':
57 def get(section
, key
):
58 return config
.get(section
, key
)
60 def getFFMPEGTemplate(tsn
):
61 if tsn
and config
.has_section('_tivo_' + tsn
):
63 return config
.get('_tivo_' + tsn
, 'ffmpeg_prams', raw
= True)
68 return config
.get('Server', 'ffmpeg_prams', raw
= True)
69 except NoOptionError
: #default
70 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 -'
73 return [1440, 720, 704, 544, 480, 352]
75 def getValidHeights():
76 return [720, 480] # Technically 240 is also supported
78 # Return the number in list that is nearest to x
79 # if two values are equidistant, return the larger
81 return reduce(lambda a
, b
: closest(x
,a
,b
), list)
84 if abs(x
-a
) < abs(x
-b
) or (abs(x
-a
) == abs(x
-b
)and a
>b
):
89 def nearestTivoWidth(width
):
90 return nearest(width
, getValidWidths())
92 def getTivoHeight(tsn
):
93 if tsn
and config
.has_section('_tivo_' + tsn
):
95 height
= int(config
.get('_tivo_' + tsn
, 'height_br'))
96 return nearest(height
, getValidHeights())
101 height
= int(config
.get('Server', 'height'))
102 return nearest(height
, getValidHeights())
103 except NoOptionError
: #default
106 def getTivoWidth(tsn
):
107 if tsn
and config
.has_section('_tivo_' + tsn
):
109 return config
.get('_tivo_' + tsn
, 'width')
110 except NoOptionError
:
114 width
= int(config
.get('Server', 'width'))
115 return nearestTivoWidth(width
)
116 except NoOptionError
: #default
119 def getAudioBR(tsn
= None):
120 if tsn
and config
.has_section('_tivo_' + tsn
):
122 return config
.get('_tivo_' + tsn
, 'audio_br')
123 except NoOptionError
:
127 return config
.get('Server', 'audio_br')
128 except NoOptionError
: #default to 192
131 def getVideoBR(tsn
= None):
132 if tsn
and config
.has_section('_tivo_' + tsn
):
134 return config
.get('_tivo_' + tsn
, 'video_br')
135 except NoOptionError
:
139 return config
.get('Server', 'video_br')
140 except NoOptionError
: #default to 4096K
145 return config
.get('Server', 'max_video_br')
146 except NoOptionError
: #default to 17M
151 return config
.get('Server', 'bufsize')
152 except NoOptionError
: #default 1024k