示例#1
0
	def __compareMovies(self, movies_col1, movies_col2, watched=False, restrict=False, playback=False):
		movies = []

		for movie_col1 in movies_col1:
			if movie_col1:
				movie_col2 = utilities.findMediaObject(movie_col1, movies_col2)
				#logger.debug("movie_col1 %s" % movie_col1)
				#logger.debug("movie_col2 %s" % movie_col2)

				if movie_col2:  #match found
					if watched: #are we looking for watched items
						if movie_col2['watched'] == 0 and movie_col1['watched'] == 1:
							if 'movieid' not in movie_col1:
								movie_col1['movieid'] = movie_col2['movieid']
							movies.append(movie_col1)
					elif playback:
						if 'movieid' not in movie_col1:
								movie_col1['movieid'] = movie_col2['movieid']
						movie_col1['runtime'] = movie_col2['runtime']
						movies.append(movie_col1)
					else:
						if 'collected' in movie_col2 and not movie_col2['collected']:
							movies.append(movie_col1)
				else: #no match found
					if not restrict:
						if 'collected' in movie_col1 and movie_col1['collected']:
							if watched and (movie_col1['watched'] == 1):
								movies.append(movie_col1)
							elif not watched:
								movies.append(movie_col1)

		return movies
示例#2
0
    def __compareMovies(self,
                        movies_col1,
                        movies_col2,
                        watched=False,
                        restrict=False):
        movies = []

        for movie_col1 in movies_col1:
            movie_col2 = utilities.findMediaObject(movie_col1, movies_col2)
            #Debug("movie_col1 %s" % movie_col1)
            #Debug("movie_col2 %s" % movie_col2)

            if movie_col2:  #match found
                if watched:  #are we looking for watched items
                    if movie_col2['watched'] == 0 and movie_col1[
                            'watched'] == 1:
                        if 'movieid' not in movie_col1:
                            movie_col1['movieid'] = movie_col2['movieid']
                        movies.append(movie_col1)
                else:
                    if 'collected' in movie_col2 and not movie_col2[
                            'collected']:
                        movies.append(movie_col1)
            else:  #no match found
                if not restrict:
                    if 'collected' in movie_col1 and movie_col1['collected']:
                        if watched and (movie_col1['plays'] > 0):
                            movies.append(movie_col1)
                        elif not watched:
                            movies.append(movie_col1)

        return movies
示例#3
0
    def __compareMovies(self,
                        movies_col1,
                        movies_col2,
                        watched=False,
                        restrict=False,
                        playback=False,
                        rating=False):
        movies = []

        for movie_col1 in movies_col1:
            if movie_col1:
                movie_col2 = utilities.findMediaObject(movie_col1, movies_col2)
                # logger.debug("movie_col1 %s" % movie_col1)
                # logger.debug("movie_col2 %s" % movie_col2)

                if movie_col2:  # match found
                    if watched:  # are we looking for watched items
                        if movie_col2['watched'] == 0 and movie_col1[
                                'watched'] == 1:
                            if 'movieid' not in movie_col1:
                                movie_col1['movieid'] = movie_col2['movieid']
                            movies.append(movie_col1)
                    elif playback:
                        if 'movieid' not in movie_col1:
                            movie_col1['movieid'] = movie_col2['movieid']
                        movie_col1['runtime'] = movie_col2['runtime']
                        movies.append(movie_col1)
                    elif rating:
                        if 'rating' in movie_col1 and movie_col1[
                                'rating'] <> 0 and ('rating' not in movie_col2
                                                    or movie_col2['rating']
                                                    == 0):
                            if 'movieid' not in movie_col1:
                                movie_col1['movieid'] = movie_col2['movieid']
                            movies.append(movie_col1)
                    else:
                        if 'collected' in movie_col2 and not movie_col2[
                                'collected']:
                            movies.append(movie_col1)
                else:  # no match found
                    if not restrict:
                        if 'collected' in movie_col1 and movie_col1[
                                'collected']:
                            if watched and (movie_col1['watched'] == 1):
                                movies.append(movie_col1)
                            elif not watched:
                                movies.append(movie_col1)

        return movies
