Example #1
0
 def get_similar_movies(self, dbid):
     """
     get list of movies from db which are similar to movie with *dbid
     based on metadata-centric ranking
     """
     movie = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                               params={"properties": ["genre", "director", "country", "year", "mpaa"], "movieid": dbid})
     if "moviedetails" not in movie['result']:
         return []
     comp_movie = movie['result']['moviedetails']
     genres = comp_movie['genre']
     data = kodijson.get_json(method="VideoLibrary.GetMovies",
                              params={"properties": ["genre", "director", "mpaa", "country", "year"], "sort": {"method": "random"}})
     if "movies" not in data['result']:
         return []
     quotalist = []
     for item in data['result']['movies']:
         item["mediatype"] = "movie"
         diff = abs(int(item['year']) - int(comp_movie['year']))
         hit = 0.0
         miss = 0.00001
         quota = 0.0
         for genre in genres:
             if genre in item['genre']:
                 hit += 1.0
             else:
                 miss += 1.0
         if hit > 0.0:
             quota = float(hit) / float(hit + miss)
         if genres and item['genre'] and genres[0] == item['genre'][0]:
             quota += 0.3
         if diff < 3:
             quota += 0.3
         elif diff < 6:
             quota += 0.15
         if comp_movie['country'] and item['country'] and comp_movie['country'][0] == item['country'][0]:
             quota += 0.4
         if comp_movie['mpaa'] and item['mpaa'] and comp_movie['mpaa'] == item['mpaa']:
             quota += 0.4
         if comp_movie['director'] and item['director'] and comp_movie['director'][0] == item['director'][0]:
             quota += 0.6
         quotalist.append((quota, item["movieid"]))
     quotalist = sorted(quotalist,
                        key=lambda quota: quota[0],
                        reverse=True)
     movies = ItemList(content_type="movies")
     for i, list_movie in enumerate(quotalist):
         if comp_movie['movieid'] is not list_movie[1]:
             newmovie = self.get_movie(list_movie[1])
             movies.append(newmovie)
             if i == 20:
                 break
     return movies
Example #2
0
 def get_set_name(self, dbid):
     """
     get name of set for movie with *dbid
     """
     data = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                              params={"properties": ["setid"], "movieid": dbid})
     if "result" not in data or "moviedetails" not in data["result"]:
         return None
     set_dbid = data['result']['moviedetails'].get('setid')
     if set_dbid:
         data = kodijson.get_json(method="VideoLibrary.GetMovieSetDetails",
                                  params={"setid": set_dbid})
         return data['result']['setdetails'].get('label')
Example #3
0
 def get_imdb_id(self, media_type, dbid):
     if not dbid:
         return None
     if media_type == "movie":
         data = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                                  params={"properties": ["imdbnumber", "title", "year"], "movieid": int(dbid)})
         if "result" in data and "moviedetails" in data["result"]:
             return data['result']['moviedetails']['imdbnumber']
     elif media_type == "tvshow":
         data = kodijson.get_json(method="VideoLibrary.GetTVShowDetails",
                                  params={"properties": ["imdbnumber", "title", "year"], "tvshowid": int(dbid)})
         if "result" in data and "tvshowdetails" in data["result"]:
             return data['result']['tvshowdetails']['imdbnumber']
     return None
Example #4
0
 def get_set_name(self, dbid):
     """
     get name of set for movie with *dbid
     """
     data = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                              params={
                                  "properties": ["setid"],
                                  "movieid": dbid
                              })
     if "result" not in data or "moviedetails" not in data["result"]:
         return None
     set_dbid = data['result']['moviedetails'].get('setid')
     if set_dbid:
         data = kodijson.get_json(method="VideoLibrary.GetMovieSetDetails",
                                  params={"setid": set_dbid})
         return data['result']['setdetails'].get('label')
Example #5
0
 def get_artist_mbid(self, dbid):
     """
     get mbid of artist with *dbid
     """
     data = kodijson.get_json(method="MusicLibrary.GetArtistDetails",
                              params={"properties": ["musicbrainzartistid"], "artistid": dbid})
     mbid = data['result']['artistdetails'].get('musicbrainzartistid')
     return mbid if mbid else None
Example #6
0
 def get_movie(self, movie_id):
     """
     get info from db for movie with *movie_id
     """
     response = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                                  params={"properties": MOVIE_PROPS, "movieid": movie_id})
     if "result" in response and "moviedetails" in response["result"]:
         return self.handle_movie(response["result"]["moviedetails"])
     return {}
