def _get_suggested_items(self):
     playedEpisodes = [item for item in self._items if item['playcount']>0]
     if self.__ignoreSpecials:
         playedEpisodes = [item for item in playedEpisodes if item['season']>0]
     playedTvShowIds = set([item['tvshowid'] for item in playedEpisodes])      
     playedTvShows = []
     for playedTvShowId in playedTvShowIds:
         showEpisodes = [item for item in self._items if item['tvshowid']==playedTvShowId]
         if self.__ignoreSpecials:
             showEpisodes = [item for item in showEpisodes if item['season']>0]
         #Relevent order in max(lastpayed in set set, min(date(dateadded) with palycount=0 in set set)), lastplayed 
         lastPlayed = max([item['lastplayed'] for item in showEpisodes])
         dateAdded = "0000-00-00 00:00:00"
         setUnplayedEpisodesDateAdded = [helper.date(item['dateadded']) for item in showEpisodes if item['playcount']==0]
         if len(setUnplayedEpisodesDateAdded) > 0:
             dateAdded = min(setUnplayedEpisodesDateAdded)
         playedTvShows.append({'tvshowid':playedTvShowId, 'relevantupdatedate':max([lastPlayed,dateAdded]), 'lastplayed':lastPlayed})
     playedTvShows = sorted(playedTvShows, key=lambda x: [x['relevantupdatedate'],x['lastplayed']], reverse=True)       
     nextEpisodes = []
     for playedTvShow in playedTvShows:
         unplayedShowEpisodes = [item for item in self._items if item['tvshowid']==playedTvShow['tvshowid'] and item['playcount']==0]
         if self.__ignoreSpecials:
             unplayedShowEpisodes = [item for item in unplayedShowEpisodes if item['season']>0]
         unplayedShowEpisodes = sorted(unplayedShowEpisodes, key=lambda x: [x['season'],x['episode']], reverse=False)
         episodes = [item for item in unplayedShowEpisodes if item['season']>0]
         if len(episodes) > 0:
             nextEpisodes.append(episodes[0])
         else:
             episodes = episodes = [item for item in unplayedShowEpisodes if item['season']==0]
             if len(episodes) > 0:
                 nextEpisodes.append(episodes[0])
     #Then when is a not inprogress show: first not played/started episode from the show with the maximum dateadded from the show
     otherTvShowIds = set([item['tvshowid'] for item in self._items if item['tvshowid'] not in playedTvShowIds])
     firstEpisodes = []
     for otherTvShowId in otherTvShowIds:
         showEpisodes = [item for item in self._items if item['tvshowid']==otherTvShowId]            
         if self.__ignoreSpecials:
             showEpisodes = [item for item in showEpisodes if item['season']>0]
         showEpisodes = sorted(showEpisodes, key=lambda x: [x['season'],x['episode']], reverse=False)            
         dateAdded = max([item['dateadded'] for item in showEpisodes])
         episodes = [item for item in showEpisodes if item['season']>0]
         if len(episodes) > 0:
             firstEpisodes.append({'episode':episodes[0], 'dateadded':dateAdded})
         else:
             episodes = [item for item in showEpisodes if item['season']==0]
             if len(episodes) > 0:
                 firstEpisodes.append({'episode':episodes[0], 'dateadded':dateAdded})
     firstEpisodes = sorted(firstEpisodes, key=lambda x: x['dateadded'], reverse=True)
     firstEpisodes = [item['episode'] for item in firstEpisodes]
     #Mix and limit the result
     result = nextEpisodes + firstEpisodes  
     return result[:self._itemLimit]
 def _get_suggested_items(self):
     unplayedItems = [item for item in self._items if item["playcount"] == 0]
     # Get all started movie form last played to first played
     startedMovies = [item for item in unplayedItems if item["resume"]["position"] > 0]
     startedMovies = sorted(startedMovies, key=lambda x: x["lastplayed"], reverse=True)
     # Then get the first movie (by year) from each set where at least one movie is played and no movie is started (selected in 1st case)
     playedSets = []
     playedSetIds = set(
         [
             item["setid"]
             for item in self._items
             if item["setid"] > 0
             and item["playcount"] > 0
             and item["setid"] not in [startedItem["setid"] for startedItem in startedMovies]
         ]
     )
     for playedSetId in playedSetIds:
         # Relevent order in max(lastpayed in set set, min(date(dateadded) with palycount=0 in set set)), lastplayed
         lastPlayed = max([item["lastplayed"] for item in self._items if item["setid"] == playedSetId])
         dateAdded = "0000-00-00 00:00:00"
         setUnplayedMoviesDateAdded = [
             helper.date(item["dateadded"])
             for item in self._items
             if item["setid"] == playedSetId and item["playcount"] == 0
         ]
         if len(setUnplayedMoviesDateAdded) > 0:
             dateAdded = min(setUnplayedMoviesDateAdded)
         playedSets.append(
             {"setid": playedSetId, "relevantupdatedate": max([lastPlayed, dateAdded]), "lastplayed": lastPlayed}
         )
     playedSets = sorted(playedSets, key=lambda x: [x["relevantupdatedate"], x["lastplayed"]], reverse=True)
     nextMoviesFromStartedSets = []
     for playedSet in playedSets:
         movies = [item for item in unplayedItems if item["setid"] == playedSet["setid"]]
         movies = sorted(movies, key=lambda x: x["year"], reverse=False)
         if len(movies) > 0:
             nextMoviesFromStartedSets.append(movies[0])
     # Then order from most recent to oldest other items:
     # - When not in a set: not played/started movie
     otherItems = []
     for movie in [item for item in unplayedItems if item["setid"] == 0 and item not in startedMovies]:
         otherItems.append({"movie": movie, "dateadded": movie["dateadded"]})
     # - When is a not played/inprogress set: first not played/started movie from the set with the maximum dateadded from the set
     otherSetIds = set(
         [
             item["setid"]
             for item in unplayedItems
             if item["setid"] > 0
             and item["setid"] not in [startedItem["setid"] for startedItem in startedMovies]
             and item["setid"] not in playedSetIds
         ]
     )
     for otherSetId in otherSetIds:
         otherSetMovies = [item for item in unplayedItems if item["setid"] == otherSetId]
         if len(otherSetMovies) > 0:
             otherSetMovies = sorted(otherSetMovies, key=lambda x: x["year"], reverse=False)
             otherItems.append(
                 {
                     "movie": otherSetMovies[0],
                     "dateadded": max([otherSetMovie["dateadded"] for otherSetMovie in otherSetMovies]),
                 }
             )
     otherItems = sorted(otherItems, key=lambda x: x["dateadded"], reverse=True)
     otherItems = [item["movie"] for item in otherItems]
     # Mix and limit the result
     items = startedMovies + nextMoviesFromStartedSets + otherItems
     return items[: self._itemLimit]