コード例 #1
0
def choose_quality(link, name=None, selected_link=None):
    """
    choose quality for scraping

    Keyword Arguments:
    link -- Jenitem link with sublinks
    name -- Name to display in dialog (default None)
    """
    import re

    if name is None:
        name = xbmc.getInfoLabel("listitem.label")
    if link.startswith("http") or link.startswith("plugin"):
        sublinks = [link]
    else:
        jen_link = JenItem(link)
        sublinks = jen_link.getAll("sublink")
        if not sublinks:
            sublinks = [jen_link]
    links = []
    message = get_link_message()
    if selected_link is None:
        default_link = ADDON.getSetting("default_link")
    else:
        default_link = selected_link
    link_dialog = ADDON.getSetting("use_link_dialog") == "true"
    direct_links = False
    for sublink in sublinks:
        if link_dialog and "search" in sublink:
            continue
        if "searchsd" in sublink:
            if default_link == "SD":
                return sublink
            label = "SD"
            if message["SD"] != "":
                label += " (%s)" % message["SD"]
            new_item = (label, sublink)
        elif "search" in sublink:
            if default_link == "HD":
                return sublink
            label = "HD"
            if message["HD"] != "":
                label += " (%s)" % message["HD"]
            new_item = (label, sublink)
        else:
            direct_links = True
            match = re.findall("(.*?)\((.*?)\)", sublink)
            if match:
                new_item = ("%s" % match[0][1], match[0][0])
            else:
                new_item = ("Link %s" % (int(sublinks.index(sublink)) + 1), sublink)
        links.append(new_item)
    if link_dialog and (not direct_links or len(sublinks) > 1):
        links.append(("Search", "search"))

    if len(links) == 1:
        url = links[0][1]
        return url

    select = xbmcgui.Dialog().select(name, [i[0] for i in links])
    if select == -1:
        return False
    else:
        url = links[select][1]
    return url
コード例 #2
0
ファイル: sources.py プロジェクト: CYBERxNUKE/xbmc-addon
def choose_quality(link, name=None, selected_link=None):
    """
    choose quality for scraping

    Keyword Arguments:
    link -- Jenitem link with sublinks
    name -- Name to display in dialog (default None)
    """
    import re
    if name is None:
        name = xbmc.getInfoLabel('listitem.label')
    if link.startswith("http") or link.startswith("plugin"):
        sublinks = [link]
    else:
        jen_link = JenItem(link)
        sublinks = jen_link.getAll("sublink")
        if not sublinks:
            sublinks = [jen_link]
    links = []
    message = get_link_message()
    if selected_link is None:
        default_link = ADDON.getSetting("default_link")
    else:
        default_link = selected_link
    link_dialog = ADDON.getSetting("use_link_dialog") == "true"
    direct_links = False
    for sublink in sublinks:
        if link_dialog and "search" in sublink:
            continue
        if "searchsd" in sublink:
            if default_link == "SD":
                return sublink
            label = 'SD'
            if message['SD'] != '':
                label += ' (%s)' % message['SD']
            new_item = (label, sublink)
        elif "search" in sublink:
            if default_link == "HD":
                return sublink
            label = 'HD'
            if message['HD'] != '':
                label += ' (%s)' % message['HD']
            new_item = (label, sublink)
        else:
            direct_links = True
            match = re.findall("(.*?)\((.*?)\)", sublink)
            if match:
                new_item = ('%s' % match[0][1], match[0][0])
            else:
                new_item = ('Link %s' % (int(sublinks.index(sublink)) + 1),
                            sublink)
        links.append(new_item)
    if link_dialog and (not direct_links or len(sublinks) > 1):
        links.append(("Search", "search"))

    if len(links) == 1:
        url = links[0][1]
        return url

    select = xbmcgui.Dialog().select(name, [i[0] for i in links])
    if select == -1:
        return False
    else:
        url = links[select][1]
    return url