示例#4
0
    def __compareShows(self, shows_col1, shows_col2, rating=False, restrict=False):
        shows = []
        for show_col1 in shows_col1['shows']:
            if show_col1:
                show_col2 = utilities.findMediaObject(show_col1, shows_col2['shows'])
                # logger.debug("show_col1 %s" % show_col1)
                # logger.debug("show_col2 %s" % show_col2)

                if show_col2:
                    show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year']}
                    if 'tvdb' in show_col1['ids']:
                        show['ids'] = {'tvdb': show_col1['ids']['tvdb']}
                    if 'imdb' in show_col2 and show_col2['imdb']:
                        show['ids']['imdb'] = show_col2['imdb']
                    if 'tvshowid' in show_col2:
                        show['tvshowid'] = show_col2['tvshowid']

                    if rating and 'rating' in show_col1 and show_col1['rating'] <> 0 and ('rating' not in show_col2 or show_col2['rating'] == 0):
                        show['rating'] = show_col1['rating']
                        shows.append(show)
                    elif not rating:
                        shows.append(show)
                else:
                    if not restrict:
                        show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year']}
                        if 'tvdb' in show_col1['ids']:
                            show['ids'] = {'tvdb': show_col1['ids']['tvdb']}

                        if rating and 'rating' in show_col1 and show_col1['rating'] <> 0:
                            show['rating'] = show_col1['rating']
                            shows.append(show)
                        elif not rating:
                            shows.append(show)

        result = {'shows': shows}
        return result
示例#5
0
    def __compareShows(self, shows_col1, shows_col2, rating=False, restrict=False):
        shows = []
        for show_col1 in shows_col1['shows']:
            if show_col1:
                show_col2 = utilities.findMediaObject(show_col1, shows_col2['shows'])
                # logger.debug("show_col1 %s" % show_col1)
                # logger.debug("show_col2 %s" % show_col2)

                if show_col2:
                    show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year']}
                    if 'tvdb' in show_col1['ids']:
                        show['ids'] = {'tvdb': show_col1['ids']['tvdb']}
                    if 'imdb' in show_col2 and show_col2['imdb']:
                        show['ids']['imdb'] = show_col2['imdb']
                    if 'tvshowid' in show_col2:
                        show['tvshowid'] = show_col2['tvshowid']

                    if rating and 'rating' in show_col1 and show_col1['rating'] != 0 and ('rating' not in show_col2 or show_col2['rating'] == 0):
                        show['rating'] = show_col1['rating']
                        shows.append(show)
                    elif not rating:
                        shows.append(show)
                else:
                    if not restrict:
                        show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year']}
                        if 'tvdb' in show_col1['ids']:
                            show['ids'] = {'tvdb': show_col1['ids']['tvdb']}

                        if rating and 'rating' in show_col1 and show_col1['rating'] != 0:
                            show['rating'] = show_col1['rating']
                            shows.append(show)
                        elif not rating:
                            shows.append(show)

        result = {'shows': shows}
        return result