Example #7
0
 def get_albums(self):
     """
     get a list of all albums from db
     """
     data = kodijson.get_json(method="AudioLibrary.GetAlbums",
                              params={"properties": ["title"]})
     if "result" not in data or "albums" not in data['result']:
         return []
     return data['result']['albums']
Example #8
0
 def get_tvshow(self, tvshow_id):
     """
     get info from db for tvshow with *tvshow_id
     """
     response = kodijson.get_json(method="VideoLibrary.GetTVShowDetails",
                                  params={"properties": TV_PROPS, "tvshowid": tvshow_id})
     if "result" in response and "tvshowdetails" in response["result"]:
         return self.handle_tvshow(response["result"]["tvshowdetails"])
     return {}
Example #9
0
 def get_tvshow_id_by_episode(self, dbid):
     if not dbid:
         return None
     data = kodijson.get_json(method="VideoLibrary.GetEpisodeDetails",
                              params={"properties": ["tvshowid"], "episodeid": dbid})
     if "episodedetails" not in data["result"]:
         return None
     return self.get_imdb_id(media_type="tvshow",
                             dbid=str(data['result']['episodedetails']['tvshowid']))
Example #10
0
 def get_albums(self):
     """
     get a list of all albums from db
     """
     data = kodijson.get_json(method="AudioLibrary.GetAlbums",
                              params={"properties": ["title"]})
     if "result" not in data or "albums" not in data['result']:
         return []
     return data['result']['albums']
Example #11
0
 def get_tvshows(self, limit=10):
     """
     get list of tvshows with length *limit from db
     """
     data = kodijson.get_json(method="VideoLibrary.GetTVShows",
                              params={"properties": TV_PROPS, "limits": {"end": limit}})
     if "result" not in data or "tvshows" not in data["result"]:
         return []
     return ItemList(content_type="movies",
                     items=[self.handle_tvshow(item) for item in data["result"]["tvshows"]])
Example #12
0
 def get_artist_mbid(self, dbid):
     """
     get mbid of artist with *dbid
     """
     data = kodijson.get_json(method="MusicLibrary.GetArtistDetails",
                              params={
                                  "properties": ["musicbrainzartistid"],
                                  "artistid": dbid
                              })
     mbid = data['result']['artistdetails'].get('musicbrainzartistid')
     return mbid if mbid else None
Example #13
0
 def get_movie(self, movie_id):
     """
     get info from db for movie with *movie_id
     """
     response = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                                  params={
                                      "properties": MOVIE_PROPS,
                                      "movieid": movie_id
                                  })
     if "result" in response and "moviedetails" in response["result"]:
         return self.handle_movie(response["result"]["moviedetails"])
     return {}
Example #14
0
 def get_tvshow(self, tvshow_id):
     """
     get info from db for tvshow with *tvshow_id
     """
     response = kodijson.get_json(method="VideoLibrary.GetTVShowDetails",
                                  params={
                                      "properties": TV_PROPS,
                                      "tvshowid": tvshow_id
                                  })
     if "result" in response and "tvshowdetails" in response["result"]:
         return self.handle_tvshow(response["result"]["tvshowdetails"])
     return {}
Example #15
0
 def get_tvshow_id_by_episode(self, dbid):
     if not dbid:
         return None
     data = kodijson.get_json(method="VideoLibrary.GetEpisodeDetails",
                              params={
                                  "properties": ["tvshowid"],
                                  "episodeid": dbid
                              })
     if "episodedetails" not in data["result"]:
         return None
     return self.get_imdb_id(
         media_type="tvshow",
         dbid=str(data['result']['episodedetails']['tvshowid']))
Example #16
0
 def get_imdb_id(self, media_type, dbid):
     if not dbid:
         return None
     if media_type == "movie":
         data = kodijson.get_json(method="VideoLibrary.GetMovieDetails",
                                  params={
                                      "properties":
                                      ["imdbnumber", "title", "year"],
                                      "movieid":
                                      int(dbid)
                                  })
         if "result" in data and "moviedetails" in data["result"]:
             return data['result']['moviedetails']['imdbnumber']
     elif media_type == "tvshow":
         data = kodijson.get_json(method="VideoLibrary.GetTVShowDetails",
                                  params={
                                      "properties":
                                      ["imdbnumber", "title", "year"],
                                      "tvshowid":
                                      int(dbid)
                                  })
         if "result" in data and "tvshowdetails" in data["result"]:
             return data['result']['tvshowdetails']['imdbnumber']
     return None
