Example #1
0
def match_title(data, lang, title_type):
    try:
        exclude = False
        if title_type.startswith('!'):
            title_type = title_type[1:]
            exclude = True

        for title_tag in data.get('titles', []):
            title = pyproxy.decode(title_tag.get('Title', ''))
            if pyproxy.decode(title_tag.get('Title', '')) == '':
                continue

            if title_tag.get('Language', '').lower() != lang.lower():
                continue
            # does it match the proper type
            if exclude and title_tag.get('Type',
                                         '').lower() == title_type.lower():
                continue

            if not exclude and title_tag.get('Type',
                                             '').lower() != title_type.lower():
                continue

            return title
        return None
    except:
        eh.exception(ErrorPriority.NORMAL)
        return None
Example #2
0
def get_tags(tag_node):
    """
    Get the tags from the new style
    Args:
        tag_node: node containing group

    Returns: a string of all of the tags formatted

    """
    try:
        if tag_node is None:
            return ''
        if len(tag_node) == 0:
            return ''
        short_tag = plugin_addon.getSetting('short_tag_list') == 'true'
        temp_genres = []
        current_length = 0
        # the '3' here is because the separator ' | ' is 3 chars
        for tag in tag_node:
            if isinstance(tag, str) or isinstance(tag, unicode):
                if short_tag and current_length + len(tag) + 3 > 50:
                    break
                temp_genres.append(tag)
                current_length += len(tag) + 3
            else:
                temp_genre = pyproxy.decode(tag['tag']).strip()
                if short_tag and current_length + len(temp_genre) + 3 > 50:
                    break
                temp_genres.append(temp_genre)
                current_length += len(temp_genre) + 3
        return kproxy.parse_tags(temp_genres)
    except:
        eh.exception(ErrorPriority.NORMAL)
        return ''
Example #3
0
def clear_image_cache():
    """
    Clear image cache in kodi db
    :return:
    """
    log_setsuzoku(Category.MAINTENANCE, Action.IMAGE, Event.CLEAN)

    ret = xbmcgui.Dialog().yesno(plugin_addon.getLocalizedString(30104),
                                 plugin_addon.getLocalizedString(30081), plugin_addon.getLocalizedString(30112))
    if ret:
        db_files = []
        db_path = os.path.join(pyproxy.decode(xbmc.translatePath('special://home')), 'userdata')
        db_path = os.path.join(db_path, 'Database')
        for r, d, f in os.walk(db_path):
            for files in f:
                if 'Textures' in files:
                    db_files.append(files)
        for db_file in db_files:
            db_connection = database.connect(os.path.join(db_path, db_file))
            db_cursor = db_connection.cursor()
            db_cursor.execute('DELETE FROM texture WHERE url LIKE "%' + plugin_addon.getSetting('port') + '/api/%"')
            db_connection.commit()
            db_cursor.execute('DELETE FROM texture WHERE url LIKE "%nakamori%"')
            db_connection.commit()
            db_connection.close()
        if len(db_files) > 0:
            xbmcgui.Dialog().ok('', plugin_addon.getLocalizedString(30138))
Example #4
0
def clear_listitem_cache():
    """
    Clear mark for nakamori files in kodi db
    :return:
    """
    log_setsuzoku(Category.MAINTENANCE, Action.LISTITEM, Event.CLEAN)

    ret = xbmcgui.Dialog().yesno(plugin_addon.getLocalizedString(30104),
                                 plugin_addon.getLocalizedString(30081), plugin_addon.getLocalizedString(30112))
    if ret:
        db_files = []
        db_path = os.path.join(pyproxy.decode(xbmc.translatePath('special://home')), 'userdata')
        db_path = os.path.join(db_path, 'Database')
        for r, d, f in os.walk(db_path):
            for files in f:
                if 'MyVideos' in files:
                    db_files.append(files)
        for db_file in db_files:
            db_connection = database.connect(os.path.join(db_path, db_file))
            db_cursor = db_connection.cursor()
            db_cursor.execute('DELETE FROM files WHERE strFilename like "%plugin.video.nakamori%"')
            db_connection.commit()
            db_connection.close()
        if len(db_files) > 0:
            xbmcgui.Dialog().ok('', plugin_addon.getLocalizedString(30138))
Example #5
0
def kodi_jsonrpc(method, params):
    try:
        values = (pyproxy.decode(method), json.dumps(params))
        request = '{"jsonrpc":"2.0","method":"%s","params":%s, "id": 1}' % values
        return_data = xbmc.executeJSONRPC(request)
        result = json.loads(return_data)
        return result
    except:
        eh.exception(ErrorPriority.HIGH, localize2(30016))
        return None
Example #6
0
def get_title(data, lang=None, title_type=None):
    """
    Get the title based on settings
    :param data: json node containing the title
    :return: string of the desired title
    :rtype: str

    """
    try:
        if 'titles' not in data or plugin_addon.getSetting(
                'use_server_title') == 'true':
            return pyproxy.decode(data.get('name', ''))
        # xbmc.log(data.get('title', 'Unknown'))
        title = pyproxy.decode(data.get('name', '').lower())
        if is_type_list(title):
            return pyproxy.decode(data.get('name', ''))

        if lang is None:
            lang = plugin_addon.getSetting('displaylang')
        if title_type is None:
            title_type = plugin_addon.getSetting('title_type')

        # try to match
        title = match_title(data, lang, title_type)
        if title is not None:
            return title

        # fallback on any type of same language
        title = match_title(data, lang, '!short')
        if title is not None:
            return title

        # fallback on x-jat main title
        title = match_title(data, 'x-jat', 'main')
        if title is not None:
            return title

        # fallback on directory title
        return pyproxy.decode(data.get('name', ''))
    except:
        eh.exception(ErrorPriority.NORMAL)
        return 'util.error'
Example #7
0
def add_cache(url, json_body):
    """
    Add 'url' with 'json'
    :param url: url you want to cache
    :param json_body: json respond
    :return:
    """
    date = time.time()
    db_connection = database.connect(db_file)
    db_cursor = db_connection.cursor()
    # noinspection PyTypeChecker
    db_cursor.execute(
        'INSERT INTO cache (url, json, created) VALUES (?, ?, ?)',
        (url, pyproxy.decode(json_body), date))
    db_connection.commit()
    db_connection.close()