示例#6
0
	def __compareShows(self, shows_col1, shows_col2, watched=False, restrict=False, collected=False, playback=False):
		shows = []
		for show_col1 in shows_col1['shows']:
			if show_col1:
				show_col2 = utilities.findMediaObject(show_col1, shows_col2['shows'])
				#logger.debug("show_col1 %s" % show_col1)
				#logger.debug("show_col2 %s" % show_col2)

				if show_col2:
					season_diff = {}
					# format the data to be easy to compare Trakt and KODI data
					season_col1 = self.__getEpisodes(show_col1['seasons'])
					season_col2 = self.__getEpisodes(show_col2['seasons'])
					for season in season_col1:
						a = season_col1[season]
						if season in season_col2:
							b = season_col2[season]
							diff = list(set(a).difference(set(b)))
							if playback:
								t = list(set(a).intersection(set(b)))
								if len(t) > 0:
									eps = {}
									for ep in t:
										eps[ep] = a[ep]
										if 'episodeid' in season_col2[season][ep]['ids']:
											if 'ids' in eps:
												eps[ep]['ids']['episodeid'] = season_col2[season][ep]['ids']['episodeid']
											else:
												eps[ep]['ids'] = {'episodeid': season_col2[season][ep]['ids']['episodeid']}
										eps[ep]['runtime'] = season_col2[season][ep]['runtime']
									season_diff[season] = eps
							elif len(diff) > 0:
								if restrict:
									# get all the episodes that we have in Kodi, watched or not - update kodi
									collectedShow = utilities.findMediaObject(show_col1, collected['shows'])
									#logger.debug("collected %s" % collectedShow)
									collectedSeasons = self.__getEpisodes(collectedShow['seasons'])
									t = list(set(collectedSeasons[season]).intersection(set(diff)))
									if len(t) > 0:
										eps = {}
										for ep in t:
											eps[ep] = a[ep]
											if 'episodeid' in collectedSeasons[season][ep]['ids']:
												if 'ids' in eps:
													eps[ep]['ids']['episodeid'] = collectedSeasons[season][ep]['ids']['episodeid']
												else:
													eps[ep]['ids'] = {'episodeid': collectedSeasons[season][ep]['ids']['episodeid']}
										season_diff[season] = eps
								else:
									eps = {}
									for ep in diff:
										eps[ep] = a[ep]
									if len(eps) > 0:
										season_diff[season] = eps
						else:
							if not restrict:
								if len(a) > 0:
									season_diff[season] = a
					#logger.debug("season_diff %s" % season_diff)
					if len(season_diff) > 0:
						#logger.debug("Season_diff")
						show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year'], 'seasons': []}
						if 'tvdb' in show_col1['ids']:
							show['ids'] = {'tvdb': show_col1['ids']['tvdb']}
						for seasonKey in season_diff:
							episodes = []
							for episodeKey in season_diff[seasonKey]:
								episodes.append(season_diff[seasonKey][episodeKey])
							show['seasons'].append({ 'number': seasonKey, 'episodes': episodes })
						if 'imdb' in show_col2 and show_col2['imdb']:
							show['ids']['imdb'] = show_col2['imdb']
						if 'tvshowid' in show_col2:
							show['tvshowid'] = show_col2['tvshowid']
						#logger.debug("show %s" % show)
						shows.append(show)
				else:
					if not restrict:
						if self.__countEpisodes([show_col1]) > 0:
							show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year'], 'seasons': []}
							if 'tvdb' in show_col1['ids']:
								show['ids'] = {'tvdb': show_col1['ids']['tvdb']}
							for seasonKey in show_col1['seasons']:
								episodes = []
								for episodeKey in seasonKey['episodes']:
									if watched and (episodeKey['watched'] == 1):
										episodes.append(episodeKey)
									elif not watched:
										episodes.append(episodeKey)
								if len(episodes) > 0:
									show['seasons'].append({ 'number': seasonKey['number'], 'episodes': episodes })

							if 'tvshowid' in show_col1:
								del(show_col1['tvshowid'])
							if self.__countEpisodes([show]) > 0:
								shows.append(show)
		result = { 'shows': shows}
		return result
