Skip to content
Browse files

New autostart feature

You can now change the default message when submitting to Gomiso
Improved autostart code (avoiding double import and settings page opening)
  • Loading branch information...
1 parent 5da0631 commit 8dde4a7d4072ee19ee3bc3ff53fa7182c0a19207 @metabaron committed
Showing with 84 additions and 32 deletions.
  1. +68 −27 default.py
  2. +4 −0 resources/language/English/strings.xml
  3. +4 −0 resources/language/French/strings.xml
  4. +8 −5 resources/settings.xml
View
95 default.py
@@ -20,51 +20,82 @@
__language__ = __settings__.getLocalizedString
__cwd__ = __settings__.getAddonInfo('path')
-BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'lib' ) )
-LANGUAGE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'language' ) )
+BASE_RESOURCE_PATH = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'lib'))
+LANGUAGE_RESOURCE_PATH = xbmc.translatePath(os.path.join(__cwd__, 'resources', 'language'))
sys.path.append (BASE_RESOURCE_PATH)
sys.path.append (LANGUAGE_RESOURCE_PATH)
-AUTOEXEC_SCRIPT = '\nimport time\nimport xbmc\n\ntime.sleep(5)\nxbmc.executebuiltin("XBMC.RunScript(special://home/addons/script.gomiso/default.py,-startup)")\n'
+AUTOEXEC_SCRIPT = 'xbmc.executebuiltin("XBMC.RunScript(special://home/addons/' + __scriptID__ + '/default.py,-startup)")\n'
AUTOEXEC_FILE = xbmc.translatePath('special://home/userdata/autoexec.py')
AUTOEXEC_FOLDER_PATH = xbmc.translatePath('special://home/userdata/')
-addon_work_folder = os.path.join(xbmc.translatePath( "special://profile/addon_data/" ), __scriptID__)
+addon_work_folder = os.path.join(xbmc.translatePath("special://profile/addon_data/"), __scriptID__)
tokensFile = addon_work_folder + '/tokens'
settingsFile = addon_work_folder + '/settings.xml'
#Now that we appended the directories, let's import
from gomiso import gomiso
+def deleteAutostart():
+# if os.path.exists(AUTOEXEC_FILE):
+# autoExecFile = file(AUTOEXEC_FILE, 'r')
+# fileContent = autoExecFile.readlines()
+# autoExecFile.close()
+# autoExecFile = file('AUTOEXEC_FILE', 'w')
+# for line in fileContent:
+# if not line.find('time.sleep(5) #gomiso'):
+# autoExecFile.write(line)
+# elif not line.find(AUTOEXEC_SCRIPT):
+# autoExecFile.write(line)
+# else:
+# autoExecFile.write('')
+# autoExecFile.close()
+# xbmc.log('####Done')
+ xbmc.executebuiltin("XBMC.Notification(%s, %s, %i, %s)" % ('Gomiso', __language__(30923), 10000, __settings__.getAddonInfo("icon")))
+
def setAutostart():
bFound = False
+ timeFound = False
+ xbmcFound = False
+ sleepFound = False
if os.path.exists(AUTOEXEC_FILE):
- xbmc.log('The file exists')
autoExecFile = file(AUTOEXEC_FILE, 'r')
fileContent = autoExecFile.readlines()
autoExecFile.close()
for line in fileContent:
- if line.find('gomiso') > 0:
+ if line.find(__scriptID__) > 0:
bFound = True
- if not bFound:
- __settings__.openSettings()
- autoExecFile = file(AUTOEXEC_FILE, 'w')
- fileContent.append(AUTOEXEC_SCRIPT)
- autoExecFile.writelines(fileContent)
- autoExecFile.close()
+ elif line.find('import time') >0:
+ timeFound = True
+ elif line.find('import xbmc') > 0:
+ xbmcFound = True
+ elif line.find('time.sleep(5) #gomiso') > 0:
+ sleepFound = True
+ if not bFound:
+ autoExecFile = file(AUTOEXEC_FILE, 'w')
+ fileContent.append('\n' + AUTOEXEC_SCRIPT)
+ if not timeFound:
+ autoExecFile.writelines('\nimport time')
+ if not xbmcFound:
+ autoExecFile.writelines('\nimport xbmc')
+ if not sleepFound:
+ autoExecFile.writelines('\ntime.sleep(5) #gomiso')
+ autoExecFile.writelines(fileContent)
+ autoExecFile.close()
else:
- xbmc.log('The file does not exist')
- __settings__.openSettings()
if os.path.exists(AUTOEXEC_FOLDER_PATH):
- xbmc.log('The directory exists')
autoExecFile = file(AUTOEXEC_FILE, 'w')
- autoExecFile.write(AUTOEXEC_SCRIPT)
+ autoExecFile.writelines('\nimport time')
+ autoExecFile.writelines('\nimport xbmc')
+ autoExecFile.writelines('\ntime.sleep(5) #gomiso')
+ autoExecFile.write('\n' + AUTOEXEC_SCRIPT)
autoExecFile.close()
else:
- xbmc.log('Need to create the directoty')
os.makedirs(AUTOEXEC_FOLDER_PATH)
- xbmc.log('Creating the file')
autoExecFile = file(AUTOEXEC_FILE, 'w')
- autoExecFile.write(AUTOEXEC_SCRIPT)
+ autoExecFile.writelines('\nimport time')
+ autoExecFile.writelines('\nimport xbmc')
+ autoExecFile.writelines('\ntime.sleep(5) #gomiso')
+ autoExecFile.write('\n' + AUTOEXEC_SCRIPT)
autoExecFile.close()
def percentageRemaining(currenttime, duration):
@@ -82,8 +113,6 @@ def percentageRemaining(currenttime, duration):
return float(0.0)
#Commented as: next XBMC version will come with new autostart features (so need to find a way to get both together if possible for backward compatibility)
-#The following function call was tested and is fully fonctional
-#setAutostart()
#We cannot have tokens file and no settings file
if os.path.isfile(tokensFile) == True:
@@ -107,7 +136,7 @@ def percentageRemaining(currenttime, duration):
json_result = json.loads(letsGo.getUserInfo())
xbmc.executebuiltin("XBMC.Notification(%s, %s, %i, %s)" % ('Gomiso', json_result['user']['username'] + " " + __language__(30916), 5000, __settings__.getAddonInfo("icon")))
- videoThreshold = int(__settings__.getSetting( "VideoThreshold" ))
+ videoThreshold = int(__settings__.getSetting("VideoThreshold"))
if videoThreshold == 0:
videoThreshold = 75
elif videoThreshold == 1:
@@ -118,12 +147,25 @@ def percentageRemaining(currenttime, duration):
sleepTime = 10
#Did we display messages on screen when playing video?
- verboseScreen = __settings__.getSetting( "DisplayScreen" )
+ verboseScreen = __settings__.getSetting("DisplayScreen")
if (verboseScreen == 'true'):
verboseScreen = True
else:
verboseScreen = False
-
+
+ #Did we want autostart?
+ autoStart = __settings__.getSetting("Autostart")
+ if(autoStart == 'true'):
+ setAutostart()
+ else:
+ deleteAutostart()
+
+ #What display message do we want?
+ displayMessage = __language__(30919)
+ defaultSubmissionMessage = __settings__.getSetting("DisplayDefaultMessage")
+ if(defaultSubmissionMessage == 'false'):
+ displayMessage = __settings__.getSetting("DisplayMessage")
+
#This is the main part of the program
while (not xbmc.abortRequested):
time.sleep(sleepTime)
@@ -143,9 +185,8 @@ def percentageRemaining(currenttime, duration):
#Retrieve only one entry but would be good to have a threshold level like if more than 20 entries, no submit
json_result = json.loads(letsGo.findMedia(showname, 'tv', 1))
if len(json_result) != 0:
- xbmc.log('###Length: ' + str(len(json_result)))
- #letsGo.checking(json_result[0]['media']['id'], season, episode, __language__(30919))
- letsGo.checking(json_result[0]['media']['id'], season, episode, "Watched on XBMC - Gomiso plugin")
+
+ letsGo.checking(json_result[0]['media']['id'], season, episode, displayMessage)
if verboseScreen:
xbmc.executebuiltin("XBMC.Notification(%s, %s, %i, %s)" % ('Gomiso', showname + ' S' + season + 'E' + episode + ' ' + __language__(30918), 5000, __settings__.getAddonInfo("icon")))
else:
View
4 resources/language/English/strings.xml
@@ -12,4 +12,8 @@
<string id="30919">Watched on XBMC - Gomiso plugin</string>
<string id="30920">Display submission message</string>
<string id="30921">Authentification failed</string>
+ <string id="30922">Autostart</string>
+ <string id="30923">Manually delete gomiso from autoexec.py</string>
+ <string id="30924">Submission message</string>
+ <string id="30925">Default submission message</string>
</strings>
View
4 resources/language/French/strings.xml
@@ -12,4 +12,8 @@
<string id="30919">Regardé sur XBMC (extension Gomiso)</string>
<string id="30920">Afficher les messages quand soumit</string>
<string id="30921">Authentification impossible</string>
+ <string id="30922">Démarrage automatique</string>
+ <string id="30923">Effacer manuellement Gomiso de autoexec.py<string>
+ <string id="30924">Message de soumission</string>
+ <string id="30925">Message de soumission par défaut</string>
</strings>
View
13 resources/settings.xml
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
- <setting type="lsep" label="30901" />
- <setting id="Username" type="text" label="30905" default="" />
- <setting id="Password" type="text" option="hidden" label="30906" default="" />
-
+ <setting type="lsep" label="30901" />
+ <setting id="Username" type="text" label="30905" default="" />
+ <setting id="Password" type="text" option="hidden" label="30906" default="" />
+ <setting id="Autostart" type="bool" label="30922" default="false" />
+
<setting type="lsep" label="30913" />
- <setting id="NotifyOnSubmit" type="bool" label="30920" default="true" />
+ <setting id="DisplayScreen" type="bool" label="30920" default="true" />
<setting id="VideoThreshold" type="enum" label="30915" values="25%|75%" default="1" />
+ <setting id="DisplayDefaultMessage" type="bool" label="30925" default="true" />
+ <setting id="DisplayMessage" type="text" label="30924" default="" visible= "eq(-1,false)" enable="eq(-1,false)"/>
</settings>

0 comments on commit 8dde4a7

Please sign in to comment.
Something went wrong with that request. Please try again.