Example #17
0
 def get_tvshows(self, limit=10):
     """
     get list of tvshows with length *limit from db
     """
     data = kodijson.get_json(method="VideoLibrary.GetTVShows",
                              params={
                                  "properties": TV_PROPS,
                                  "limits": {
                                      "end": limit
                                  }
                              })
     if "result" not in data or "tvshows" not in data["result"]:
         return []
     return ItemList(content_type="movies",
                     items=[
                         self.handle_tvshow(item)
                         for item in data["result"]["tvshows"]
                     ])
Example #18
0
 def compare_album_with_library(self, online_list):
     """
     merge *albums from online sources with local db info
     """
     if not self.albums:
         self.albums = self.get_albums()
     for item in online_list:
         for local_item in self.albums:
             if not item.get_info("title") == local_item["title"]:
                 continue
             data = kodijson.get_json(method="AudioLibrary.getAlbumDetails",
                                      params={"properties": ["thumbnail"], "albumid": local_item["albumid"]})
             album = data["result"]["albumdetails"]
             item.set_info("dbid", album["albumid"])
             item.set_path(PLUGIN_BASE + 'playalbum&&dbid=%i' % album['albumid'])
             if album["thumbnail"]:
                 item.update_artwork({"thumb": album["thumbnail"]})
             break
     return online_list
Example #19
0
 def get_similar_artists(self, artist_id):
     """
     get list of artists from db which are similar to artist with *artist_id
     based on LastFM online data
     """
     import LastFM
     simi_artists = LastFM.get_similar_artists(artist_id)
     if simi_artists is None:
         utils.log('Last.fm didn\'t return proper response')
         return None
     if not self.artists:
         self.artists = self.get_artists()
     artists = ItemList(content_type="artists")
     for simi_artist, kodi_artist in itertools.product(simi_artists, self.artists):
         if kodi_artist['musicbrainzartistid'] and kodi_artist['musicbrainzartistid'] == simi_artist['mbid']:
             artists.append(kodi_artist)
         elif kodi_artist['artist'] == simi_artist['name']:
             data = kodijson.get_json(method="AudioLibrary.GetArtistDetails",
                                      params={"properties": ["genre", "description", "mood", "style", "born", "died", "formed", "disbanded", "yearsactive", "instrument", "fanart", "thumbnail"], "artistid": kodi_artist['artistid']})
             item = data["result"]["artistdetails"]
             artwork = {"thumb": item['thumbnail'],
                        "fanart": item['fanart']}
             artists.append({"label": item['label'],
                             "artwork": artwork,
                             "title": item['label'],
                             "genre": " / ".join(item['genre']),
                             "artist_description": item['description'],
                             "userrating": item['userrating'],
                             "born": item['born'],
                             "died": item['died'],
                             "formed": item['formed'],
                             "disbanded": item['disbanded'],
                             "yearsactive": " / ".join(item['yearsactive']),
                             "style": " / ".join(item['style']),
                             "mood": " / ".join(item['mood']),
                             "instrument": " / ".join(item['instrument']),
                             "librarypath": 'musicdb://artists/%s/' % item['artistid']})
     utils.log('%i of %i artists found in last.FM are in Kodi database' % (len(artists), len(simi_artists)))
     return artists
Example #20
0
 def compare_album_with_library(self, online_list):
     """
     merge *albums from online sources with local db info
     """
     if not self.albums:
         self.albums = self.get_albums()
     for item in online_list:
         for local_item in self.albums:
             if not item.get_info("title") == local_item["title"]:
                 continue
             data = kodijson.get_json(method="AudioLibrary.getAlbumDetails",
                                      params={
                                          "properties": ["thumbnail"],
                                          "albumid": local_item["albumid"]
                                      })
             album = data["result"]["albumdetails"]
             item.set_info("dbid", album["albumid"])
             item.set_path(PLUGIN_BASE +
                           'playalbum&&dbid=%i' % album['albumid'])
             if album["thumbnail"]:
                 item.update_artwork({"thumb": album["thumbnail"]})
             break
     return online_list
