[6c2c92]: / plugin.video.vine / default.py  Maximize  Restore  History

Download this file

134 lines (98 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#/bin/python
# -*- coding: utf-8 -*-
# http://wiki.xbmc.org/index.php?title=How-to:Debug_Python_Scripts_with_Eclipse
REMOTE_DBG = False
# append pydev remote debugger
if REMOTE_DBG:
# Make pydev debugger works for auto reload.
# Note pydevd module need to be copied in XBMC\system\python\Lib\pysrc
try:
import pysrc.pydevd as pydevd
# stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True)
#pydevd.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True)
except ImportError:
sys.stderr.write("Error: " +
"You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
sys.exit(1)
import os
import xbmcplugin
import xbmcgui
import xbmc
import re
import mycgi
from httpmanager import HttpManager
from vine import VineProvider
from socket import setdefaulttimeout
from socket import getdefaulttimeout
from urlparse import urlunparse
from xbmcaddon import Addon
import utils
from utils import log
pluginHandle = int(sys.argv[1])
#pluginName = addon.getAddonInfo('id')
addon = Addon()
version = addon.getAddonInfo('version')
pluginName = addon.getAddonInfo('id')
name = addon.getAddonInfo('name')
language = addon.getLocalizedString
httpManager = HttpManager()
RESOURCE_PATH = os.path.join( addon.getAddonInfo( "path" ), "resources" )
MEDIA_PATH = os.path.join( RESOURCE_PATH, "media" )
# Use masterprofile rather profile, because we are caching data that may be used by more than one user on the machine
DATA_FOLDER = xbmc.translatePath( os.path.join( "special://masterprofile","addon_data", pluginName ) )
CACHE_FOLDER = os.path.join( DATA_FOLDER, 'cache' )
def get_system_platform():
platform = "unknown"
if xbmc.getCondVisibility( "system.platform.linux" ):
platform = "linux"
elif xbmc.getCondVisibility( "system.platform.xbox" ):
platform = "xbox"
elif xbmc.getCondVisibility( "system.platform.windows" ):
platform = "windows"
elif xbmc.getCondVisibility( "system.platform.osx" ):
platform = "osx"
log("Platform: %s" % platform, xbmc.LOGDEBUG)
return platform
__platform__ = get_system_platform()
def InitTimeout():
log("getdefaulttimeout(): " + str(getdefaulttimeout()), xbmc.LOGDEBUG)
environment = os.environ.get( "OS", "xbox" )
if environment in ['Linux', 'xbox']:
try:
timeout = int(addon.getSetting('socket_timeout'))
if (timeout > 0):
setdefaulttimeout(timeout)
except:
setdefaulttimeout(None)
#==============================================================================
def executeCommand():
success = False
log (u"pluginHandle: " + repr(pluginHandle), xbmc.LOGDEBUG)
provider = VineProvider()
provider.initialise(httpManager, sys.argv[0], pluginHandle)
success = provider.ExecuteCommand(mycgi)
log (u"executeCommand done", xbmc.LOGDEBUG)
return success
if __name__ == "__main__":
try:
log (u"Name: %s, Version: %s" % (name, version), xbmc.LOGDEBUG)
if addon.getSetting('http_cache_disable_adv') == 'false':
httpManager.SetCacheDir( CACHE_FOLDER )
InitTimeout()
# Each command processes a web page
# Get the web page from the cache if it's there
# If there is an error when processing the web page from the cache
# we want to try again, this time getting the page from the web
httpManager.setGetFromCache(True)
success = executeCommand()
xbmc.log(u"success: %s, getGotFromCache(): %s" % (unicode(success), unicode(httpManager.getGotFromCache())), xbmc.LOGDEBUG)
if success is not None and success == False and httpManager.getGotFromCache() == True:
httpManager.setGetFromCache(False)
executeCommand()
log (u"executeCommand after", xbmc.LOGDEBUG)
except:
# Make sure the text from any script errors are logged
import traceback
traceback.print_exc(file=sys.stdout)
raise