def markUnwatched(self, trakt_object): self.post_request('sync/history/remove', postData=trakt_object) if 'seasons' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase show_id = trakt_object['show_id'] season_no = trakt_object['seasons'][0]['number'] TraktSyncDatabase().mark_season_watched(show_id, season_no, 0) elif 'shows' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase trakt_object = trakt_object['shows'][0] TraktSyncDatabase().mark_show_watched(trakt_object['ids']['trakt'], 0) elif 'episodes' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase trakt_object = trakt_object['episodes'][0] TraktSyncDatabase().mark_episode_unwatched_by_id( trakt_object['ids']['trakt']) elif 'movies' in trakt_object: from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase trakt_object = trakt_object['movies'][0] TraktSyncDatabase().mark_movie_unwatched( trakt_object['ids']['trakt']) tools.showDialog.notification(tools.addonName + ': Trakt Manager', 'Item marked as unwatched')
def removeFromCollection(self, trakt_object): self.post_request('sync/collection/remove', postData=trakt_object) if 'seasons' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase trakt_object = trakt_object['seasons'][0] TraktSyncDatabase().mark_season_collected( trakt_object['ids']['trakt'], trakt_object['number'], 0) if 'shows' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase trakt_object = trakt_object['shows'][0] TraktSyncDatabase().mark_show_collected( trakt_object['ids']['trakt'], 0) if 'episodes' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase trakt_object = trakt_object['episodes'][0] TraktSyncDatabase().mark_episode_uncollected( trakt_object['ids']['trakt'], trakt_object['season'], trakt_object['number']) if 'movies' in trakt_object: from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase trakt_object = trakt_object['movies'][0] TraktSyncDatabase().mark_movie_uncollected( trakt_object['ids']['trakt']) tools.showDialog.notification(tools.addonName + ': Trakt Manager', 'Item removed from Collection')
def traktStopWatching(self, override_progress=None): if not self.trakt_integration() or self.scrobbled: return post_data = self.buildTraktObject(override_progress=override_progress) self.trakt_api.post_request('scrobble/stop', postData=post_data, limit=False) try: if post_data['progress'] > 90: if self.media_type == 'episode': from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase TraktSyncDatabase().mark_episode_watched( self.args['showInfo']['ids']['trakt'], self.args['episodeInfo']['info']['season'], self.args['episodeInfo']['info']['episode']) if self.media_type == 'movie': from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase TraktSyncDatabase().mark_movie_watched(self.trakt_id) except: import traceback traceback.print_exc() pass
def traktStopWatching(self, override_progress=None): if not self.trakt_integration() or self.scrobbled: return post_data = self.buildTraktObject(override_progress=override_progress) scrobble_response = self.trakt_api.json_response('scrobble/stop', postData=post_data, limit=False) # Consider the scrobble attempt a failure if the attempt returns a None value if scrobble_response is None: return self.scrobbled = True try: if post_data['progress'] >= 80: if self.media_type == 'episode': from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase TraktSyncDatabase().mark_episode_watched_by_id(self.trakt_id) if self.media_type == 'movie': from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase TraktSyncDatabase().mark_movie_watched(self.trakt_id) except: import traceback traceback.print_exc() pass
def traktStopWatching(self, override_progress=None): if not self.trakt_integration(): return self.handleBookmark() if self.scrobbling_enabled and not self.scrobbled: post_data = self.buildTraktObject( override_progress=override_progress) try: scrobble_response = self.trakt_api.json_response( 'scrobble/stop', postData=post_data, limit=False) # Consider the scrobble attempt a failure if the attempt returns a None value if scrobble_response is not None: self.scrobbled = True except: pass try: if post_data['progress'] >= 80: if self.media_type == 'episode': from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase TraktSyncDatabase().mark_episode_watched_by_id( self.trakt_id) if self.media_type == 'movie': from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase TraktSyncDatabase().mark_movie_watched(self.trakt_id) except: import traceback traceback.print_exc() pass elif not self.scrobbling_enabled and not self.marked_watched: if int(self.getWatchedPercent()) >= int( tools.get_advanced_setting('video', 'playcountminimumpercent')): if self.media_type == 'episode': from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase TraktSyncDatabase().mark_episode_watched_by_id( self.trakt_id) else: from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase TraktSyncDatabase().mark_movie_watched(self.trakt_id)
def myShowCollection(self): trakt_list = TraktSyncDatabase().get_collected_episodes() trakt_list = [i for i in trakt_list if i is not None] trakt_list = list(set([i['show_id'] for i in trakt_list])) trakt_list = [{'ids': {'trakt': i}} for i in trakt_list] trakt_list = [i for i in trakt_list if i is not None] if trakt_list is None: return self.showListBuilder(trakt_list) tools.closeDirectory('tvshows', sort='title')
def myProgress(self): collected_episodes = TraktSyncDatabase().get_collected_episodes() collection = list(set([i['show_id'] for i in collected_episodes])) if len(collection) == 0: return show_dicts = [] for i in collection: show_dicts.append({'show': {'ids': {'trakt': i}}}) show_meta_list = TraktSyncDatabase().get_show_list(show_dicts) unfinished = [] for show in show_meta_list: if show['info']['playcount'] == 0: unfinished.append(show) self.showListBuilder(unfinished) tools.closeDirectory('tvshows', sort='title')
def hideItem(self, trakt_object): from resources.lib.modules.trakt_sync.hidden import TraktSyncDatabase sections = ['progress_watched', 'calendar'] sections_display = ['Watched Progress', 'Calendar'] selection = tools.showDialog.select( tools.addonName + ': Select Menu type to hide from', sections_display) section = sections[selection] self.json_response('users/hidden/%s' % section, postData=trakt_object) if 'movies' in trakt_object: TraktSyncDatabase().add_hidden_item( trakt_object['movies'][0]['ids']['trakt'], 'movie', section) if 'shows' in trakt_object: TraktSyncDatabase().add_hidden_item( trakt_object['shows'][0]['ids']['trakt'], 'show', section) tools.showDialog.notification( tools.addonName, 'Item has been hidden from your %s' % sections_display[selection])
def markUnwatched(self, trakt_object, actionArgs): response = self.json_response('sync/history/remove', postData=trakt_object) if 'episodes' in trakt_object: if not self.confirm_marked_unwatched(response, 'episodes'): return from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase trakt_object = trakt_object['episodes'][0] TraktSyncDatabase().mark_episode_unwatched_by_id( trakt_object['ids']['trakt']) elif 'seasons' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase if not self.confirm_marked_unwatched(response, 'episodes'): return show_id = actionArgs['trakt_id'] season_no = trakt_object['seasons'][0]['number'] TraktSyncDatabase().mark_season_watched(show_id, season_no, 0) elif 'shows' in trakt_object: from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase if not self.confirm_marked_unwatched(response, 'episodes'): return trakt_object = trakt_object['shows'][0] TraktSyncDatabase().mark_show_watched(trakt_object['ids']['trakt'], 0) elif 'movies' in trakt_object: from resources.lib.modules.trakt_sync.movies import TraktSyncDatabase if not self.confirm_marked_unwatched(response, 'movies'): return trakt_object = trakt_object['movies'][0] TraktSyncDatabase().mark_movie_unwatched( trakt_object['ids']['trakt']) tools.showDialog.notification(tools.addonName + ': Trakt Manager', 'Item marked as unwatched') tools.trigger_widget_refresh()
def _get_next_episode_to_watch(self, show_db_dict, watched_episodes): try: show_id = show_db_dict['trakt_id'] watched_episodes = [ i for i in watched_episodes if i['show_id'] == show_id ] watched_episodes = sorted(watched_episodes, key=lambda episode: episode['season'], reverse=True) season = watched_episodes[0]['season'] season_meta = TraktSyncDatabase().get_single_season( show_id, season) watched_episodes = [ i for i in watched_episodes if i['season'] == season ] watched_episodes = sorted(watched_episodes, key=lambda episode: episode['number'], reverse=True) last_watched_episode = watched_episodes[0]['number'] next_episode = int(watched_episodes[0]['number']) + 1 if season_meta['info']['episode_count'] == len(watched_episodes) \ or season_meta['info']['episode_count'] == last_watched_episode: if int(show_db_dict['kodi_meta']['info'] ['season_count']) > season: season += 1 next_episode = 1 else: return episode_dict = { 'show': { 'ids': { 'trakt': show_id } }, 'episode': { 'season': season, 'number': next_episode } } self.itemList.append(episode_dict) except: import traceback traceback.print_exc() pass
def myNextUp(self, ): tv_database = TraktSyncDatabase() watched_shows = tv_database.get_watched_shows() hidden_shows = HiddenDatabase().get_hidden_items( 'progress_watched', 'shows') watched_shows = [ i for i in watched_shows if i['trakt_id'] not in hidden_shows ] watched_episodes = TraktSyncDatabase().get_watched_episodes() self._start_queue_workers() for show in watched_shows: self.task_queue.put( (self._get_next_episode_to_watch, (show, watched_episodes)), block=True) self._finish_queue_workers() if tools.getSetting('nextup.sort') == '1': watched_list = trakt.json_response('users/me/watched/shows') watched_list = sorted(watched_list, key=lambda i: i['last_watched_at'], reverse=True) watched_list = [i['show']['ids']['trakt'] for i in watched_list] sort = {'type': 'showInfo', 'id_list': watched_list} else: sort = None episodes = self.itemList self.itemList = [] self.mixedEpisodeBuilder(episodes, sort=sort, hide_watched=True) tools.closeDirectory('tvshows')
from resources.lib.indexers.trakt import TraktAPI from resources.lib.modules import database from resources.lib.modules.trakt_sync import bookmark from resources.lib.modules.trakt_sync.hidden import TraktSyncDatabase as HiddenDatabase from resources.lib.modules.trakt_sync.shows import TraktSyncDatabase sysaddon = sys.argv[0] try: syshandle = int(sys.argv[1]) except: syshandle = '' trakt = TraktAPI() language_code = tools.get_language_code() trakt_database = TraktSyncDatabase() hidden_database = HiddenDatabase() bookmark_sync = bookmark.TraktSyncDatabase() class Menus: def __init__(self): self.itemList = [] self.direct_episode_threads = [] self.title_appends = tools.getSetting('general.appendtitles') self.task_queue = ThreadPool() ###################################################### # MENUS ######################################################
def showListBuilder(self, trakt_list, forceResume=False, info_only=False): try: if len(trakt_list) == 0: return except: return if 'show' in trakt_list[0]: trakt_list = [i['show'] for i in trakt_list] show_ids = [i['ids']['trakt'] for i in trakt_list] self.itemList = TraktSyncDatabase().get_show_list(show_ids) self.itemList = [ x for x in self.itemList if x is not None and 'info' in x ] self.itemList = tools.sort_list_items(self.itemList, trakt_list) item_list = [] for item in self.itemList: try: args = {} cm = [] # Add Arguments to pass with items args['ids'] = item['ids'] args['info'] = item['info'] args['art'] = item['art'] name = tools.display_string(item['info']['tvshowtitle']) args = tools.quote(json.dumps(args, sort_keys=True)) if info_only == True: return args if not self.is_aired(item['info']): if tools.getSetting('general.hideUnAired') == 'true': continue name = tools.colorString(name, 'red') name = tools.italic_string(name) item['info'] = tools.clean_air_dates(item['info']) if 'setCast' in item: set_cast = item['setCast'] else: set_cast = False if tools.getSetting('smartplay.clickresume' ) == 'true' or forceResume is True: action = 'smartPlay' else: action = 'showSeasons' # Context Menu Items cm.append( (tools.lang(32070), 'XBMC.PlayMedia(%s?action=shufflePlay&actionArgs=%s)' % (sysaddon, args))) cm.append( (tools.lang(32020), 'Container.Update(%s?action=showsRelated&actionArgs=%s)' % (sysaddon, item['ids']['trakt']))) cm.append((tools.lang( 32069 ), 'XBMC.Container.Update(%s?action=showSeasons&actionArgs=%s)' % (sysaddon, args))) if tools.getSetting('trakt.auth') != '': cm.append( ('Trakt Manager', 'RunPlugin(%s?action=traktManager&actionArgs=%s)' % (sysaddon, tools.quote(json.dumps(item['trakt_object']))))) cm.append((tools.lang( 40153 ), 'XBMC.PlayMedia(%s?aciton=playFromRandomPoint&actionArgs=%s' % (sysaddon, args))) if tools.context_addon(): cm = [] except: import traceback traceback.print_exc() continue item_list.append( tools.addDirectoryItem(name, action, item['info'], item['art'], cm=cm, isFolder=True, isPlayable=False, actionArgs=args, bulk_add=True, set_cast=set_cast, set_ids=item['ids'])) tools.addMenuItems(syshandle, item_list, len(item_list))
def mixedEpisodeBuilder(self, trakt_list, sort=None, hide_watched=False, smartPlay=False, hide_unaired=True, prepend_date=False): self.threadList = [] try: if len(trakt_list) == 0: return self.itemList = TraktSyncDatabase().get_episode_list(trakt_list) self.itemList = [ x for x in self.itemList if x is not None and 'info' in x ] self.itemList = [ i for i in self.itemList if 'info' in i and i['info'].get('premiered', None) is not None ] if sort is None: self.itemList = sorted( self.itemList, key=lambda i: tools.datetime_workaround( i['info']['premiered'], tools.trakt_gmt_format, False), reverse=True) elif sort is not False: sort_list = [] for trakt_id in sort['id_list']: try: if not sort['type']: item = [ i for i in self.itemList if i['ids']['trakt'] == trakt_id ][0] else: item = [ i for i in self.itemList if i[sort['type']]['ids']['trakt'] == trakt_id ][0] sort_list.append(item) except IndexError: continue except: import traceback traceback.print_exc() self.itemList = sort_list item_list = [] for item in self.itemList: if item is None: continue if item['info'].get('title', '') == '': continue if hide_watched and item['info']['playcount'] != 0: continue cm = [] try: name = tools.display_string(item['info']['title']) if not self.is_aired( item['info']) and hide_unaired is True: continue elif not self.is_aired(item['info']): name = tools.colorString(name, 'red') name = tools.italic_string(name) item['info']['title'] = name item['info'] = tools.clean_air_dates(item['info']) args = {'showInfo': {}, 'episodeInfo': {}} if tools.getSetting('smartplay.playlistcreate' ) == 'true' and not smartPlay: action = 'smartPlay' playable = False else: playable = True action = 'getSources' args['showInfo'] = item['showInfo'] args['episodeInfo']['info'] = item['info'] args['episodeInfo']['art'] = item['art'] args['episodeInfo']['ids'] = item['ids'] if self.title_appends == 'true': name = "%s: %sx%s %s" % ( tools.colorString( args['showInfo']['info']['tvshowtitle']), tools.display_string( item['info']['season']).zfill(2), tools.display_string( item['info']['episode']).zfill(2), tools.display_string(item['info']['title'])) if prepend_date: release_day = tools.datetime_workaround( item['info']['aired']) release_day = release_day.strftime('%d %b') name = '[%s] %s' % (release_day, name) args = tools.quote(json.dumps(args, sort_keys=True)) cm.append((tools.lang( 32069 ), 'XBMC.Container.Update(%s?action=showSeasons&actionArgs=%s)' % (sysaddon, tools.quote(json.dumps(str( item['showInfo'])))))) cm.append((tools.lang( 32066 ), 'PlayMedia(%s?action=getSources&source_select=true&actionArgs=%s)' % (sysaddon, args))) cm.append((tools.lang( 33022 ), 'PlayMedia(%s?action=getSources&seren_reload=true&actionArgs=%s)' % (sysaddon, args))) if tools.getSetting('trakt.auth') != '': cm.append(( 'Trakt Manager', 'RunPlugin(%s?action=traktManager&actionArgs=%s)' % (sysaddon, tools.quote(json.dumps(str( item['trakt_object'])))))) if tools.context_addon(): cm = [] if tools.getSetting( 'premiumize.enabled' ) == 'true' and tools.getSetting('premiumize.pin') != '': cm.append((tools.lang( 32068 ), 'XBMC.RunPlugin(%s?action=filePicker&actionArgs=%s)' % (sysaddon, args))) item['info']['title'] = item['info'][ 'originaltitle'] = name item_list.append( tools.addDirectoryItem(name, action, item['info'], item['art'], isFolder=False, isPlayable=playable, actionArgs=args, bulk_add=True, set_ids=item['ids'], cm=cm)) except: import traceback traceback.print_exc() continue if smartPlay is True: return item_list else: tools.addMenuItems(syshandle, item_list, len(item_list)) except: import traceback traceback.print_exc()
def episodeListBuilder(self, show_id, season_number, smartPlay=False, hide_unaired=False): try: item_list = [] self.itemList = TraktSyncDatabase().get_season_episodes( show_id, season_number) self.itemList = [ x for x in self.itemList if x is not None and 'info' in x ] try: self.itemList = sorted(self.itemList, key=lambda k: k['info']['episode']) except: pass for item in self.itemList: cm = [] try: args = {'showInfo': {}, 'episodeInfo': {}} if tools.getSetting('smartplay.playlistcreate' ) == 'true' and smartPlay is False: action = 'smartPlay' playable = False else: playable = True action = 'getSources' args['showInfo'] = item['showInfo'] args['episodeInfo']['info'] = item['info'] args['episodeInfo']['art'] = item['art'] args['episodeInfo']['ids'] = item['ids'] name = item['info']['title'] if not self.is_aired(item['info']): if tools.getSetting('general.hideUnAired' ) == 'true' or hide_unaired: continue else: name = tools.colorString(name, 'red') name = tools.italic_string(name) item['info']['title'] = name item['info'] = tools.clean_air_dates(item['info']) args = tools.quote(json.dumps(args, sort_keys=True)) except: import traceback traceback.print_exc() continue cm.append((tools.lang( 33022 ), 'PlayMedia(%s?action=getSources&seren_reload=true&actionArgs=%s)' % (sysaddon, args))) cm.append((tools.lang( 32066 ), 'PlayMedia(%s?action=getSources&source_select=true&actionArgs=%s)' % (sysaddon, args))) if tools.getSetting('trakt.auth') != '': cm.append( ('Trakt Manager', 'RunPlugin(%s?action=traktManager&actionArgs=%s)' % (sysaddon, tools.quote(json.dumps(item['trakt_object']))))) if tools.context_addon(): cm = [] if tools.getSetting( 'premiumize.enabled' ) == 'true' and tools.getSetting('premiumize.pin') != '': cm.append( (tools.lang(32068), 'XBMC.RunPlugin(%s?action=filePicker&actionArgs=%s)' % (sysaddon, args))) item_list.append( tools.addDirectoryItem(name, action, item['info'], item['art'], isFolder=False, isPlayable=playable, actionArgs=args, bulk_add=True, set_ids=item['ids'], cm=cm)) if smartPlay is True: return item_list else: tools.addMenuItems(syshandle, item_list, len(item_list)) except: import traceback traceback.print_exc()
def seasonListBuilder(self, show_id, smartPlay=False): self.itemList = TraktSyncDatabase().get_season_list(show_id) self.itemList = [ x for x in self.itemList if x is not None and 'info' in x ] self.itemList = sorted(self.itemList, key=lambda k: k['info']['season']) hide_specials = False if tools.getSetting('general.hideSpecials') == 'true': hide_specials = True item_list = [] for item in self.itemList: try: if hide_specials and int(item['info']['season']) == 0: continue args = {'showInfo': {}, 'seasonInfo': {}} action = 'seasonEpisodes' args['showInfo'] = item['showInfo'] args['seasonInfo']['info'] = item['info'] args['seasonInfo']['art'] = item['art'] args['seasonInfo']['ids'] = item['ids'] item['trakt_object']['show_id'] = item['showInfo']['ids'][ 'trakt'] name = item['info']['season_title'] if not self.is_aired( item['info']) or 'aired' not in item['info']: if tools.getSetting('general.hideUnAired') == 'true': continue name = tools.colorString(name, 'red') name = tools.italic_string(name) item['info']['title'] = name item['info'] = tools.clean_air_dates(item['info']) args = tools.quote(json.dumps(args, sort_keys=True)) except: import traceback traceback.print_exc() continue if smartPlay is True: return args cm = [] if tools.getSetting('trakt.auth') != '': cm.append(( 'Trakt Manager', 'RunPlugin(%s?action=traktManager&actionArgs=%s)' % (sysaddon, tools.quote(json.dumps(item['trakt_object']))))) if tools.context_addon(): cm = [] item_list.append( tools.addDirectoryItem(name, action, item['info'], item['art'], cm=cm, isFolder=True, isPlayable=False, actionArgs=args, set_ids=item['ids'], bulk_add=True)) tools.addMenuItems(syshandle, item_list, len(item_list))