Beispiel #1
0
 def search_image(self, search_query, manual_select=False):
     '''
         search google images with the given query, returns first/best match
         optional parameter: manual_select (bool), will show selectdialog to allow manual select by user
     '''
     image = ""
     images_list = []
     for img in self.get_data(search_query):
         img = img.replace(" ", "%20")  # fix for spaces in url
         if xbmcvfs.exists(img):
             if not manual_select:
                 # just return the first image found (assuming that will be the best match)
                 return img
             else:
                 # manual lookup, list results and let user pick one
                 listitem = xbmcgui.ListItem(label=img, iconImage=img)
                 images_list.append(listitem)
     if manual_select and images_list:
         dialog = DialogSelect("DialogSelect.xml", "", listing=images_list, window_title="%s - Google"
                               % xbmc.getLocalizedString(283))
         dialog.doModal()
         selected_item = dialog.result
         del dialog
         if selected_item != -1:
             selected_item = images_list[selected_item]
             image = selected_item.getLabel().decode("utf-8")
     return image
Beispiel #2
0
 def search_image(self, search_query, manual_select=False):
     """
         search google images with the given query, returns first/best match
         optional parameter: manual_select (bool), will show selectdialog to allow manual select by user
     """
     image = ""
     images_list = []
     for img in self.get_data(search_query):
         img = img.replace(" ", "%20")  # fix for spaces in url
         if xbmcvfs.exists(img):
             if not manual_select:
                 # just return the first image found (assuming that will be the best match)
                 return img
             else:
                 # manual lookup, list results and let user pick one
                 listitem = xbmcgui.ListItem(label=img)
                 listitem.setArt({'icon': img})
                 images_list.append(listitem)
     if manual_select and images_list:
         dialog = DialogSelect("DialogSelect.xml",
                               "",
                               listing=images_list,
                               window_title="%s - Google" %
                               xbmc.getLocalizedString(283))
         dialog.doModal()
         selected_item = dialog.result
         del dialog
         if selected_item != -1:
             selected_item = images_list[selected_item]
             if sys.version_info.major == 3:
                 image = selected_item.getLabel()
             else:
                 image = selected_item.getLabel().decode("utf-8")
     return image
Beispiel #3
0
 def select_art(items, manual_select=False, art_type=""):
     '''select the preferred image from the list'''
     image = None
     if manual_select:
         # show selectdialog to manually select the item
         results_list = []
         # add none and browse entries
         listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(231), iconImage="DefaultAddonNone.png")
         results_list.append(listitem)
         listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(1030), iconImage="DefaultFolder.png")
         results_list.append(listitem)
         for item in items:
             labels = [item["contributedby"], item["dateadded"], item["language"], item["source"]]
             label = " / ".join(labels)
             listitem = xbmcgui.ListItem(label=label, iconImage=item["thumb"])
             results_list.append(listitem)
         if manual_select and results_list:
             dialog = DialogSelect("DialogSelect.xml", "", listing=results_list, window_title=art_type)
             dialog.doModal()
             selected_item = dialog.result
             del dialog
             if selected_item == 0:
                 image = ""
             if selected_item == 1:
                 # browse for image
                 dialog = xbmcgui.Dialog()
                 image = dialog.browse(2, xbmc.getLocalizedString(1030), 'files', mask='.gif').decode("utf-8")
                 del dialog
             elif selected_item > 1:
                 # user has selected an image from online results
                 image = items[selected_item - 2]["image"]
     elif items:
         # just grab the first item as best match
         image = items[0]["image"]
     return image
