def __init__(self): #Check if a path has been set in the addon settings db_path = common.addon.get_setting('local_db_location') if db_path: self.path = xbmc.translatePath(db_path) else: self.path = xbmc.translatePath('special://profile/addon_data/script.icechannel/databases') self.path = common.make_dir(self.path, '') self.db = os.path.join(self.path, self.local_db_name) # connect to db at class init and use it globally if DB == 'mysql': class MySQLCursorDict(database.cursor.MySQLCursor): def _row_to_python(self, rowdata, desc=None): row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc) if row: return dict(zip(self.column_names, row)) return None self.dbcon = database.connect(database=common.addon.get_setting('db_name'), user=common.addon.get_setting('db_user'), password=common.addon.get_setting('db_pass'), host=common.addon.get_setting('db_address'), buffered=True, charset='utf8') self.dbcur = self.dbcon.cursor(cursor_class=MySQLCursorDict, buffered=True) else: self.dbcon = database.connect(self.db) self.dbcon.row_factory = database.Row # return results indexed by field names and not numbers so we can convert to dict self.dbcon.text_factory = str self.dbcur = self.dbcon.cursor() self._create_subscription_tables()
def __init__(self): #Check if a path has been set in the addon settings db_path = common.addon.get_setting('local_db_location') if db_path: self.path = xbmc.translatePath(db_path) else: self.path = xbmc.translatePath('special://profile/addon_data/script.icechannel/databases') self.path = common.make_dir(self.path, '') self.db = os.path.join(self.path, self.local_db_name) # connect to db at class init and use it globally if DB == 'mysql': class MySQLCursorDict(database.cursor.MySQLCursor): def _row_to_python(self, rowdata, desc=None): row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc) if row: return dict(zip(self.column_names, row)) return None self.dbcon = database.connect(database=common.addon.get_setting('db_name'), user=common.addon.get_setting('db_user'), password=common.addon.get_setting('db_pass'), host=common.addon.get_setting('db_address'), buffered=True, charset='utf8') self.dbcur = self.dbcon.cursor(cursor_class=MySQLCursorDict, buffered=True) else: self.dbcon = database.connect(self.db) self.dbcon.row_factory = database.Row # return results indexed by field names and not numbers so we can convert to dict self.dbcon.text_factory = str self.dbcur = self.dbcon.cursor() self._create_filestore_tables()
def __init__(self, cookie_file='', proxy='', user_agent='', http_debug=False, cached=True, do_not_cache_if_any=[]): ''' Kwargs: cookie_file (str): Full path to a file to be used to load and save cookies to. proxy (str): Proxy setting (eg. ``'http://*****:*****@example.com:1234'``) user_agent (str): String to use as the User Agent header. If not supplied the class will use a default user agent (chrome) http_debug (bool): Set ``True`` to have HTTP header info written to the XBMC log for all requests. ''' # setup net cache if cached == True self._cached = cached self._do_not_cache_if_any = do_not_cache_if_any if self._cached == True: self._local_cache_db = 'netcache.db' try: #raise Exception('Remote Net Cache Disabled...') if common.addon.get_setting('use_remote_db')=='true' and \ common.addon.get_setting('db_address') is not None and \ common.addon.get_setting('db_user') is not None and \ common.addon.get_setting('db_pass') is not None and \ common.addon.get_setting('db_name') is not None: import mysql.connector as database common.addon.log('-' + HELPER + '- -' +'Loading MySQLdb as DB engine', 2) self._DB = 'mysql' else: raise ValueError('MySQL not enabled or not setup correctly') except: try: import sqlite3 from sqlite3 import dbapi2 as database common.addon.log('-' + HELPER + '- -' +'Loading sqlite3 as DB engine version: %s' % database.sqlite_version, 2) except Exception, e: from pysqlite2 import dbapi2 as database common.addon.log('-' + HELPER + '- -' +'pysqlite2 as DB engine', 2) self._DB = 'sqlite' import os import xbmc db_path = common.addon.get_setting('local_db_location') if db_path: self.path = xbmc.translatePath(db_path) else: self.path = xbmc.translatePath('special://profile/addon_data/script.icechannel/databases') self.path = common.make_dir(self.path, '') self.db = os.path.join(self.path, self._local_cache_db) # connect to db at class init and use it globally if self._DB == 'mysql': class MySQLCursorDict(database.cursor.MySQLCursor): def _row_to_python(self, rowdata, desc=None): row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc) if row: return dict(zip(self.column_names, row)) return None self.dbcon = database.connect(database=common.addon.get_setting('db_name'), user=common.addon.get_setting('db_user'), password=common.addon.get_setting('db_pass'), host=common.addon.get_setting('db_address'), buffered=True, charset='utf8') self.dbcur = self.dbcon.cursor(cursor_class=MySQLCursorDict, buffered=True) else: self.dbcon = database.connect(self.db) self.dbcon.row_factory = database.Row # return results indexed by field names and not numbers so we can convert to dict self.dbcon.text_factory = str self.dbcur = self.dbcon.cursor() self._create_net_cache_tables()
def __init__(self, cookie_file='', proxy='', user_agent='', http_debug=False, cached=True, do_not_cache_if_any=[]): ''' Kwargs: cookie_file (str): Full path to a file to be used to load and save cookies to. proxy (str): Proxy setting (eg. ``'http://*****:*****@example.com:1234'``) user_agent (str): String to use as the User Agent header. If not supplied the class will use a default user agent (chrome) http_debug (bool): Set ``True`` to have HTTP header info written to the XBMC log for all requests. ''' # setup net cache if cached == True self._cached = cached self._do_not_cache_if_any = do_not_cache_if_any if self._cached == True: self._local_cache_db = 'netcache.db' try: #raise Exception('Remote Net Cache Disabled...') if common.addon.get_setting('use_remote_db')=='true' and \ common.addon.get_setting('db_address') is not None and \ common.addon.get_setting('db_user') is not None and \ common.addon.get_setting('db_pass') is not None and \ common.addon.get_setting('db_name') is not None: import mysql.connector as database common.addon.log( '-' + HELPER + '- -' + 'Loading MySQLdb as DB engine', 2) self._DB = 'mysql' else: raise ValueError( 'MySQL not enabled or not setup correctly') except: try: import sqlite3 from sqlite3 import dbapi2 as database common.addon.log( '-' + HELPER + '- -' + 'Loading sqlite3 as DB engine version: %s' % database.sqlite_version, 2) except Exception, e: from pysqlite2 import dbapi2 as database common.addon.log( '-' + HELPER + '- -' + 'pysqlite2 as DB engine', 2) self._DB = 'sqlite' import os import xbmc db_path = common.addon.get_setting('local_db_location') if db_path: self.path = xbmc.translatePath(db_path) else: self.path = xbmc.translatePath( 'special://profile/addon_data/script.icechannel/databases') self.path = common.make_dir(self.path, '') self.db = os.path.join(self.path, self._local_cache_db) # connect to db at class init and use it globally if self._DB == 'mysql': class MySQLCursorDict(database.cursor.MySQLCursor): def _row_to_python(self, rowdata, desc=None): row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc) if row: return dict(zip(self.column_names, row)) return None self.dbcon = database.connect( database=common.addon.get_setting('db_name'), user=common.addon.get_setting('db_user'), password=common.addon.get_setting('db_pass'), host=common.addon.get_setting('db_address'), buffered=True, charset='utf8') self.dbcur = self.dbcon.cursor(cursor_class=MySQLCursorDict, buffered=True) else: self.dbcon = database.connect(self.db) self.dbcon.row_factory = database.Row # return results indexed by field names and not numbers so we can convert to dict self.dbcon.text_factory = str self.dbcur = self.dbcon.cursor() self._create_net_cache_tables()