Esempio n. 1
0
    def _sql(self, file):
        ''' Get the database path based on the file objects/obj_map.json
            Compatible check, in the event multiple db version are supported with the same Kodi version.
            Load video, music, texture databases from the log file. Will only run once per service thread.
            Running database version lines
        '''
        from objects import obj

        databases = obj.Objects().objects

        if file not in ('video', 'music', 'texture') or databases.get(
                'database_set%s' % file):
            return self._get_database(databases[file], True)

        folder = xbmc.translatePath("special://database/").decode('utf-8')
        files = {
            'Textures': "texture",
            'MyMusic': "music",
            'MyVideos': "video"
        }

        with open(
                xbmc.translatePath('special://logpath/kodi.log').decode(
                    'utf-8'), 'r') as log:
            found_lines = len(files)

            for line in log:
                if 'Running database version' in line:

                    filename = line.rsplit('version ', 1)[1].strip()
                    filename = "%s.db" % filename

                    for database in files:
                        if database in line:

                            key = files[database]
                            databases[key] = os.path.join(
                                folder,
                                filename.decode('utf-8')).decode('utf-8')
                            databases['database_set%s' % key] = True
                            found_lines -= 1

                            break

                elif not found_lines:
                    break

        return databases[file]
Esempio n. 2
0
    def _sql(self, file):
        ''' Get the database path based on the file objects/obj_map.json
            Compatible check, in the event multiple db version are supported with the same Kodi version.
            Discover by file as a last resort.
        '''
        databases = obj.Objects().objects

        if file not in ('video', 'music', 'texture') or databases.get(
                'database_set%s' % file):
            return self._get_database(databases[file], True)

        discovered = self._discover_database(file) if not databases.get(
            'database_set%s' % file) else None

        try:
            loaded = self._get_database(
                databases[file]) if file in databases else file
        except Exception as error:
            LOG.exception(error)

            for i in range(1, 10):
                alt_file = "%s-%s" % (file, i)

                try:
                    loaded = self._get_database(databases[alt_file])

                    break
                except KeyError:  # No other db options
                    loaded = None

                    break
                except Exception as error:
                    LOG.exception(error)

        if discovered and discovered != loaded:

            databases[file] = discovered
            self.discovered = True
        else:
            databases[file] = loaded

        databases['database_set%s' % file] = True
        LOG.info("Database locked in: %s", databases[file])

        return databases[file]
Esempio n. 3
0
    def _sql(self, db_file):
        ''' Get the database path based on the file objects/obj_map.json
            Compatible check, in the event multiple db version are supported with the same Kodi version.
            Discover by file as a last resort.
        '''
        databases = obj.Objects().objects

        if db_file not in ('video', 'music', 'texture') or databases.get(
                'database_set%s' % db_file):
            return self._get_database(databases[db_file], True)

        discovered = self._discover_database(db_file) if not databases.get(
            'database_set%s' % db_file) else None

        databases[db_file] = discovered
        self.discovered = True

        databases['database_set%s' % db_file] = True
        LOG.info("Database locked in: %s", databases[db_file])

        return databases[db_file]
Esempio n. 4
0
    def _sql(self, file):

        databases = obj.Objects().objects

        return xbmc.translatePath(
            databases[file]).decode('utf-8') if file in databases else file