Beispiel #4
0
 def select_art(items, manual_select=False, art_type=""):
     """select the preferred image from the list"""
     image = None
     if manual_select:
         # show selectdialog to manually select the item
         results_list = []
         # add none and browse entries
         listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(231), iconImage="DefaultAddonNone.png")
         results_list.append(listitem)
         listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(1030), iconImage="DefaultFolder.png")
         results_list.append(listitem)
         for item in items:
             labels = [item["contributedby"], item["dateadded"], item["language"], item["source"]]
             label = " / ".join(labels)
             listitem = xbmcgui.ListItem(label=label, iconImage=item["thumb"])
             results_list.append(listitem)
         if manual_select and results_list:
             dialog = DialogSelect("DialogSelect.xml", "", listing=results_list, window_title=art_type)
             dialog.doModal()
             selected_item = dialog.result
             del dialog
             if selected_item == 0:
                 image = ""
             if selected_item == 1:
                 # browse for image
                 dialog = xbmcgui.Dialog()
                 image = dialog.browse(2, xbmc.getLocalizedString(1030), 'files', mask='.gif').decode("utf-8")
                 del dialog
             elif selected_item > 1:
                 # user has selected an image from online results
                 image = items[selected_item - 2]["image"]
     elif items:
         # just grab the first item as best match
         image = items[0]["image"]
     return image
 def lookup_tvdb(self, searchtitle, channel, manual_select=False):
     '''helper to select a match on tvdb'''
     tvdb_match = None
     searchtitle = searchtitle.lower()
     tvdb_result = self.artutils.thetvdb.search_series(searchtitle, True)
     searchchannel = channel.lower().split("hd")[0].replace(" ", "")
     match_results = []
     if tvdb_result:
         for item in tvdb_result:
             item["score"] = 0
             itemtitle = item["seriesName"].lower()
             network = item["network"].lower().replace(" ", "")
             # high score if channel name matches
             if network in searchchannel or searchchannel in network:
                 item["score"] += 800
             # exact match on title - very high score
             if searchtitle == itemtitle:
                 item["score"] += 1000
             # match title by replacing some characters
             if re.sub('\*|,|.\"|\'| |:|;', '', searchtitle) == re.sub('\*|,|.\"|\'| |:|;', '', itemtitle):
                 item["score"] += 750
             # add SequenceMatcher score to the results
             stringmatchscore = SM(None, searchtitle, itemtitle).ratio()
             if stringmatchscore > 0.7:
                 item["score"] += stringmatchscore * 500
             # prefer items with native language as we've searched with localized info enabled
             if item["overview"]:
                 item["score"] += 250
             # prefer items with artwork
             if item["banner"]:
                 item["score"] += 1
             if item["score"] > 500 or manual_select:
                 match_results.append(item)
         # sort our new list by score
         match_results = sorted(match_results, key=itemgetter("score"), reverse=True)
         if match_results and manual_select:
             # show selectdialog to manually select the item
             listitems = []
             for item in match_results:
                 thumb = "http://thetvdb.com/banners/%s" % item["banner"] if item["banner"] else ""
                 listitem = xbmcgui.ListItem(label=item["seriesName"], iconImage=thumb, label2=item["overview"])
                 listitems.append(listitem)
             dialog = DialogSelect(
                 "DialogSelect.xml",
                 "",
                 listing=listitems,
                 window_title="%s - TVDB" %
                 xbmc.getLocalizedString(283))
             dialog.doModal()
             selected_item = dialog.result
             del dialog
             if selected_item != -1:
                 tvdb_match = match_results[selected_item]["id"]
             else:
                 match_results = []
         if not tvdb_match and match_results:
             # just grab the first item as best match
             tvdb_match = match_results[0]["id"]
     return tvdb_match
    def select_best_match(results,
                          prefyear="",
                          preftype="",
                          preftitle="",
                          manual_select=False):
        '''helper to select best match or let the user manually select the best result from the search'''
        details = {}
        # score results if one or more preferences are given
        if results and (prefyear or preftype or preftitle):
            newdata = []
            preftitle = preftitle.lower()
            for item in results:
                item["score"] = 0
                itemtitle = item["title"] if item.get(
                    "title") else item["name"]
                itemtitle = itemtitle.lower()
                itemorgtitle = item["original_title"] if item.get(
                    "original_title") else item["original_name"]
                itemorgtitle = itemorgtitle.lower()

                # high score if year matches
                if prefyear:
                    if item.get("first_air_date"
                                ) and prefyear in item["first_air_date"]:
                        item["score"] += 800  # matches preferred year
                    if item.get("release_date"
                                ) and prefyear in item["release_date"]:
                        item["score"] += 800  # matches preferred year

                # find exact match on title
                if preftitle and preftitle == itemtitle:
                    item["score"] += 1000  # exact match!
                if preftitle and preftitle == itemorgtitle:
                    item["score"] += 1000  # exact match!

                # match title by replacing some characters
                if preftitle and get_compare_string(
                        preftitle) == get_compare_string(itemtitle):
                    item["score"] += 750
                if preftitle and get_compare_string(
                        preftitle) == get_compare_string(itemorgtitle):
                    item["score"] += 750

                # add SequenceMatcher score to the results
                if preftitle:
                    stringmatchscore = SM(
                        None, preftitle, itemtitle).ratio() + SM(
                            None, preftitle, itemorgtitle).ratio()
                    if stringmatchscore > 1.6:
                        item["score"] += stringmatchscore * 250

                # higher score if result ALSO matches our preferred type or native language
                # (only when we already have a score)
                if item["score"]:
                    if preftype and (item["media_type"] in preftype) or (
                            preftype in item["media_type"]):
                        item["score"] += 250  # matches preferred type
                    if item["original_language"] == KODI_LANGUAGE:
                        item["score"] += 500  # native language!
                    if KODI_LANGUAGE.upper() in item.get("origin_country", []):
                        item["score"] += 500  # native language!
                    if KODI_LANGUAGE in item.get("languages", []):
                        item["score"] += 500  # native language!

                if item["score"] > 500 or manual_select:
                    newdata.append(item)
            results = sorted(newdata, key=itemgetter("score"), reverse=True)

        if results and manual_select:
            # show selectdialog to manually select the item
            results_list = []
            for item in results:
                title = item["name"] if "name" in item else item["title"]
                if item.get("premiered"):
                    year = item["premiered"].split("-")[0]
                else:
                    year = item.get("first_air_date", "").split("-")[0]
                if item["poster_path"]:
                    thumb = "http://image.tmdb.org/t/p/original%s" % item[
                        "poster_path"]
                else:
                    thumb = ""
                label = "%s (%s) - %s" % (title, year, item["media_type"])
                listitem = xbmcgui.ListItem(label=label,
                                            iconImage=thumb,
                                            label2=item["overview"])
                results_list.append(listitem)
            if manual_select and results_list:
                dialog = DialogSelect("DialogSelect.xml",
                                      "",
                                      listing=results_list,
                                      window_title="%s - TMDB" %
                                      xbmc.getLocalizedString(283))
                dialog.doModal()
                selected_item = dialog.result
                del dialog
                if selected_item != -1:
                    details = results[selected_item]
                else:
                    results = []

        if not details and results:
            # just grab the first item as best match
            details = results[0]
        return details
 def lookup_tvdb(self,
                 searchtitle,
                 channel,
                 manual_select=False,
                 tempmanualselect=False):
     """helper to select a match on tvdb"""
     tvdb_match = None
     searchtitle = searchtitle.lower()
     tvdb_result = self._mutils.thetvdb.search_series(searchtitle, True)
     searchchannel = channel.lower().split("hd")[0].replace(" ", "")
     if " FHD" in channel:
         searchchannel = channel.lower().split("fhd")[0].replace(" ", "")
     if " HD" in channel:
         searchchannel = channel.lower().split("hd")[0].replace(" ", "")
     if " SD" in channel:
         searchchannel = channel.lower().split("sd")[0].replace(" ", "")
     match_results = []
     if tvdb_result:
         for item in tvdb_result:
             item["score"] = 0
             if not item["seriesName"]:
                 continue  # seriesname can be None in some conditions
             itemtitle = item["seriesName"].lower()
             if not item["network"]:
                 continue  # network can be None in some conditions
             network = item["network"].lower().replace(" ", "")
             # high score if channel name matches
             if network in searchchannel or searchchannel in network:
                 item["score"] += 800
             # exact match on title - very high score
             if searchtitle == itemtitle:
                 item["score"] += 1000
             # match title by replacing some characters
             if re.sub('\*|,|.\"|\'| |:|;', '',
                       searchtitle) == re.sub('\*|,|.\"|\'| |:|;', '',
                                              itemtitle):
                 item["score"] += 750
             # add SequenceMatcher score to the results
             stringmatchscore = SM(None, searchtitle, itemtitle).ratio()
             if stringmatchscore > 0.7:
                 item["score"] += stringmatchscore * 500
             # prefer items with native language as we've searched with localized info enabled
             try:
                 if item["overview"]:
                     item["score"] += 250
             except KeyError:
                 log_msg(
                     "pvrartwork.py - Overview Key Error in lookup_tvb: %s"
                     % searchchannel)
             # prefer items with artwork
             if item["banner"]:
                 item["score"] += 1
             if item["score"] > 500 or manual_select:
                 match_results.append(item)
         # sort our new list by score
         match_results = sorted(match_results,
                                key=itemgetter("score"),
                                reverse=True)
         # original code:  if match_results and manual_select:. part of "auto refresh" fix.
         if match_results and manual_select and tempmanualselect:
             # show selectdialog to manually select the item
             listitems = []
             for item in match_results:
                 thumb = "http://thetvdb.com%s" % item["poster"] if item[
                     "poster"] else ""
                 try:
                     listitem = xbmcgui.ListItem(label=item["seriesName"],
                                                 label2=item["overview"])
                 except KeyError:
                     listitem = xbmcgui.ListItem(label=item["seriesName"])
                     log_msg(
                         "pvrartwork.py - Overview Key Error in lookup_tvb: %s"
                         % searchchannel)
                 listitem.setArt({'icon': thumb})
                 listitems.append(listitem)
             dialog = DialogSelect("DialogSelect.xml",
                                   "",
                                   listing=listitems,
                                   window_title="%s - TVDB" %
                                   xbmc.getLocalizedString(283))
             dialog.doModal()
             selected_item = dialog.result
             del dialog
             if selected_item != -1:
                 tvdb_match = match_results[selected_item]["id"]
             else:
                 match_results = []
         if not tvdb_match and match_results:
             # just grab the first item as best match
             tvdb_match = match_results[0]["id"]
     return tvdb_match