示例#7
0
	def __compareShows(self, shows_col1, shows_col2, watched=False, restrict=False):
		shows = []
		p = 'watched' if watched else 'seasons'
		for show_col1 in shows_col1['shows']:
			show_col2 = utilities.findMediaObject(show_col1, shows_col2['shows'])

			if show_col2:
				season_diff = {}
				# format the data to be easy to compare trakt and KODI data
				season1 = self.__getEpisodes(show_col1['seasons'], watched)
				season2 = self.__getEpisodes(show_col2['seasons'], watched)
				for season in season1:
					a = season1[season]
					if season in season2:
						b = season2[season]
						diff = list(set(a).difference(set(b)))
						if len(diff) > 0:
							if restrict:
								# get all the episodes that we have in Kodi, watched or not
								_seasons = self.__getEpisodes(show_col2['seasons'], False)
								t = list(set(_seasons[season]).intersection(set(diff)))
								if len(t) > 0:
									eps = {}
									for ep in t:
										eps[ep] = _seasons[season][ep]
									season_diff[season] = eps
							else:
								eps = {}
								for ep in diff:
									eps[ep] = a[ep]
								season_diff[season] = eps
					else:
						if not restrict:
							if len(a) > 0:
								season_diff[season] = a
				if len(season_diff) > 0:
					show = {'title': show_col1['title'], 'ids' : {'tvdb': show_col1['ids']['tvdb']}, 'year': show_col1['year'], 'seasons': []}
					for seasonKey in season_diff:
						episodes = []
						#Debug("seasonKey %s" % seasonKey)                        
						for episodeKey in season_diff[seasonKey]:
							episodes.append({ 'number': episodeKey, 'ids': season_diff[seasonKey][episodeKey]})
						show['seasons'].append({ 'number': seasonKey, 'episodes': episodes })
					if 'imdb' in show_col1 and show_col1['imdb']:
						show['ids']['imdb'] = show_col1['imdb']
					if 'imdb' in show_col2 and show_col2['imdb']:
						show['ids']['imdb'] = show_col2['imdb']
					if 'tvshowid' in show_col1:
						show['tvshowid'] = show_col1['tvshowid']
					if 'tvshowid' in show_col2:
						show['tvshowid'] = show_col2['tvshowid']
					shows.append(show)
			else:
				if not restrict:
					if self.__countEpisodes([show_col1]) > 0:
						
						show = {'title': show_col1['title'], 'ids': {'tvdb': show_col1['ids']['tvdb']}, 'year': show_col1['year'], 'seasons': []}
						for seasonKey in show_col1['seasons']:
							episodes = []
							for episodeKey in seasonKey['episodes']:
								if 'ids' in episodeKey:
									ids = episodeKey['ids']
									if 'episodeid' in ids:
										del(ids['episodeid'])
								else:
									ids = {}
								episodes.append({ 'number': episodeKey['number'], 'ids': ids })
									
							show['seasons'].append({ 'number': seasonKey['number'], 'episodes': episodes })

						if 'tvshowid' in show_col1:
							del(show_col1['tvshowid'])
						#	show['tvshowid'] = show_col1['tvshowid']
						shows.append(show)
						Debug('show %s' % show)
		result = { 'shows': shows}
		return result
