Beispiel #1
0
def do_search(term=None):
    import os
    import xbmc
    import xbmcgui
    import time
    import datetime
    import urllib2
    import shutil

    search_term = term.lower()

    result = run_hook("do_search", search_term)
    if result:
        display_list(result, "videos")
        return
    jenlist = JenList("")
    jenlist.list_image = xbmcaddon.Addon().getAddonInfo('icon')
    theme = xbmcaddon.Addon().getSetting('theme')
    if theme and theme != 'DEFAULT' and theme != 'none':
        jenlist.list_fanart = jenlist.set_theme(theme)
    else:
        jenlist.list_fanart = xbmcaddon.Addon().getAddonInfo('fanart')
    result_list = []
    exact_result_list = []
    item_xml_result_list = []
    exact_item_xml_result_list = []
    dest_file = os.path.join(
        xbmc.translatePath(xbmcaddon.Addon().getSetting("cache_folder")),
        "search.db")

    url = __builtin__.search_db_location
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    try:
        changed = response.headers["Last-Modified"]
        changed_struct = time.strptime(changed, "%a, %d %b %Y %H:%M:%S GMT")
        epoch_changed = int(time.mktime(changed_struct))
        if not os.path.exists(dest_file) or \
           int(os.path.getmtime(dest_file)) < epoch_changed:
            dp = xbmcgui.DialogProgress()
            dp.create(_('Loading database file'), _('Please Wait'))
            if response.getcode() == 200:
                with open(dest_file, 'wb') as out_file:
                    shutil.copyfileobj(response, out_file)
                if os.path.getsize(dest_file) == 0:
                    koding.dolog("0 size db: " + repr(dest_file))
                    os.remove(dest_file)
            dp.close()
    except:  # server down
        if not os.path.exists(dest_file):
            import xbmcgui
            addon_name = xbmcaddon.Addon().getAddonInfo('name')
            xbmcgui.Dialog().ok(
                addon_name, _("no local file found, and server seems down"))
            dp.close()
    response.close()

    results = koding.DB_Query(
        dest_file,
        'SELECT * from search where item like "%%%s%%"' % search_term)
    for result in results:
        item = jenlist.process_item(result["item"])
        playlister = result["poster"]
        title = item["label"].lower()
        if search_term in title:
            item["info"] = {}
            try:
                item['label'] = '{0} - {1}'.format(playlister, item["label"])
            except:
                import xbmc
                koding.dolog("playlister: " + repr(playlister))
                koding.dolog("label:" + repr(item["lable"]))
                koding.dolog("item: " + repr(item))
                raise Exception()
            if title.startswith(search_term + " "):
                exact_result_list.append(item)
                exact_item_xml_result_list.append(result["item"])
                continue
            result_list.append(item)
            item_xml_result_list.append(result["item"])
    meta = xbmcaddon.Addon().getSetting("metadata") == "true"
    if meta:
        # TODO find way to get it all in single cal
        info = get_info(exact_item_xml_result_list)
        if info:
            for index, item in enumerate(exact_result_list):
                item["info"].update(info[index])

        info = get_info(item_xml_result_list)
        if info:
            for index, item in enumerate(result_list):
                item["info"].update(info[index])
    exact_result_list = sorted(exact_result_list, key=lambda item: title)
    exact_result_list.extend(sorted(result_list, key=lambda item: title))
    display_list(exact_result_list, "videos")
Beispiel #2
0
def do_search(term=None):
    import os
    import xbmc
    import xbmcgui
    import time
    import datetime
    import urllib2

    search_term = term.lower()

    boblist = BobList("")
    boblist.list_image = xbmcaddon.Addon().getAddonInfo('icon')
    theme = xbmcaddon.Addon().getSetting('theme')
    if theme and theme != 'DEFAULT' and theme != 'none':
        boblist.list_fanart = boblist.set_theme(theme)
    else:
        boblist.list_fanart = xbmcaddon.Addon().getAddonInfo('fanart')
    result_list = []
    exact_result_list = []
    item_xml_result_list = []
    exact_item_xml_result_list = []
    dest_file = os.path.join(
        xbmc.translatePath(xbmcaddon.Addon().getSetting("cache_folder")),
        "search.db")

    url = "http://norestrictions.club/norestrictions.club/main/search/search.db"
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    try:
        changed = response.headers["Last-Modified"]
        changed_struct = time.strptime(changed, "%a, %d %b %Y %H:%M:%S GMT")
        epoch_changed = int(time.mktime(changed_struct))
        if not os.path.exists(dest_file) or \
           int(os.path.getmtime(dest_file)) < epoch_changed:
            dp = xbmcgui.DialogProgress()
            dp.create('Loading database file', 'Please Wait')
            koding.Download(url, dest_file)
    except:  # server down
        if not os.path.exists(dest_file):
            import xbmcgui
            addon_name = xbmcaddon.Addon().getAddonInfo('name')
            xbmcgui.Dialog().ok(addon_name,
                                "no local file found, and server seems down")
    response.close()
    results = koding.DB_Query(
        dest_file,
        'SELECT * from search where item like "%%%s%%"' % search_term)
    for result in results:
        item = boblist.process_item(result["item"])
        playlister = result["poster"]
        title = item["label"].lower()
        if search_term in title:
            item["info"] = {}
            try:
                item['label'] = '{0} - {1}'.format(playlister, item["label"])
            except:
                import xbmc
                xbmc.log("playlister: " + repr(playlister), xbmc.LOGDEBUG)
                xbmc.log("label:" + repr(item["lable"]), xbmc.LOGDEBUG)
                xbmc.log("item: " + repr(item), xbmc.LOGDEBUG)
                raise Exception()
            if title.startswith(search_term + " "):
                exact_result_list.append(item)
                exact_item_xml_result_list.append(result["item"])
                continue
            result_list.append(item)
            item_xml_result_list.append(result["item"])
    meta = xbmcaddon.Addon().getSetting("metadata") == "true"
    if meta:
        # TODO find way to get it all in single cal
        info = get_info(exact_item_xml_result_list)
        if info:
            for index, item in enumerate(exact_result_list):
                item["info"].update(info[index])

        info = get_info(item_xml_result_list)
        if info:
            for index, item in enumerate(result_list):
                item["info"].update(info[index])
    exact_result_list = sorted(exact_result_list, key=lambda item: title)
    exact_result_list.extend(sorted(result_list, key=lambda item: title))
    display_list(exact_result_list, "videos")