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 shares
= [ (section
, dict(config
.items(section
))) for section
in config
.sections() if not(section
.startswith('_tivo_') or section
== 'Server') ]
47 for name
, data
in shares
:
48 if not data
.get('auto_subshares', 'False').lower() == 'true':
51 base_path
= data
['path']
52 for item
in os
.listdir(base_path
):
53 item_path
= os
.path
.join(base_path
, item
)
54 if not os
.path
.isdir(item_path
):
57 new_name
= name
+ '/' + item
59 new_data
['path'] = item_path
61 shares
.append( (new_name
, new_data
) )
68 debug
= config
.get('Server', 'debug')
69 if debug
.lower() == 'true':
76 def get(section
, key
):
77 return config
.get(section
, key
)
79 def getFFMPEGTemplate(tsn
):
80 if tsn
and config
.has_section('_tivo_' + tsn
):
82 return config
.get('_tivo_' + tsn
, 'ffmpeg_prams', raw
= True)
87 return config
.get('Server', 'ffmpeg_prams', raw
= True)
88 except NoOptionError
: #default
89 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 -'
92 return [1440, 720, 704, 544, 480, 352]
94 def getValidHeights():
95 return [720, 480] # Technically 240 is also supported
97 # Return the number in list that is nearest to x
98 # if two values are equidistant, return the larger
100 return reduce(lambda a
, b
: closest(x
,a
,b
), list)
103 if abs(x
-a
) < abs(x
-b
) or (abs(x
-a
) == abs(x
-b
)and a
>b
):
108 def nearestTivoWidth(width
):
109 return nearest(width
, getValidWidths())
111 def getTivoHeight(tsn
):
112 if tsn
and config
.has_section('_tivo_' + tsn
):
114 height
= int(config
.get('_tivo_' + tsn
, 'height_br'))
115 return nearest(height
, getValidHeights())
116 except NoOptionError
:
120 height
= int(config
.get('Server', 'height'))
121 return nearest(height
, getValidHeights())
122 except NoOptionError
: #default
125 def getTivoWidth(tsn
):
126 if tsn
and config
.has_section('_tivo_' + tsn
):
128 return config
.get('_tivo_' + tsn
, 'width')
129 except NoOptionError
:
133 width
= int(config
.get('Server', 'width'))
134 return nearestTivoWidth(width
)
135 except NoOptionError
: #default
138 def getAudioBR(tsn
= None):
139 if tsn
and config
.has_section('_tivo_' + tsn
):
141 return config
.get('_tivo_' + tsn
, 'audio_br')
142 except NoOptionError
:
146 return config
.get('Server', 'audio_br')
147 except NoOptionError
: #default to 192
150 def getVideoBR(tsn
= None):
151 if tsn
and config
.has_section('_tivo_' + tsn
):
153 return config
.get('_tivo_' + tsn
, 'video_br')
154 except NoOptionError
:
158 return config
.get('Server', 'video_br')
159 except NoOptionError
: #default to 4096K
164 return config
.get('Server', 'max_video_br')
165 except NoOptionError
: #default to 17M
170 return config
.get('Server', 'bufsize')
171 except NoOptionError
: #default 1024k