示例#8
0
    def __compareEpisodes(self, shows_col1, shows_col2, watched=False, restrict=False, collected=False, playback=False, rating=False):
        shows = []
        for show_col1 in shows_col1['shows']:
            if show_col1:
                show_col2 = utilities.findMediaObject(show_col1, shows_col2['shows'])
                # logger.debug("show_col1 %s" % show_col1)
                # logger.debug("show_col2 %s" % show_col2)

                if show_col2:
                    season_diff = {}
                    # format the data to be easy to compare Trakt and KODI data
                    season_col1 = self.__getEpisodes(show_col1['seasons'])
                    season_col2 = self.__getEpisodes(show_col2['seasons'])
                    for season in season_col1:
                        a = season_col1[season]
                        if season in season_col2:
                            b = season_col2[season]
                            diff = list(set(a).difference(set(b)))
                            if playback:
                                t = list(set(a).intersection(set(b)))
                                if len(t) > 0:
                                    eps = {}
                                    for ep in t:
                                        eps[ep] = a[ep]
                                        if 'episodeid' in season_col2[season][ep]['ids']:
                                            if 'ids' in eps:
                                                eps[ep]['ids']['episodeid'] = season_col2[season][ep]['ids']['episodeid']
                                            else:
                                                eps[ep]['ids'] = {'episodeid': season_col2[season][ep]['ids']['episodeid']}
                                        eps[ep]['runtime'] = season_col2[season][ep]['runtime']
                                    season_diff[season] = eps
                            elif rating:
                                t = list(set(a).intersection(set(b)))
                                if len(t) > 0:
                                    eps = {}
                                    for ep in t:
                                        if 'rating' in a[ep] and a[ep]['rating'] != 0 and season_col2[season][ep]['rating'] == 0:
                                            eps[ep] = a[ep]
                                            if 'episodeid' in season_col2[season][ep]['ids']:
                                                if 'ids' in eps:
                                                    eps[ep]['ids']['episodeid'] = season_col2[season][ep]['ids']['episodeid']
                                                else:
                                                    eps[ep]['ids'] = {'episodeid': season_col2[season][ep]['ids']['episodeid']}
                                    if len(eps) > 0:
                                        season_diff[season] = eps
                            elif len(diff) > 0:
                                if restrict:
                                    # get all the episodes that we have in Kodi, watched or not - update kodi
                                    collectedShow = utilities.findMediaObject(show_col1, collected['shows'])
                                    # logger.debug("collected %s" % collectedShow)
                                    collectedSeasons = self.__getEpisodes(collectedShow['seasons'])
                                    t = list(set(collectedSeasons[season]).intersection(set(diff)))
                                    if len(t) > 0:
                                        eps = {}
                                        for ep in t:
                                            eps[ep] = a[ep]
                                            if 'episodeid' in collectedSeasons[season][ep]['ids']:
                                                if 'ids' in eps:
                                                    eps[ep]['ids']['episodeid'] = collectedSeasons[season][ep]['ids']['episodeid']
                                                else:
                                                    eps[ep]['ids'] = {'episodeid': collectedSeasons[season][ep]['ids']['episodeid']}
                                        season_diff[season] = eps
                                else:
                                    eps = {}
                                    for ep in diff:
                                        eps[ep] = a[ep]
                                    if len(eps) > 0:
                                        season_diff[season] = eps
                        else:
                            if not restrict and not rating:
                                if len(a) > 0:
                                    season_diff[season] = a
                    # logger.debug("season_diff %s" % season_diff)
                    if len(season_diff) > 0:
                        # logger.debug("Season_diff")
                        show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year'], 'seasons': []}
                        if 'tvdb' in show_col1['ids']:
                            show['ids'] = {'tvdb': show_col1['ids']['tvdb']}
                        for seasonKey in season_diff:
                            episodes = []
                            for episodeKey in season_diff[seasonKey]:
                                episodes.append(season_diff[seasonKey][episodeKey])
                            show['seasons'].append({'number': seasonKey, 'episodes': episodes})
                        if 'imdb' in show_col2 and show_col2['imdb']:
                            show['ids']['imdb'] = show_col2['imdb']
                        if 'tvshowid' in show_col2:
                            show['tvshowid'] = show_col2['tvshowid']
                        # logger.debug("show %s" % show)
                        shows.append(show)
                else:
                    if not restrict:
                        if self.__countEpisodes([show_col1]) > 0:
                            show = {'title': show_col1['title'], 'ids': {}, 'year': show_col1['year'], 'seasons': []}
                            if 'tvdb' in show_col1['ids']:
                                show['ids'] = {'tvdb': show_col1['ids']['tvdb']}
                            for seasonKey in show_col1['seasons']:
                                episodes = []
                                for episodeKey in seasonKey['episodes']:
                                    if watched and (episodeKey['watched'] == 1):
                                        episodes.append(episodeKey)
                                    elif rating and episodeKey['rating'] != 0:
                                        episodes.append(episodeKey)
                                    elif not watched and not rating:
                                        episodes.append(episodeKey)
                                if len(episodes) > 0:
                                    show['seasons'].append({'number': seasonKey['number'], 'episodes': episodes})

                            if 'tvshowid' in show_col1:
                                del(show_col1['tvshowid'])
                            if self.__countEpisodes([show]) > 0:
                                shows.append(show)
        result = {'shows': shows}
        return result