Exemple #1
0
 def album_info(self, album_id):
     '''get album metadata by musicbrainz id'''
     details = {"art": {}}
     data = self.get_data("/album-mb.php", {'i': album_id})
     if data and data.get("album"):
         adbdetails = data["album"][0]
         if adbdetails.get("strAlbumThumb") and xbmcvfs.exists(adbdetails.get("strAlbumThumb")):
             details["art"]["thumb"] = adbdetails.get("strAlbumThumb")
             details["art"]["thumbs"] = [adbdetails.get("strAlbumThumb")]
         if adbdetails.get("strAlbumCDart") and xbmcvfs.exists(adbdetails.get("strAlbumCDart")):
             details["art"]["discart"] = adbdetails.get("strAlbumCDart")
             details["art"]["discarts"] = [adbdetails.get("strAlbumCDart")]
         if adbdetails.get("strAlbumSpine") and xbmcvfs.exists(adbdetails.get("strAlbumSpine")):
             details["art"]["spine"] = adbdetails.get("strAlbumSpine")
         if adbdetails.get("strAlbumThumbBack") and xbmcvfs.exists(adbdetails.get("strAlbumThumbBack")):
             details["art"]["thumbback"] = adbdetails.get("strAlbumThumbBack")
         if adbdetails.get("strDescription%s" % KODI_LANGUAGE.upper()):
             details["plot"] = adbdetails.get("strDescription%s" % KODI_LANGUAGE.upper())
         if not details.get("plot") and adbdetails.get("strDescriptionEN"):
             details["plot"] = adbdetails.get("strDescriptionEN")
         if details.get("plot"):
             details["plot"] = strip_newlines(details["plot"])
         if adbdetails.get("strGenre"):
             details["genre"] = adbdetails["strGenre"].split("/")
         if adbdetails.get("strStyle"):
             details["style"] = adbdetails["strStyle"].split("/")
         if adbdetails.get("strMood"):
             details["mood"] = adbdetails["strMood"].split("/")
         if adbdetails.get("intYearReleased"):
             details["year"] = adbdetails["intYearReleased"]
         if adbdetails.get("intScore"):
             details["rating"] = adbdetails["intScore"]
         if adbdetails.get("strAlbum"):
             details["title"] = adbdetails["strAlbum"]
     return details
Exemple #2
0
 def album_info(self, album_id):
     '''get album metadata by musicbrainz id'''
     details = {"art": {}}
     data = self.get_data("/album-mb.php", {'i': album_id})
     if data and data.get("album"):
         adbdetails = data["album"][0]
         if adbdetails.get("strAlbumThumb") and xbmcvfs.exists(
                 adbdetails.get("strAlbumThumb")):
             details["art"]["thumb"] = adbdetails.get("strAlbumThumb")
             details["art"]["thumbs"] = [adbdetails.get("strAlbumThumb")]
         if adbdetails.get("strAlbumCDart") and xbmcvfs.exists(
                 adbdetails.get("strAlbumCDart")):
             details["art"]["discart"] = adbdetails.get("strAlbumCDart")
             details["art"]["discarts"] = [adbdetails.get("strAlbumCDart")]
         if adbdetails.get("strDescription%s" % KODI_LANGUAGE.upper()):
             details["plot"] = adbdetails.get("strDescription%s" %
                                              KODI_LANGUAGE.upper())
         if not details.get("plot") and adbdetails.get("strDescriptionEN"):
             details["plot"] = adbdetails.get("strDescriptionEN")
         if details.get("plot"):
             details["plot"] = strip_newlines(details["plot"])
         if adbdetails.get("strGenre"):
             details["genre"] = adbdetails["strGenre"].split("/")
         if adbdetails.get("strStyle"):
             details["style"] = adbdetails["strStyle"].split("/")
         if adbdetails.get("strMood"):
             details["mood"] = adbdetails["strMood"].split("/")
         if adbdetails.get("intYearReleased"):
             details["year"] = adbdetails["intYearReleased"]
         if adbdetails.get("intScore"):
             details["rating"] = adbdetails["intScore"]
         if adbdetails.get("strAlbum"):
             details["title"] = adbdetails["strAlbum"]
     return details