Beispiel #8
0
    def select_best_match(results, prefyear="", preftype="", preftitle="", manual_select=False):
        '''helper to select best match or let the user manually select the best result from the search'''
        details = {}
        # score results if one or more preferences are given
        if results and (prefyear or preftype or preftitle):
            newdata = []
            preftitle = preftitle.lower()
            for item in results:
                item["score"] = 0
                itemtitle = item["title"] if item.get("title") else item["name"]
                itemtitle = itemtitle.lower()
                itemorgtitle = item["original_title"] if item.get("original_title") else item["original_name"]
                itemorgtitle = itemorgtitle.lower()

                # high score if year matches
                if prefyear:
                    if item.get("first_air_date") and prefyear in item["first_air_date"]:
                        item["score"] += 800  # matches preferred year
                    if item.get("release_date") and prefyear in item["release_date"]:
                        item["score"] += 800  # matches preferred year

                # find exact match on title
                if preftitle and preftitle == itemtitle:
                    item["score"] += 1000  # exact match!
                if preftitle and preftitle == itemorgtitle:
                    item["score"] += 1000  # exact match!

                # match title by replacing some characters
                if preftitle and get_compare_string(preftitle) == get_compare_string(itemtitle):
                    item["score"] += 750
                if preftitle and get_compare_string(preftitle) == get_compare_string(itemorgtitle):
                    item["score"] += 750

                # add SequenceMatcher score to the results
                if preftitle:
                    stringmatchscore = SM(None, preftitle, itemtitle).ratio(
                    ) + SM(None, preftitle, itemorgtitle).ratio()
                    if stringmatchscore > 1.6:
                        item["score"] += stringmatchscore * 250

                # higher score if result ALSO matches our preferred type or native language
                # (only when we already have a score)
                if item["score"]:
                    if preftype and (item["media_type"] in preftype) or (preftype in item["media_type"]):
                        item["score"] += 250  # matches preferred type
                    if item["original_language"] == KODI_LANGUAGE:
                        item["score"] += 500  # native language!
                    if KODI_LANGUAGE.upper() in item.get("origin_country", []):
                        item["score"] += 500  # native language!
                    if KODI_LANGUAGE in item.get("languages", []):
                        item["score"] += 500  # native language!

                if item["score"] > 500 or manual_select:
                    newdata.append(item)
            results = sorted(newdata, key=itemgetter("score"), reverse=True)

        if results and manual_select:
            # show selectdialog to manually select the item
            results_list = []
            for item in results:
                title = item["name"] if "name" in item else item["title"]
                if item.get("premiered"):
                    year = item["premiered"].split("-")[0]
                else:
                    year = item.get("first_air_date", "").split("-")[0]
                if item["poster_path"]:
                    thumb = "http://image.tmdb.org/t/p/original%s" % item["poster_path"]
                else:
                    thumb = ""
                label = "%s (%s) - %s" % (title, year, item["media_type"])
                listitem = xbmcgui.ListItem(label=label, iconImage=thumb, label2=item["overview"])
                results_list.append(listitem)
            if manual_select and results_list:
                dialog = DialogSelect("DialogSelect.xml", "", listing=results_list, window_title="%s - TMDB"
                                      % xbmc.getLocalizedString(283))
                dialog.doModal()
                selected_item = dialog.result
                del dialog
                if selected_item != -1:
                    details = results[selected_item]
                else:
                    results = []

        if not details and results:
            # just grab the first item as best match
            details = results[0]
        return details
    def manual_set_pvr_artwork(self, title, channel, genre):
        '''manual override artwork options'''

        artwork = self.get_pvr_artwork(title, channel, genre)
        cache_str = artwork["cachestr"]

        # show dialogselect with all artwork options
        abort = False
        while not abort:
            listitems = []
            for arttype in ["thumb", "poster", "fanart", "banner", "clearart", "clearlogo",
                            "discart", "landscape", "characterart"]:
                listitem = xbmcgui.ListItem(label=arttype, iconImage=artwork["art"].get(arttype, ""))
                listitem.setProperty("icon", artwork["art"].get(arttype, ""))
                listitems.append(listitem)
            dialog = DialogSelect("DialogSelect.xml", "", listing=listitems,
                                  windowtitle=xbmc.getLocalizedString(13511), multiselect=False)
            dialog.doModal()
            selected_item = dialog.result
            del dialog
            if selected_item == -1:
                abort = True
            else:
                # show results for selected art type
                artoptions = []
                selected_item = listitems[selected_item]
                image = selected_item.getProperty("icon").decode("utf-8")
                label = selected_item.getLabel().decode("utf-8")
                heading = "%s: %s" % (xbmc.getLocalizedString(13511), label)
                if image:
                    # current image
                    listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(13512), iconImage=image)
                    listitem.setProperty("icon", image)
                    artoptions.append(listitem)
                    # none option
                    listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(231), iconImage="DefaultAddonNone.png")
                    listitem.setProperty("icon", "DefaultAddonNone.png")
                    artoptions.append(listitem)
                # browse option
                listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(1024), iconImage="DefaultFolder.png")
                listitem.setProperty("icon", "DefaultFolder.png")
                artoptions.append(listitem)

                # add remaining images as option
                allarts = artwork["art"].get(label + "s", [])
                if len(allarts) > 1:
                    for item in allarts:
                        listitem = xbmcgui.ListItem(label=item, iconImage=item)
                        listitem.setProperty("icon", item)
                        artoptions.append(listitem)

                dialog = DialogSelect("DialogSelect.xml", "", listing=artoptions, window_title=heading)
                dialog.doModal()
                selected_item = dialog.result
                del dialog
                if image and selected_item == 1:
                    artwork["art"][label] = ""
                elif image and selected_item > 2:
                    artwork["art"][label] = artoptions[selected_item].getProperty("icon").decode("utf-8")
                elif (image and selected_item == 2) or not image and selected_item == 0:
                    # manual browse...
                    dialog = xbmcgui.Dialog()
                    image = dialog.browse(2, xbmc.getLocalizedString(1030),
                                          'files', mask='.gif|.png|.jpg').decode("utf-8")
                    del dialog
                    if image:
                        artwork["art"][label] = image

        # save results in cache
        self.artutils.cache.set(cache_str, artwork, expiration=timedelta(days=120))
