Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: UDID from aTV, some cleanup
- Loading branch information
Showing
11 changed files
with
237 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
|
||
*.pyc | ||
|
||
ATVSettings.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/usr/bin/python | ||
|
||
import sys | ||
from os import sep | ||
import ConfigParser | ||
|
||
from Debug import * # dprint() | ||
|
||
|
||
|
||
options = { \ | ||
'movieview' :('Grid', 'List'), \ | ||
'showview' :('List', 'Grid'), \ | ||
'seasonview' :('List', 'Coverflow'), \ | ||
\ | ||
'transcodequality':('9', '1', '5'), \ | ||
'forcedirectplay' :('False', 'True'), \ | ||
'forcetranscode' :('False', 'True') \ | ||
} | ||
# comment on forcedirectplay -> if true, this has higher priority than forcetranscode | ||
|
||
|
||
|
||
class CATVSettings(): | ||
def __init__(self): | ||
dprint(__name__, 1, "init class CATVSettings") | ||
self.cfg = None | ||
self.loadSettings() | ||
|
||
|
||
|
||
# load/save config | ||
def loadSettings(self): | ||
dprint(__name__, 1, "load settings") | ||
# options -> default | ||
dflt = {} | ||
for opt in options: | ||
dflt[opt] = options[opt][0] | ||
|
||
# load settings | ||
self.cfg = ConfigParser.SafeConfigParser(dflt) | ||
self.cfg.read(self.getSettingsFile()) | ||
|
||
def saveSettings(self): | ||
dprint(__name__, 1, "save settings") | ||
f = open(self.getSettingsFile(), 'wb') | ||
self.cfg.write(f) | ||
f.close() | ||
|
||
def getSettingsFile(self): | ||
return sys.path[0] + sep + "ATVSettings.cfg" | ||
|
||
def checkSection(self, UDID): | ||
# check for existing UDID section | ||
sections = self.cfg.sections() | ||
if not UDID in sections: | ||
self.cfg.add_section(UDID) | ||
dprint(__name__, 0, "add section {0}", UDID) | ||
|
||
|
||
|
||
# access/modify AppleTV options | ||
def getSetting(self, UDID, option): | ||
self.checkSection(UDID) | ||
dprint(__name__, 1, "getsetting {0}", self.cfg.get(UDID, option)) | ||
return self.cfg.get(UDID, option) | ||
|
||
def setSetting(self, UDID, option, val): | ||
self.checkSection(UDID) | ||
opts = options[option] | ||
|
||
# check val in list | ||
found = False | ||
for opt in opts: | ||
if opt==val: | ||
found = True | ||
|
||
# set - if incorrect val, pick default | ||
if found: | ||
self.cfg.set(UDID, option, val) | ||
else: | ||
self.cfg.set(UDID, option, opts[0]) | ||
|
||
def toggleSetting(self, UDID, option): | ||
self.checkSection(UDID) | ||
cur = self.cfg.get(UDID, option) | ||
opts = options[option] | ||
|
||
# find current in list | ||
for i,opt in enumerate(opts): | ||
if opt==cur: | ||
break | ||
|
||
# get next option (circle to first) | ||
i=i+1 | ||
if i>=len(opts): | ||
i=0 | ||
|
||
# set | ||
self.cfg.set(UDID, option, opts[i]) | ||
|
||
|
||
|
||
if __name__=="__main__": | ||
ATVSettings = CATVSettings() | ||
|
||
UDID = '007' | ||
ATVSettings.checkSection(UDID) | ||
|
||
option = 'transcodequality' | ||
print ATVSettings.getSetting(UDID, option) | ||
|
||
print "setSetting" | ||
ATVSettings.setSetting(UDID, option, 'True') # error - pick default | ||
print ATVSettings.getSetting(UDID, option) | ||
ATVSettings.setSetting(UDID, option, '9') | ||
print ATVSettings.getSetting(UDID, option) | ||
|
||
print "toggleSetting" | ||
ATVSettings.toggleSetting(UDID, option) | ||
print ATVSettings.getSetting(UDID, option) | ||
ATVSettings.toggleSetting(UDID, option) | ||
print ATVSettings.getSetting(UDID, option) | ||
ATVSettings.toggleSetting(UDID, option) | ||
print ATVSettings.getSetting(UDID, option) | ||
|
||
del ATVSettings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
"DNSServer" : 1, \ | ||
"WebServer" : 1, \ | ||
"XMLConverter" : 0, \ | ||
"Settings" : 0, \ | ||
"ATVSettings": 0, \ | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.