Exemple #3
0
 def artist_info(self, artist_id):
     '''get artist metadata by musicbrainz id'''
     details = {"art": {}}
     data = self.get_data("/artist-mb.php", {'i': artist_id})
     if data and data.get("artists"):
         adbdetails = data["artists"][0]
         if adbdetails.get("strArtistBanner") and xbmcvfs.exists(adbdetails.get("strArtistBanner")):
             details["art"]["banner"] = adbdetails.get("strArtistBanner")
             details["art"]["banners"] = [adbdetails.get("strArtistBanner")]
         details["art"]["fanarts"] = []
         if adbdetails.get("strArtistFanart") and xbmcvfs.exists(adbdetails.get("strArtistFanart")):
             details["art"]["fanart"] = adbdetails.get("strArtistFanart")
             details["art"]["fanarts"].append(adbdetails.get("strArtistFanart"))
         if adbdetails.get("strArtistFanart2") and xbmcvfs.exists(adbdetails.get("strArtistFanart2")):
             details["art"]["fanarts"].append(adbdetails.get("strArtistFanart2"))
         if adbdetails.get("strArtistFanart3") and xbmcvfs.exists(adbdetails.get("strArtistFanart3")):
             details["art"]["fanarts"].append(adbdetails.get("strArtistFanart3"))
         if adbdetails.get("strArtistLogo") and xbmcvfs.exists(adbdetails.get("strArtistLogo")):
             details["art"]["clearlogo"] = adbdetails.get("strArtistLogo")
             details["art"]["clearlogos"] = [adbdetails.get("strArtistLogo")]
         if adbdetails.get("strArtistThumb") and xbmcvfs.exists(adbdetails.get("strArtistThumb")):
             details["art"]["thumb"] = adbdetails["strArtistThumb"]
             details["art"]["thumbs"] = [adbdetails["strArtistThumb"]]
         if adbdetails.get("strBiography" + KODI_LANGUAGE.upper()):
             details["plot"] = adbdetails["strBiography" + KODI_LANGUAGE.upper()]
         if adbdetails.get("strBiographyEN") and not details.get("plot"):
             details["plot"] = adbdetails.get("strBiographyEN")
         if details.get("plot"):
             details["plot"] = strip_newlines(details["plot"])
         if adbdetails.get("strArtistAlternate"):
             details["alternamename"] = adbdetails["strArtistAlternate"]
         if adbdetails.get("intFormedYear"):
             details["formed"] = adbdetails["intFormedYear"]
         if adbdetails.get("intBornYear"):
             details["born"] = adbdetails["intBornYear"]
         if adbdetails.get("intDiedYear"):
             details["died"] = adbdetails["intDiedYear"]
         if adbdetails.get("strDisbanded"):
             details["disbanded"] = adbdetails["strDisbanded"]
         if adbdetails.get("strStyle"):
             details["style"] = adbdetails["strStyle"].split("/")
         if adbdetails.get("strGenre"):
             details["genre"] = adbdetails["strGenre"].split("/")
         if adbdetails.get("strMood"):
             details["mood"] = adbdetails["strMood"].split("/")
         if adbdetails.get("strWebsite"):
             details["homepage"] = adbdetails["strWebsite"]
         if adbdetails.get("strFacebook"):
             details["facebook"] = adbdetails["strFacebook"]
         if adbdetails.get("strTwitter"):
             details["twitter"] = adbdetails["strTwitter"]
         if adbdetails.get("strGender"):
             details["gender"] = adbdetails["strGender"]
         if adbdetails.get("intMembers"):
             details["members"] = adbdetails["intMembers"]
         if adbdetails.get("strCountry"):
             details["country"] = adbdetails["strCountry"].split(", ")
     return details
    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 artist_info(self, artist):
     """get artist metadata by artist"""
     details = {"art": {}}
     data = self.get_data("/search.php", {'s': artist})
     if data and data.get("artists"):
         adbdetails = data["artists"][0]
         if adbdetails.get("strArtistBanner") and xbmcvfs.exists(
                 adbdetails.get("strArtistBanner")):
             details["art"]["banner"] = adbdetails.get("strArtistBanner")
             details["art"]["banners"] = [adbdetails.get("strArtistBanner")]
         details["art"]["fanarts"] = []
         if adbdetails.get("strArtistFanart") and xbmcvfs.exists(
                 adbdetails.get("strArtistFanart")):
             details["art"]["fanart"] = adbdetails.get("strArtistFanart")
             details["art"]["fanarts"].append(
                 adbdetails.get("strArtistFanart"))
         if adbdetails.get("strArtistFanart2") and xbmcvfs.exists(
                 adbdetails.get("strArtistFanart2")):
             details["art"]["fanarts"].append(
                 adbdetails.get("strArtistFanart2"))
         if adbdetails.get("strArtistFanart3") and xbmcvfs.exists(
                 adbdetails.get("strArtistFanart3")):
             details["art"]["fanarts"].append(
                 adbdetails.get("strArtistFanart3"))
         if adbdetails.get("strArtistWideThumb") and xbmcvfs.exists(
                 adbdetails.get("strArtistWideThumb")):
             details["art"]["landscape"] = adbdetails.get(
                 "strArtistWideThumb")
         if adbdetails.get("strArtistLogo") and xbmcvfs.exists(
                 adbdetails.get("strArtistLogo")):
             details["art"]["clearlogo"] = adbdetails.get("strArtistLogo")
             details["art"]["clearlogos"] = [
                 adbdetails.get("strArtistLogo")
             ]
         if adbdetails.get("strArtistClearart") and xbmcvfs.exists(
                 adbdetails.get("strArtistClearart")):
             details["art"]["clearart"] = adbdetails.get(
                 "strArtistClearart")
             details["art"]["cleararts"] = [
                 adbdetails.get("strArtistClearart")
             ]
         if adbdetails.get("strArtistThumb") and xbmcvfs.exists(
                 adbdetails.get("strArtistThumb")):
             details["art"]["thumb"] = adbdetails["strArtistThumb"]
             details["art"]["thumbs"] = [adbdetails["strArtistThumb"]]
         if adbdetails.get("strBiography" + KODI_LANGUAGE.upper()):
             details["plot"] = adbdetails["strBiography" +
                                          KODI_LANGUAGE.upper()]
         if adbdetails.get("strBiographyEN") and not details.get("plot"):
             details["plot"] = adbdetails.get("strBiographyEN")
         if details.get("plot"):
             details["plot"] = strip_newlines(details["plot"])
         if adbdetails.get("strArtistAlternate"):
             details["alternamename"] = adbdetails["strArtistAlternate"]
         if adbdetails.get("intFormedYear"):
             details["formed"] = adbdetails["intFormedYear"]
         if adbdetails.get("intBornYear"):
             details["born"] = adbdetails["intBornYear"]
         if adbdetails.get("intDiedYear"):
             details["died"] = adbdetails["intDiedYear"]
         if adbdetails.get("strDisbanded"):
             details["disbanded"] = adbdetails["strDisbanded"]
         if adbdetails.get("strStyle"):
             details["style"] = adbdetails["strStyle"].split("/")
         if adbdetails.get("strGenre"):
             details["genre"] = adbdetails["strGenre"].split("/")
         if adbdetails.get("strMood"):
             details["mood"] = adbdetails["strMood"].split("/")
         if adbdetails.get("strWebsite"):
             details["homepage"] = adbdetails["strWebsite"]
         if adbdetails.get("strFacebook"):
             details["facebook"] = adbdetails["strFacebook"]
         if adbdetails.get("strTwitter"):
             details["twitter"] = adbdetails["strTwitter"]
         if adbdetails.get("strGender"):
             details["gender"] = adbdetails["strGender"]
         if adbdetails.get("intMembers"):
             details["members"] = adbdetails["intMembers"]
         if adbdetails.get("strCountry"):
             details["country"] = adbdetails["strCountry"].split(", ")
     return details
 def album_info(self, artist, album):
     """get album metadata by name"""
     details = {"art": {}}
     data = self.get_data("/searchalbum.php", {'s': artist, 'a': album})
     if data and data.get("album"):
         adbdetails = data["album"][0]
         if adbdetails.get("strAlbumThumb") and xbmcvfs.exists(
                 adbdetails.get("strAlbumThumb")):
             details["art"]["thumb"] = adbdetails.get("strAlbumThumb")
             details["art"]["thumbs"] = [adbdetails.get("strAlbumThumb")]
         if adbdetails.get("strAlbumCDart") and xbmcvfs.exists(
                 adbdetails.get("strAlbumCDart")):
             details["art"]["discart"] = adbdetails.get("strAlbumCDart")
             details["art"]["discarts"] = [adbdetails.get("strAlbumCDart")]
         if adbdetails.get("strAlbumSpine") and xbmcvfs.exists(
                 adbdetails.get("strAlbumSpine")):
             details["art"]["spine"] = adbdetails.get("strAlbumSpine")
         if adbdetails.get("strAlbumThumbBack") and xbmcvfs.exists(
                 adbdetails.get("strAlbumThumbBack")):
             details["art"]["thumbback"] = adbdetails.get(
                 "strAlbumThumbBack")
         if adbdetails.get("strAlbum3DCase") and xbmcvfs.exists(
                 adbdetails.get("strAlbum3DCase")):
             details["art"]["album3Dcase"] = adbdetails.get(
                 "strAlbum3DCase")
         if adbdetails.get("strAlbum3DFlat") and xbmcvfs.exists(
                 adbdetails.get("strAlbum3DFlat")):
             details["art"]["album3Dflat"] = adbdetails.get(
                 "strAlbum3DFlat")
         if adbdetails.get("strAlbum3DFace") and xbmcvfs.exists(
                 adbdetails.get("strAlbum3DFace")):
             details["art"]["album3Dface"] = adbdetails.get(
                 "strAlbum3DFace")
         if adbdetails.get("strAlbum3DThumb") and xbmcvfs.exists(
                 adbdetails.get("strAlbum3DThumb")):
             details["art"]["album3Dthumb"] = adbdetails.get(
                 "strAlbum3DThumb")
         if adbdetails.get("strDescription%s" % KODI_LANGUAGE.upper()):
             details["plot"] = adbdetails.get("strDescription%s" %
                                              KODI_LANGUAGE.upper())
         if not details.get("plot") and adbdetails.get("strDescriptionEN"):
             details["plot"] = adbdetails.get("strDescriptionEN")
         if details.get("plot"):
             details["plot"] = strip_newlines(details["plot"])
         if adbdetails.get("strGenre"):
             details["genre"] = adbdetails["strGenre"].split("/")
         if adbdetails.get("strStyle"):
             details["style"] = adbdetails["strStyle"].split("/")
         if adbdetails.get("strMood"):
             details["mood"] = adbdetails["strMood"].split("/")
         if adbdetails.get("intYearReleased"):
             details["year"] = adbdetails["intYearReleased"]
         if adbdetails.get("intScore"):
             details["rating"] = adbdetails["intScore"]
         if adbdetails.get("strAlbum"):
             details["title"] = adbdetails["strAlbum"]
         if adbdetails.get("strLabel"):
             details["albumlabel"] = adbdetails["strLabel"]
         if adbdetails.get("idAlbum"):
             details["idalbum"] = adbdetails["idAlbum"]
             if adbdetails.get("idAlbum"):
                 idalbum = adbdetails.get("idAlbum", "")
                 data = self.get_data("/track.php", {'m': idalbum})
                 adbtrackdetails = data["track"]
                 if data.get("track"):
                     tracks = []
                     for count, item in enumerate(adbtrackdetails):
                         tracks.append(item["strTrack"])
                         details["tracks.formatted.%s" % count] = item[
                             "intTrackNumber"] + "." + item["strTrack"]
                         details["tracks.clean.formatted.%s" %
                                 count] = item["strTrack"]
                     details["tracks.formatted"] = "[CR]".join(tracks)
     return details
Exemple #7
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