def dispatch(params): from resources.lib.common import tools from resources.lib.modules import database tools.SETTINGS_CACHE = {} try: url = params.get('url') action = params.get('action') page = params.get('page') actionArgs = params.get('actionArgs') pack_select = params.get('packSelect') source_select = params.get('source_select') seren_reload = True if params.get('seren_reload') == 'true' else False resume = params.get('resume') forceresumeoff = True if params.get( 'forceresumeoff') == 'true' else False forceresumeon = True if params.get( 'forceresumeon') == 'true' else False smartPlay = True if params.get('smartPlay') == 'true' else False except: print('Welcome to console mode') print('Command Help:') print(' - Menu Number: opens the relevant menu page') print(' - shell: opens a interactive python shell within Seren') print(' - action xxx: run a custom Seren URL argument') url = '' action = None page = '' actionArgs = '' pack_select = '' source_select = '' seren_reload = '' resume = None forceresumeoff = True if params.get( 'forceresumeoff') == 'true' else False forceresumeon = True if params.get( 'forceresumeon') == 'true' else False smartPlay = True if params.get('smartPlay') == 'true' else False tools.log('Seren, Running Path - Action: %s, actionArgs: %s' % (action, actionArgs)) if action is None: from resources.lib.gui import homeMenu homeMenu.Menus().home() if action == 'smartPlay': from resources.lib.modules import smartPlay # if 'resume' not in actionArgs: # actionArgs = json.loads(actionArgs) # actionArgs['resume'] = sys.argv[3].split(':')[-1] # actionArgs = tools.quote(json.dumps(actionArgs, sort_keys=True)) smartPlay.SmartPlay(actionArgs).fill_playlist() if action == 'playbackResume': from resources.lib.modules import smartPlay smart = smartPlay.SmartPlay(actionArgs) smart.workaround() if action == 'moviesHome': from resources.lib.gui import movieMenus movieMenus.Menus().discoverMovies() if action == 'moviesPopular': from resources.lib.gui import movieMenus movieMenus.Menus().moviesPopular(page) if action == 'moviesTrending': from resources.lib.gui import movieMenus movieMenus.Menus().moviesTrending(page) if action == 'moviesPlayed': from resources.lib.gui import movieMenus movieMenus.Menus().moviesPlayed(page) if action == 'moviesWatched': from resources.lib.gui import movieMenus movieMenus.Menus().moviesWatched(page) if action == 'moviesCollected': from resources.lib.gui import movieMenus movieMenus.Menus().moviesCollected(page) if action == 'moviesAnticipated': from resources.lib.gui import movieMenus movieMenus.Menus().moviesAnticipated(page) if action == 'moviesBoxOffice': from resources.lib.gui import movieMenus movieMenus.Menus().moviesBoxOffice() if action == 'moviesUpdated': from resources.lib.gui import movieMenus movieMenus.Menus().moviesUpdated(page) if action == 'moviesRecommended': from resources.lib.gui import movieMenus movieMenus.Menus().moviesRecommended() if action == 'moviesSearch': from resources.lib.gui import movieMenus movieMenus.Menus().moviesSearch(actionArgs) if action == 'moviesSearchResults': from resources.lib.gui import movieMenus movieMenus.Menus().moviesSearchResults(actionArgs) if action == 'moviesSearchHistory': from resources.lib.gui import movieMenus movieMenus.Menus().moviesSearchHistory() if action == 'myMovies': from resources.lib.gui import movieMenus movieMenus.Menus().myMovies() if action == 'moviesMyCollection': from resources.lib.gui import movieMenus movieMenus.Menus().myMovieCollection() if action == 'moviesMyWatchlist': from resources.lib.gui import movieMenus movieMenus.Menus().myMovieWatchlist() if action == 'moviesRelated': from resources.lib.gui import movieMenus movieMenus.Menus().moviesRelated(actionArgs) if action == 'colorPicker': tools.colorPicker() if action == 'authTrakt': from resources.lib.indexers import trakt trakt.TraktAPI().auth() if action == 'revokeTrakt': from resources.lib.indexers import trakt trakt.TraktAPI().revokeAuth() if action == 'getSources': try: item_information = tools.get_item_information(actionArgs) # # This tomfoolery here is the new workaround for Seren to skip the building playlist window if tools.getSetting( 'smartplay.playlistcreate') == 'true' or smartPlay: if tools.playList.size() > 0: playlist_uris = [ tools.playList[i].getPath() for i in range(tools.playList.size()) ] else: playlist_uris = [] if ('showInfo' in item_information and tools.playList.size() == 0) \ or not any(sys.argv[2] in i for i in playlist_uris): try: name = item_information['info']['title'] item = tools.addDirectoryItem( name, 'getSources', item_information['info'], item_information['art'], item_information['cast'], isFolder=False, isPlayable=True, actionArgs=actionArgs, bulk_add=True, set_ids=item_information['ids']) tools.cancelPlayback() tools.playList.add(url=sys.argv[0] + sys.argv[2], listitem=item[1]) tools.player().play(tools.playList) return except: import traceback traceback.print_exc() return bookmark_style = tools.getSetting('general.bookmarkstyle') if tools.playList.size( ) == 1 and resume is not None and bookmark_style != '2' and not forceresumeoff: if bookmark_style == '0' and not forceresumeon: import datetime selection = tools.showDialog.contextmenu([ '{} {}'.format( tools.lang(32092), datetime.timedelta(seconds=int(resume))), tools.lang(40350) ]) if selection == -1: tools.cancelPlayback() sys.exit() elif selection != 0: resume = None else: resume = None # Assume if we couldn't get information using the normal method, that it's the legacy method if item_information is None: item_information = actionArgs if not tools.premium_check(): tools.showDialog.ok(tools.addonName, tools.lang(40146), tools.lang(40147)) return None if tools.playList.getposition() == 0 and tools.getSetting( 'general.scrapedisplay') == '0': display_background = True else: display_background = False from resources.lib.modules.skin_manager import SkinManager if display_background: from resources.lib.gui.windows.persistent_background import PersistentBackground background = PersistentBackground( *SkinManager().confirm_skin_path( 'persistent_background.xml'), actionArgs=actionArgs) background.setText(tools.lang(32045)) background.show() from resources.lib.modules import getSources uncached_sources, source_results, args = database.get( getSources.getSourcesHelper, 1, actionArgs, seren_reload=seren_reload, seren_sources=True) if len(source_results) <= 0: tools.showDialog.notification(tools.addonName, tools.lang(32047), time=5000) return if 'showInfo' in item_information: source_select_style = 'Episodes' else: source_select_style = 'Movie' if tools.getSetting( 'general.playstyle%s' % source_select_style) == '1' or source_select == 'true': try: background.setText(tools.lang(40135)) except: pass from resources.lib.modules import sourceSelect stream_link = sourceSelect.sourceSelect( uncached_sources, source_results, actionArgs) if stream_link is None: tools.showDialog.notification(tools.addonName, tools.lang(32047), time=5000) raise Exception if not stream_link: # user has backed out of source select, don't show no playable sources notification raise Exception else: try: background.setText(tools.lang(32046)) except: pass from resources.lib.modules import resolver resolver_window = resolver.Resolver( *SkinManager().confirm_skin_path('resolver.xml'), actionArgs=actionArgs) stream_link = database.get(resolver_window.doModal, 1, source_results, args, pack_select, seren_reload=seren_reload) del resolver_window if stream_link is None: tools.closeBusyDialog() tools.showDialog.notification(tools.addonName, tools.lang(32047), time=5000) raise Exception tools.showBusyDialog() try: background.close() except: pass try: del background except: pass from resources.lib.modules import player # if 'resume' not in actionArgs: # actionArgs = json.loads(actionArgs) # actionArgs['resume'] = sys.argv[3].split(':')[-1] # actionArgs = json.dumps(actionArgs, sort_keys=True) player.serenPlayer().play_source(stream_link, actionArgs, resume_time=resume, params=params) except: import traceback traceback.print_exc() # Perform cleanup and make sure all open windows close and playlist is cleared try: tools.closeBusyDialog() except: pass try: background.close() except: pass try: del background except: pass try: resolver_window.close() except: pass try: del resolver_window except: pass try: tools.playList.clear() except: pass try: tools.closeOkDialog() except: pass try: tools.cancelPlayback() except: pass if action == 'preScrape': from resources.lib.modules.skin_manager import SkinManager try: item_information = tools.get_item_information(actionArgs) if 'showInfo' in item_information: source_select_style = 'Episodes' else: source_select_style = 'Movie' from resources.lib.modules import getSources uncached_sources, source_results, args = database.get( getSources.getSourcesHelper, 1, actionArgs, seren_reload=seren_reload, seren_sources=True) if tools.getSetting('general.playstyle%s' % source_select_style) == '0': from resources.lib.modules import resolver resolver_window = resolver.Resolver( *SkinManager().confirm_skin_path('resolver.xml'), actionArgs=actionArgs) database.get(resolver_window.doModal, 1, source_results, args, pack_select, seren_reload=seren_reload) tools.setSetting(id='general.tempSilent', value='false') except: tools.setSetting(id='general.tempSilent', value='false') import traceback traceback.print_exc() pass tools.log('Pre-scraping completed') if action == 'authRealDebrid': from resources.lib.debrid import real_debrid real_debrid.RealDebrid().auth() if action == 'showsHome': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().discoverShows() if action == 'myShows': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myShows() if action == 'showsMyCollection': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myShowCollection() if action == 'showsMyWatchlist': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myShowWatchlist() if action == 'showsMyProgress': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myProgress() if action == 'showsMyRecentEpisodes': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myRecentEpisodes() if action == 'showsPopular': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsPopular(page) if action == 'showsRecommended': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsRecommended() if action == 'showsTrending': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsTrending(page) if action == 'showsPlayed': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsPlayed(page) if action == 'showsWatched': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsWatched(page) if action == 'showsCollected': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsCollected(page) if action == 'showsAnticipated': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsAnticipated(page) if action == 'showsUpdated': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsUpdated(page) if action == 'showsSearch': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsSearch(actionArgs) if action == 'showsSearchResults': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsSearchResults(actionArgs) if action == 'showsSearchHistory': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showSearchHistory() if action == 'showSeasons': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showSeasons(actionArgs) if action == 'seasonEpisodes': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().seasonEpisodes(actionArgs) if action == 'showsRelated': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsRelated(actionArgs) if action == 'showYears': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showYears(actionArgs, page) if action == 'searchMenu': from resources.lib.gui import homeMenu homeMenu.Menus().searchMenu() if action == 'toolsMenu': from resources.lib.gui import homeMenu homeMenu.Menus().toolsMenu() if action == 'clearCache': from resources.lib.common import tools tools.clearCache() if action == 'traktManager': from resources.lib.indexers import trakt trakt.TraktAPI().traktManager(actionArgs) if action == 'onDeckShows': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().onDeckShows() if action == 'onDeckMovies': from resources.lib.gui.movieMenus import Menus Menus().onDeckMovies() if action == 'cacheAssist': from resources.lib.modules import cacheAssist cacheAssist.CacheAssit(actionArgs) if action == 'tvGenres': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showGenres() if action == 'showGenresGet': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showGenreList(actionArgs, page) if action == 'movieGenres': from resources.lib.gui import movieMenus movieMenus.Menus().movieGenres() if action == 'movieGenresGet': from resources.lib.gui import movieMenus movieMenus.Menus().movieGenresList(actionArgs, page) if action == 'filePicker': from resources.lib.modules import smartPlay smartPlay.SmartPlay(actionArgs).torrent_file_picker() if action == 'shufflePlay': from resources.lib.modules import smartPlay try: smart = smartPlay.SmartPlay(actionArgs).shufflePlay() except: import traceback traceback.print_exc() pass if action == 'resetSilent': tools.setSetting('general.tempSilent', 'false') tools.showDialog.notification('{}: {}'.format(tools.addonName, tools.lang(40296)), tools.lang(32048), time=5000) if action == 'clearTorrentCache': from resources.lib.modules import database database.torrent_cache_clear() if action == 'openSettings': tools.execute('Addon.OpenSettings(%s)' % tools.addonInfo('id')) if action == 'myTraktLists': from resources.lib.indexers import trakt trakt.TraktAPI().myTraktLists(actionArgs) if action == 'traktList': from resources.lib.indexers import trakt trakt.TraktAPI().getListItems(actionArgs, page) if action == 'nonActiveAssistClear': from resources.lib.gui import debridServices debridServices.Menus().assist_non_active_clear() if action == 'debridServices': from resources.lib.gui import debridServices debridServices.Menus().home() if action == 'cacheAssistStatus': from resources.lib.gui import debridServices debridServices.Menus().get_assist_torrents() if action == 'premiumizeTransfers': from resources.lib.gui import debridServices debridServices.Menus().list_premiumize_transfers() if action == 'showsNextUp': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myNextUp() if action == 'runMaintenance': from resources.lib.common import maintenance maintenance.run_maintenance() if action == 'providerTools': from resources.lib.gui import homeMenu homeMenu.Menus().providerMenu() if action == 'adjustProviders': tools.log('adjustProviders endpoint has been deprecated') return # from resources.lib.modules import customProviders # # customProviders.providers().adjust_providers(actionArgs) if action == 'adjustPackage': tools.log('adjustPackage endpoint has been deprecated') return # DEPRECATED # from resources.lib.modules import customProviders # # customProviders.providers().adjust_providers(actionArgs, package_disable=True) if action == 'installProviders': from resources.lib.modules import customProviders customProviders.providers().install_package(actionArgs) if action == 'uninstallProviders': from resources.lib.modules import customProviders customProviders.providers().uninstall_package() if action == 'showsNew': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().newShows() if action == 'realdebridTransfers': from resources.lib.gui import debridServices debridServices.Menus().list_RD_transfers() if action == 'cleanInstall': from resources.lib.common import maintenance maintenance.wipe_install() if action == 'buildPlaylistWorkaround': from resources.lib.modules import smartPlay smartPlay.SmartPlay(actionArgs).resume_playback() if action == 'premiumizeCleanup': from resources.lib.common import maintenance maintenance.premiumize_transfer_cleanup() if action == 'test2': pass if action == 'manualProviderUpdate': from resources.lib.modules import customProviders customProviders.providers().manual_update() if action == 'clearSearchHistory': from resources.lib.modules import database database.clearSearchHistory() if action == 'externalProviderInstall': from resources.lib.modules import customProviders confirmation = tools.showDialog.yesno(tools.addonName, tools.lang(40117)) if confirmation == 0: sys.exit() customProviders.providers().install_package(1, url=url) if action == 'externalProviderUninstall': from resources.lib.modules import customProviders confirmation = tools.showDialog.yesno(tools.addonName, tools.lang(40119) % url) if confirmation == 0: sys.exit() customProviders.providers().uninstall_package(package=url, silent=False) if action == 'showsNetworks': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsNetworks() if action == 'showsNetworkShows': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsNetworkShows(actionArgs, page) if action == 'movieYears': from resources.lib.gui import movieMenus movieMenus.Menus().movieYears() if action == 'movieYearsMovies': from resources.lib.gui import movieMenus movieMenus.Menus().movieYearsMovies(actionArgs, page) if action == 'syncTraktActivities': from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase TraktSyncDatabase().sync_activities() if action == 'traktSyncTools': from resources.lib.gui import homeMenu homeMenu.Menus().traktSyncTools() if action == 'flushTraktActivities': from resources.lib.modules import trakt_sync trakt_sync.TraktSyncDatabase().flush_activities() if action == 'flushTraktDBMeta': from resources.lib.modules import trakt_sync trakt_sync.TraktSyncDatabase().clear_all_meta() if action == 'myFiles': from resources.lib.gui import myFiles myFiles.Menus().home() if action == 'myFilesFolder': from resources.lib.gui import myFiles myFiles.Menus().myFilesFolder(actionArgs) if action == 'myFilesPlay': from resources.lib.gui import myFiles myFiles.Menus().myFilesPlay(actionArgs) if action == 'forceTraktSync': from resources.lib.modules import trakt_sync from resources.lib.modules.trakt_sync.activities import TraktSyncDatabase trakt_sync.TraktSyncDatabase().flush_activities() TraktSyncDatabase().sync_activities() if action == 'rebuildTraktDatabase': from resources.lib.modules.trakt_sync import TraktSyncDatabase TraktSyncDatabase().re_build_database() if action == 'myUpcomingEpisodes': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myUpcomingEpisodes() if action == 'myWatchedEpisodes': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().myWatchedEpisodes(page) if action == 'myWatchedMovies': from resources.lib.gui import movieMenus movieMenus.Menus().myWatchedMovies(page) if action == 'showsByActor': from resources.lib.gui import tvshowMenus tvshowMenus.Menus().showsByActor(actionArgs) if action == 'movieByActor': from resources.lib.gui import movieMenus movieMenus.Menus().moviesByActor(actionArgs) if action == 'playFromRandomPoint': from resources.lib.modules import smartPlay smartPlay.SmartPlay(actionArgs).play_from_random_point() if action == 'refreshProviders': from resources.lib.modules.customProviders import providers providers().update_known_providers() if action == 'installSkin': from resources.lib.modules.skin_manager import SkinManager SkinManager().install_skin() if action == 'uninstallSkin': from resources.lib.modules.skin_manager import SkinManager SkinManager().uninstall_skin() if action == 'switchSkin': from resources.lib.modules.skin_manager import SkinManager SkinManager().switch_skin() if action == 'manageProviders': tools.showBusyDialog() from resources.lib.gui.windows.custom_providers import CustomProviders from resources.lib.modules.skin_manager import SkinManager CustomProviders(*SkinManager().confirm_skin_path( 'custom_providers.xml')).doModal() if action == 'flatEpisodes': from resources.lib.gui.tvshowMenus import Menus Menus().flat_episode_list(actionArgs) if action == 'runPlayerDialogs': from resources.lib.modules.player import PlayerDialogs try: PlayerDialogs().display_dialog() except: import traceback traceback.print_exc() if action == 'authAllDebrid': from resources.lib.debrid.all_debrid import AllDebrid AllDebrid().auth() if action == 'checkSkinUpdates': from resources.lib.modules.skin_manager import SkinManager SkinManager().check_for_updates() if action == 'authPremiumize': from resources.lib.debrid.premiumize import Premiumize Premiumize().auth()
def workaround(self): actionArgs = tools.quote( json.dumps(self.info_dictionary, sort_keys=True)) tools.execute( 'RunPlugin(plugin://plugin.video.%s?action=buildPlaylistWorkaround&actionArgs=%s)' % (tools.addonName.lower(), actionArgs))
def smart_play_show(self, append_playlist=False): self.window = windows.smart_play_background() self.window.setBackground(self.poster) self.window.setText(tools.lang(32094).encode('utf-8')) self.window.show() self.window.setProgress(0) self.window.setProgress(40) self.window.setText(tools.lang(32095).encode('utf-8')) if not append_playlist: tools.playList.clear() if 'episodeInfo' not in self.info_dictionary: if tools.getSetting('trakt.auth') == '': tools.showDialog.ok(tools.addonName, tools.lang(32093).encode('utf-8')) return season, episode = self.get_resume_episode() if self.final_episode_check(season, episode) is True: season = 1 episode = 1 season_object = TraktAPI().json_response( 'shows/%s/seasons?extended=full' % self.info_dictionary['ids']['trakt']) season_object = [x for x in season_object if x['number'] == season] self.info_dictionary = tvshowMenus.Menus().seasonListBuilder( season_object, self.info_dictionary, smartPlay=True) self.info_dictionary = json.loads( tools.unquote(self.info_dictionary)) else: season = self.info_dictionary['episodeInfo']['info']['season'] episode = self.info_dictionary['episodeInfo']['info']['episode'] self.window.setText(tools.lang(32096).encode('utf-8')) self.window.setProgress(60) episode_list = database.get( TraktAPI().json_response, 12, 'shows/%s/seasons/%s?extended=full' % (self.show_trakt_id, str(season))) playlist = [] for i in episode_list: if i['number'] < episode: continue playlist.append(i) if append_playlist: tools.log("STARTING PLAYLIST GENERATION") playlist = tvshowMenus.Menus().episodeListBuilder( playlist, self.info_dictionary, smartPlay=True) for i in playlist: tools.log("ADDING ITEM TO PLAYLIST") tools.playList.add(url=i[0], listitem=i[1]) return self.window.setText(tools.lang(32097).encode('utf-8')) self.window.setProgress(80) actionArgs = {} actionArgs['playlist'] = playlist actionArgs['info_dictionary'] = self.info_dictionary actionArgs = tools.quote(json.dumps(actionArgs)) # Begin nasty Kodi 18 Skin workaround tools.execute( 'RunPlugin(plugin://plugin.video.%s?action=buildPlaylist&actionArgs=%s)' % (tools.addonName.lower(), actionArgs)) self.window.close()
traceback.print_exc() pass if action == 'resetSilent': tools.setSetting('general.tempSilent', 'false') tools.showDialog.notification(tools.addonName + ": Silent scrape", tools.lang(32048), time=5000) if action == 'clearTorrentCache': from resources.lib.modules import database database.torrent_cache_clear() if action == 'openSettings': tools.execute('Addon.OpenSettings(%s)' % tools.addonInfo('id')) if action == 'myTraktLists': from resources.lib.indexers import trakt trakt.TraktAPI().myTraktLists(actionArgs) if action == 'traktList': from resources.lib.indexers import trakt trakt.TraktAPI().getListItems(actionArgs, page) if action == 'nonActiveAssistClear': from resources.lib.gui import debridServices debridServices.Menus().assist_non_active_clear()
def getSourcesWorkaround(self, actionArgs): tools.execute( 'RunPlugin(plugin://plugin.video.%s?action=getSourcesWorkaround2&actionArgs=%s)' % (tools.addonName.lower(), tools.quote(actionArgs)))
def build_cache_assist(self, args): if tools.getSetting('general.autocache') == 'false': return if len(self.allTorrents) == 0: return if len(self.torrentCacheSources) > 0: return build_list = [] if tools.getSetting('general.cacheAssistMode') == "0": quality_list = ['1080p', '720p', 'SD'] for quality in quality_list: if len(build_list) > 0: break if len([ i for i in self.torrentCacheSources if i['quality'] == quality ]) == 0: quality_filter = [ i for i in self.allTorrents if i['quality'] == quality ] if len(quality_filter) > 0: packtype_filter = [ i for i in quality_filter if i['package'] == 'show' or i['package'] == 'season' ] sorted_list = sorted(packtype_filter, key=lambda k: k['seeds'], reverse=True) for i in sorted_list: print(i) if len(sorted_list) > 0: build_list.append(sorted_list[0]) break else: package_type_list = [ i for i in quality_filter if i['package'] == 'single' ] sorted_list = sorted(package_type_list, key=lambda k: k['seeds'], reverse=True) if sorted_list > 0: build_list.append(sorted_list[0]) else: if self.silent is True: return yesno = tools.showDialog.yesno( '%s - Cache Assist' % tools.addonName, tools.lang(32086).encode('utf-8')) if yesno == 0: return display_list = [ '%sS | %s | %s | %s' % (i['seeds'], tools.color_quality( i['quality']), tools.source_size_display( i['size']), tools.colorString(i['release_title'])) for i in self.allTorrents ] selection = tools.showDialog.select( '%s - ' % tools.addonName + tools.lang(32087).encode('utf-8'), display_list) if selection == -1: return build_list.append(self.allTorrents[selection]) if len(build_list) > 0: actionArgs = {'torrent_list': build_list, 'args': args} actionArgs = tools.quote(json.dumps(actionArgs)) tools.execute('RunPlugin(%s?action=cacheAssist&actionArgs=%s)' % (sysaddon, actionArgs)) return
def keepAlive(self): for i in range(0, 480): tools.kodi.sleep(250) if self.isPlayingVideo(): break for i in range(0, 480): if self.AVStarted: break tools.closeAllDialogs() self.media_length = self.getTotalTime() if self.offset is not None and self.offset != 0: tools.log("Seeking {} seconds".format(self.offset)) self.seekTime(self.offset) self.offset = None while self.isPlayingVideo() and not self.scrobbled: try: watched_percentage = self.getWatchedPercent() time_left = int(self.getTotalTime()) - int(self.getTime()) try: self.current_time = self.getTime() except: import traceback traceback.print_exc() pass if not self.playback_started: tools.kodi.sleep(1000) continue if watched_percentage > 80 or time_left <= self.min_time_before_scrape: if self.pre_cache_initiated is False: try: if tools.getSetting( 'smartPlay.preScrape') == 'true': self.pre_cache_initiated = True smartPlay.SmartPlay( self.original_action_args).pre_scrape() except: import traceback traceback.print_exc() pass if watched_percentage > 80: self.traktStopWatching() self.handleBookmark() break except: import traceback traceback.print_exc() tools.kodi.sleep(1000) continue tools.kodi.sleep(1000) else: self.traktStopWatching() return if tools.getSetting('smartplay.playingnextdialog') == 'true' or \ tools.getSetting('smartplay.stillwatching') == 'true': endpoint = int(tools.getSetting('playingnext.time')) else: endpoint = False if endpoint: while self.isPlayingVideo(): if int(self.getTotalTime()) - int(self.getTime()) <= endpoint: tools.execute( 'RunPlugin("plugin://plugin.video.seren/?action=runPlayerDialogs")' ) break else: tools.kodi.sleep(1000) self.traktStopWatching()
'userdata', 'addon_data') dir_listing = os.listdir(data_path) if 'plugin.video.Seren' in dir_listing: os.rename(os.path.join(data_path, 'plugin.video.Seren'), os.path.join(data_path, 'plugin.video.seren')) tools.showDialog.ok( 'Seren', 'Because of an issue with original addon ID on release,' ' Seren requires a restart of Kodi after this update.\n' 'Please restart Kodi now.') except: tools.showDialog.ok( tools.addonName, 'Migration from bugged initial release has failed.\n' 'Please uninstall Seren, re-start kodi and try again') tools.log('Checking Common API Tokens for refresh') maintenance.run_maintenance() tools.log('Initial API Checks have completed succesfully') monitor = xbmc.Monitor() tools.log('############# SERVICE ENTERED KEEP ALIVE #################') while not monitor.abortRequested(): try: if monitor.waitForAbort(60 * 30): break tools.execute( 'RunPlugin("plugin://plugin.video.%s/?action=runMaintenance")' % tools.addonName.lower()) except: continue
def smart_play_show(self): self.window = windows.smart_play_background() self.window.setBackground(self.poster) self.window.setText("Begining SmartPlay") self.window.show() self.window.setProgress(0) self.window.setProgress(40) self.window.setText('Identifying Resume Point') tools.playList.clear() if 'episodeInfo' not in self.info_dictionary: if tools.getSetting('trakt.auth') == '': tools.showDialog.ok( tools.addonName, 'Error: Trakt is not authorized \n' 'Please authorise Trakt in the settings menu to use this feature' ) return season, episode = self.get_resume_episode() if self.final_episode_check(season, episode) is True: season = 1 episode = 1 season_object = TraktAPI().json_response( 'shows/%s/seasons?extended=full' % self.info_dictionary['ids']['trakt']) season_object = [x for x in season_object if x['number'] == season] self.info_dictionary = tvshowMenus.Menus().seasonListBuilder( season_object, self.info_dictionary, smartPlay=True) self.info_dictionary = json.loads( tools.unquote(self.info_dictionary)) else: season = self.info_dictionary['episodeInfo']['info']['season'] episode = self.info_dictionary['episodeInfo']['info']['episode'] self.window.setText('Building PlayList') self.window.setProgress(60) episode_list = database.get( TraktAPI().json_response, 12, 'shows/%s/seasons/%s?extended=full' % (self.show_trakt_id, str(season))) playlist = [] for i in episode_list: if i['number'] < episode: continue playlist.append(i) self.window.setText('Building List Items') self.window.setProgress(80) actionArgs = {} actionArgs['playlist'] = playlist actionArgs['info_dictionary'] = self.info_dictionary actionArgs = tools.quote(json.dumps(actionArgs)) # Begin nasty Kodi 18 Skin workaround tools.execute( 'RunPlugin(plugin://plugin.video.%s?action=buildPlaylist&actionArgs=%s)' % (tools.addonName.lower(), actionArgs)) self.window.close()
def install_zip(self, zip_file, silent=False): file_list = zip_file.namelist() for i in file_list: if i.startswith('/') or '..' in i: raise Exception zip_root_dir = '' if file_list[0].endswith('/'): zip_root_dir = file_list[0] for i, v in enumerate(file_list): file_list[i] = file_list[i].replace(zip_root_dir, '') file_list = file_list[1:] meta_file = None for i in file_list: if i.startswith('meta.json'): meta_file = i break if meta_file is not None: meta = zip_file.open(zip_root_dir + meta_file) meta = meta.readlines() meta = ''.join(meta) meta = meta.replace(' ', '').replace('\r', '').replace('\n', '') meta = json.loads(meta) requirements = ['author', 'name', 'version'] for i in requirements: if i not in meta: if not silent: self.failed_prompt() tools.log( 'Source pack is malformed, please check and correct issue in the meta file' ) return author = meta['author'] version = meta['version'] pack_name = meta['name'] remote_meta = meta.get('remote_meta', '') else: if not silent: self.failed_prompt() tools.log( 'Source pack is malformed, please check and correct issue in the meta file' ) import traceback traceback.print_exc() raise Exception if remote_meta == '': tools.showDialog.ok(tools.addonName, tools.lang(33016)) line1 = tools.colorString( tools.lang(33001)) + " %s - v%s" % (pack_name, version) line2 = tools.colorString(tools.lang(33002)) + "%s" % author line3 = tools.lang(33003) if not silent: accept = tools.showDialog.yesno( tools.addonName + " - %s" % tools.lang(33004), line1, line2, line3, tools.lang(33005), tools.lang(33006)) if accept == 0: return self.pre_update_collection = [ i for i in database.get_providers() if i['package'] == pack_name ] folders = ['providerModules/', 'providers/'] meta_output_location = os.path.join(tools.dataPath, 'providerMeta', '%s.json' % pack_name) if os.path.isfile(meta_output_location): if os.path.isfile(meta_output_location + '.temp'): os.remove(meta_output_location + '.temp') try: os.rename(meta_output_location, '%s.temp' % meta_output_location) except Exception as e: self.failure_cleanup(meta_output_location, pack_name, folders) tools.log('Failed to create temporary meta file') if not silent: tools.showDialog.ok(tools.addonName, tools.lang(33007)) return try: self.output_meta(meta) except: self.failure_cleanup(meta_output_location, pack_name, folders) tools.log('Failed to create new meta file') if not silent: self.failed_prompt() return else: self.output_meta(meta) if not silent: install_progress = tools.progressDialog install_progress.create(tools.addonName, '%s - %s' % (pack_name, tools.lang(33008)), tools.lang(33009)) install_progress.update(-1) try: for folder in folders: try: folder_path = os.path.join(tools.dataPath, folder.strip('/'), pack_name) if os.path.exists(folder_path): if os.path.exists('%s.temp' % folder_path): shutil.rmtree('%s.temp' % folder_path) os.rename(folder_path, '%s.temp' % folder_path) for file in file_list: if file == 'providers/__init__.py': continue if file.startswith(folder): memberpath = os.path.join(zip_root_dir, file) targetpath = os.path.join(tools.dataPath, file) upperdirs = os.path.dirname(targetpath) if upperdirs and not os.path.exists(upperdirs): os.makedirs(upperdirs) if memberpath[-1] == '/': if not os.path.isdir(targetpath): os.mkdir(targetpath) continue with zip_file.open(memberpath) as source, \ open(targetpath, "wb") as target: shutil.copyfileobj(source, target) except: tools.log('Failed to extract to folder - %s' % folder) import traceback traceback.print_exc() self.failure_cleanup(meta_output_location, pack_name, folders) if not silent: self.failed_prompt() return try: zip_file.close() except: pass if not silent: try: install_progress.close() except: pass if not silent: tools.showDialog.ok(tools.addonName, '%s - %s' % (tools.lang(33010), pack_name)) except: import traceback traceback.print_exc() if not silent: try: install_progress.close() tools.showDialog.ok( tools.addonName, '%s - %s' % (tools.lang(33012), pack_name), tools.lang(33011)) except: pass return if os.path.exists('%s.temp' % meta_output_location): os.remove('%s.temp' % meta_output_location) for folder in folders: folder_path = os.path.join(tools.dataPath, folder.strip('/'), pack_name) if os.path.exists('%s.temp' % folder_path): shutil.rmtree('%s.temp' % folder_path) tools.log('Refreshing provider database ') database.add_provider_package(pack_name, author, remote_meta, version) tools.execute( 'RunPlugin("plugin://plugin.video.%s/?action=refreshProviders")' % tools.addonName.lower()) return True