Example #21
0
 def get_similar_movies(self, dbid):
     """
     get list of movies from db which are similar to movie with *dbid
     based on metadata-centric ranking
     """
     movie = kodijson.get_json(
         method="VideoLibrary.GetMovieDetails",
         params={
             "properties": ["genre", "director", "country", "year", "mpaa"],
             "movieid": dbid
         })
     if "moviedetails" not in movie['result']:
         return []
     comp_movie = movie['result']['moviedetails']
     genres = comp_movie['genre']
     data = kodijson.get_json(
         method="VideoLibrary.GetMovies",
         params={
             "properties": ["genre", "director", "mpaa", "country", "year"],
             "sort": {
                 "method": "random"
             }
         })
     if "movies" not in data['result']:
         return []
     quotalist = []
     for item in data['result']['movies']:
         item["mediatype"] = "movie"
         diff = abs(int(item['year']) - int(comp_movie['year']))
         hit = 0.0
         miss = 0.00001
         quota = 0.0
         for genre in genres:
             if genre in item['genre']:
                 hit += 1.0
             else:
                 miss += 1.0
         if hit > 0.0:
             quota = float(hit) / float(hit + miss)
         if genres and item['genre'] and genres[0] == item['genre'][0]:
             quota += 0.3
         if diff < 3:
             quota += 0.3
         elif diff < 6:
             quota += 0.15
         if comp_movie['country'] and item['country'] and comp_movie[
                 'country'][0] == item['country'][0]:
             quota += 0.4
         if comp_movie['mpaa'] and item['mpaa'] and comp_movie[
                 'mpaa'] == item['mpaa']:
             quota += 0.4
         if comp_movie['director'] and item['director'] and comp_movie[
                 'director'][0] == item['director'][0]:
             quota += 0.6
         quotalist.append((quota, item["movieid"]))
     quotalist = sorted(quotalist, key=lambda quota: quota[0], reverse=True)
     movies = ItemList(content_type="movies")
     for i, list_movie in enumerate(quotalist):
         if comp_movie['movieid'] is not list_movie[1]:
             newmovie = self.get_movie(list_movie[1])
             movies.append(newmovie)
             if i == 20:
                 break
     return movies
Example #22
0
 def get_similar_artists(self, artist_id):
     """
     get list of artists from db which are similar to artist with *artist_id
     based on LastFM online data
     """
     import LastFM
     simi_artists = LastFM.get_similar_artists(artist_id)
     if simi_artists is None:
         utils.log('Last.fm didn\'t return proper response')
         return None
     if not self.artists:
         self.artists = self.get_artists()
     artists = ItemList(content_type="artists")
     for simi_artist, kodi_artist in itertools.product(
             simi_artists, self.artists):
         if kodi_artist['musicbrainzartistid'] and kodi_artist[
                 'musicbrainzartistid'] == simi_artist['mbid']:
             artists.append(kodi_artist)
         elif kodi_artist['artist'] == simi_artist['name']:
             data = kodijson.get_json(
                 method="AudioLibrary.GetArtistDetails",
                 params={
                     "properties": [
                         "genre", "description", "mood", "style", "born",
                         "died", "formed", "disbanded", "yearsactive",
                         "instrument", "fanart", "thumbnail"
                     ],
                     "artistid":
                     kodi_artist['artistid']
                 })
             item = data["result"]["artistdetails"]
             artwork = {
                 "thumb": item['thumbnail'],
                 "fanart": item['fanart']
             }
             artists.append({
                 "label":
                 item['label'],
                 "artwork":
                 artwork,
                 "title":
                 item['label'],
                 "genre":
                 " / ".join(item['genre']),
                 "artist_description":
                 item['description'],
                 "userrating":
                 item['userrating'],
                 "born":
                 item['born'],
                 "died":
                 item['died'],
                 "formed":
                 item['formed'],
                 "disbanded":
                 item['disbanded'],
                 "yearsactive":
                 " / ".join(item['yearsactive']),
                 "style":
                 " / ".join(item['style']),
                 "mood":
                 " / ".join(item['mood']),
                 "instrument":
                 " / ".join(item['instrument']),
                 "librarypath":
                 'musicdb://artists/%s/' % item['artistid']
             })
     utils.log('%i of %i artists found in last.FM are in Kodi database' %
               (len(artists), len(simi_artists)))
     return artists