Beispiel #10
0
 def lookup_tvdb(self, searchtitle, channel, manual_select=False):
     '''helper to select a match on tvdb'''
     tvdb_match = None
     searchtitle = searchtitle.lower()
     tvdb_result = self.metadatautils.thetvdb.search_series(searchtitle, True)
     searchchannel = channel.lower().split("hd")[0].replace(" ", "")
     match_results = []
     if tvdb_result:
         for item in tvdb_result:
             item["score"] = 0
             if not item["seriesName"]:
                 continue  # seriesname can be None in some conditions
             itemtitle = item["seriesName"].lower()
             network = item["network"].lower().replace(" ", "")
             # high score if channel name matches
             if network in searchchannel or searchchannel in network:
                 item["score"] += 800
             # exact match on title - very high score
             if searchtitle == itemtitle:
                 item["score"] += 1000
             # match title by replacing some characters
             if re.sub('\*|,|.\"|\'| |:|;', '', searchtitle) == re.sub('\*|,|.\"|\'| |:|;', '', itemtitle):
                 item["score"] += 750
             # add SequenceMatcher score to the results
             stringmatchscore = SM(None, searchtitle, itemtitle).ratio()
             if stringmatchscore > 0.7:
                 item["score"] += stringmatchscore * 500
             # prefer items with native language as we've searched with localized info enabled
             if item["overview"]:
                 item["score"] += 250
             # prefer items with artwork
             if item["banner"]:
                 item["score"] += 1
             if item["score"] > 500 or manual_select:
                 match_results.append(item)
         # sort our new list by score
         match_results = sorted(match_results, key=itemgetter("score"), reverse=True)
         if match_results and manual_select:
             # show selectdialog to manually select the item
             listitems = []
             for item in match_results:
                 thumb = "http://thetvdb.com/banners/%s" % item["banner"] if item["banner"] else ""
                 listitem = xbmcgui.ListItem(label=item["seriesName"], iconImage=thumb, label2=item["overview"])
                 listitems.append(listitem)
             dialog = DialogSelect(
                 "DialogSelect.xml",
                 "",
                 listing=listitems,
                 window_title="%s - TVDB" %
                 xbmc.getLocalizedString(283))
             dialog.doModal()
             selected_item = dialog.result
             del dialog
             if selected_item != -1:
                 tvdb_match = match_results[selected_item]["id"]
             else:
                 match_results = []
         if not tvdb_match and match_results:
             # just grab the first item as best match
             tvdb_match = match_results[0]["id"]
     return tvdb_match