def add_remove_movie(self, silent=False): from resources.lib.modules.utils import to_utf8 from resources.lib.modules.kodi_library import get_library_video self.add_remove_database() if self.action == 'add': in_library = get_library_video( 'movie', self.title, self.year) if settings.skip_duplicates() else False if in_library: return self.make_folder() self.make_nfo() stream_file = self.create_movie_strm_files() params = to_utf8({ 'mode': 'play_media', 'library': 'True', 'query': self.rootname, 'poster': self.meta['poster'], 'year': self.year, 'plot': self.meta['plot'], 'title': self.title, 'tmdb_id': self.meta['tmdb_id'], 'vid_type': 'movie' }) self.make_stream(stream_file, params) elif self.action == 'remove': self.remove_folder() if not silent: notification('{}'.format(self.notify % self.rootname), 4500)
def toggle_jump_to(): from resources.lib.modules.nav_utils import toggle_setting, notification from resources.lib.modules.settings import nav_jump_use_alphabet use_alphabet = nav_jump_use_alphabet() (setting, new_action) = ('0', 'PAGE') if use_alphabet == True else ('1', 'ALPHABET') toggle_setting(setting_id='nav_jump', setting_value=setting, refresh=True) notification('Jump To Action Switched to [B]%s[/B]' % new_action)
def clear_subscriptions(self, confirm=True, silent=False): if confirm: if not self.subscription_choice( 'Choose Subscriptions to Erase', 'Continuing will erase all your {}'): return self.db_type = self.choice[1] self.path = settings.movies_directory( ) if self.db_type == 'movie' else settings.tv_show_directory() subscriptions = self.get_subscriptions() if len(subscriptions) == 0: return notification( '{}'.format('%s Subscriptions is already empty' % self.db_type.upper()), 4500) self.remove_folder(self.path) self.make_folder(self.path) dbcon = database.connect(self.sub_database, timeout=40.0) dbcur = dbcon.cursor() for item in subscriptions: dbcur.execute( "DELETE FROM subscriptions where db_type=? and tmdb_id=?", (self.db_type, item['tmdb_id'])) dbcur.execute("VACUUM") dbcon.commit() dbcon.close() if not silent: notification( '{}'.format('%s Subscriptions has been cleared' % self.db_type.upper()), 4500)
def refresh_icon(): import xbmcvfs, xbmcgui try: from sqlite3 import dbapi2 as database except ImportError: from pysqlite2 import dbapi2 as database from resources.lib.modules.nav_utils import notification try: icon_path = xbmc.translatePath(os.path.join(ADDON_PATH, 'icon.png')) thumbs_folder = xbmc.translatePath('special://thumbnails') TEXTURE_DB = xbmc.translatePath(os.path.join('special://database', 'Textures13.db')) dbcon = database.connect(TEXTURE_DB) dbcur = dbcon.cursor() dbcur.execute("""SELECT cachedurl FROM texture WHERE url = ?""", (icon_path,)) image = dbcur.fetchone()[0] dbcon.close() removal_path = os.path.join(thumbs_folder, image) if xbmcgui.Dialog().yesno("Fen", 'Add-on Icon about to be refreshed.', 'Continue?', '', 'No', 'Yes'): xbmcvfs.delete(removal_path) xbmc.sleep(200) xbmc.executebuiltin('ReloadSkin()') xbmc.sleep(500) notice = '[B]Success!![/B] Icon refreshed.' else: return except: notice = '[B]Error!![/B] deleting icon from database' notification(notice)
def nextEpPrep(self): auto_nextep_limit_reached = False autoplay_next_check_threshold = settings.autoplay_next_check_threshold( ) try: current_number = int( window.getProperty('current_autoplay_next_number')) except: current_number = 1 if autoplay_next_check_threshold != 0: if current_number == autoplay_next_check_threshold: auto_nextep_limit_reached = True continue_playing = xbmcgui.Dialog().yesno( 'Fen Next Episode', '[B]Are you still watching %s?[/B]' % self.meta['title'], '', '', 'Not Watching', 'Still Watching', 10000) if not continue_playing == 1: from resources.lib.modules.nav_utils import notification notification('Fen Next Episode Cancelled', 6000) self.nextep_info = {'pass': True} if not self.nextep_info: from resources.lib.modules.next_episode import nextep_playback_info, nextep_play self.nextep_info = nextep_playback_info(self.meta['tmdb_id'], int(self.meta['season']), int(self.meta['episode']), self.library_setting) if not self.nextep_info.get('pass', False): if not auto_nextep_limit_reached: self.delete_nextep_playcount = False window.setProperty('current_autoplay_next_number', str(current_number + 1)) nextep_play(self.nextep_info)
def update_subscriptions(self): from datetime import datetime, timedelta from resources.lib.modules.nav_utils import close_all_dialog self.db_type = 'tvshow' self.action = 'add' self.path = settings.tv_show_directory() subscriptions = self.get_subscriptions() if not subscriptions: return notification( '{0}'.format('No TV Show Subscriptions to update'), 1200) hours = settings.subscription_timer() close_all_dialog() bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', 'Preparing Subscription Update...') for count, item in enumerate(subscriptions, 1): self.tmdb_id = item['tmdb_id'] self.add_remove_constants() self.add_remove_tvshow(silent=True) display = 'Fen Updating - [B][I]%s[/I][/B]' % self.rootname bg_dialog.update( int(float(count) / float(len(subscriptions)) * 100), 'Please Wait', '%s' % display) xbmc.sleep(300) __addon__.setSetting( 'service_time', str(datetime.now() + timedelta(hours=hours)).split('.')[0]) bg_dialog.close() notification('{}'.format('Fen Subscriptions Updated'), 4500) if settings.update_library_after_service(): xbmc.executebuiltin('UpdateLibrary(video)')
def remake_subscriptions(self): if not self.subscription_choice('Choose Subscriptions to Remake', 'Continuing will remake all your {}'): return self.db_type = self.choice[1] self.action = 'add' self.path = settings.movies_directory( ) if self.db_type == 'movie' else settings.tv_show_directory() subscriptions = self.get_subscriptions() if len(subscriptions) == 0: return notification( '{}'.format('%s Subscriptions is empty' % self.db_type.upper()), 4500) self.clear_subscriptions(confirm=False, silent=True) bg_dialog = xbmcgui.DialogProgress() bg_dialog.create('Please Wait', '') for count, item in enumerate(subscriptions, 1): display = 'Fen Updating %s' % self.choice[0] bg_dialog.update( int(float(count) / float(len(subscriptions)) * 100), 'Please Wait', '%s' % display) self.tmdb_id = item['tmdb_id'] self.add_remove_constants() self.add_remove_movie( silent=True ) if self.db_type == 'movie' else self.add_remove_tvshow( silent=True) xbmc.sleep(300) bg_dialog.close() notification('All %s remade' % self.choice[0], 4500)
def remove_from_favourites(self): if self.db_type == 'audio': self.title = self.tmdb_id.split('<>')[0] dbcon = database.connect(self.fav_database) dbcon.execute("DELETE FROM favourites where db_type=? and tmdb_id=?", (self.db_type, str(self.tmdb_id))) dbcon.commit() dbcon.close() xbmc.executebuiltin("Container.Refresh") notification('[B]%s[/B] removed from Favourites' % self.title.upper(), 3500)
def play_auto_nextep(self): from resources.lib.modules.nav_utils import notification try: results = json.loads(window.getProperty('fen_search_results')) except: return meta = json.loads(window.getProperty('fen_media_meta')) notification('%s %s S%02dE%02d' % ('[B]Next Up:[/B]', meta['title'], meta['season'], meta['episode']), 10000, meta['poster']) while xbmc.Player().isPlaying(): xbmc.sleep(100) xbmc.sleep(1500) return self.play_auto()
def add_remove_tvshow(self, silent=False): self.add_remove_database() if self.action == 'add': self.make_folder() self.make_nfo() self.create_tvshow_strm_files() elif self.action == 'remove': self.remove_folder() if not silent: notification('{}'.format(self.notify % self.rootname), 4500)
def add_to_favourites_audio(self): try: self.db_type = 'audio' self.title = self.dialog.input( 'Choose Name for New Fen Music Favourite', type=xbmcgui.INPUT_ALPHANUM, defaultt=self.name) self.tmdb_id = '%s<>%s<>%s<>%s' % (to_unicode( self.title), self.id, self.url_dl, self.size) self.add_to_favourites() except: notification('Error Adding Item to Favourites', 3500)
def add_to_favourites(self): try: dbcon = database.connect(self.fav_database) dbcon.execute( "INSERT INTO favourites VALUES (?, ?, ?)", (self.db_type, str(self.tmdb_id), to_unicode(self.title))) dbcon.commit() dbcon.close() notification('[B]%s[/B] added to Favourites' % self.title.upper(), 3500) except: notification( '[B]%s[/B] already in Favourites' % self.title.upper(), 3500)
def myfiles_protect_unprotect(name='', item_id='', action=''): from resources.lib.modules.nav_utils import notification params = dict(parse_qsl(sys.argv[2].replace('?', ''))) name = params.get('name') if 'name' in params else name item_id = params.get('item_id') if 'item_id' in params else item_id action = params.get('action') if 'action' in params else action is_protected = '1' if action == 'protect' else '0' line1 = 'File added to Protected List' if action == 'protect' else 'File removed from Protected List' try: response = Furk.file_protect(item_id, is_protected) if response['status'] == 'ok': xbmc.executebuiltin("Container.Refresh") notification(line1, time=7000) except: return
def add_next_episode_unwatched(action=None, media_id=None, silent=False): from urlparse import parse_qsl from resources.lib.modules.nav_utils import notification from resources.lib.modules.indicators_bookmarks import mark_as_watched_unwatched settings.check_database(WATCHED_DB) params = dict(parse_qsl(sys.argv[2].replace('?',''))) media_id = params['tmdb_id'] if not media_id else media_id action = params['action'] if not action else action if action == 'add': command, line1 = "INSERT OR IGNORE INTO unwatched_next_episode VALUES (?)", '%s Added to Fen Next Episode' % params.get('title') else: command, line1 = "DELETE FROM unwatched_next_episode WHERE media_id=?", '%s Removed from Fen Next Episode' % params.get('title') dbcon = database.connect(WATCHED_DB) dbcon.execute(command, (media_id,)) dbcon.commit() dbcon.close() if not silent: notification(line1, time=3500) xbmc.sleep(500) xbmc.executebuiltin("Container.Refresh")
def remove_from_history(): import xbmc import sys from urlparse import parse_qsl from resources.lib.modules.nav_utils import notification params = dict(parse_qsl(sys.argv[2].replace('?', ''))) try: result = _cache.get(params['setting_id']) result.remove(params.get('name')) _cache.set(params['setting_id'], result, expiration=timedelta(days=365)) notification( '[B]%s[/B] Removed from History' % params.get('name').upper(), 3500) xbmc.executebuiltin('Container.Refresh') except: return
def add_to_files(name='', item_id=''): from resources.lib.modules.nav_utils import notification params = dict(parse_qsl(sys.argv[2].replace('?', ''))) name = params.get('name') if 'name' in params else name item_id = params.get('item_id') if 'item_id' in params else item_id resp = dialog.yesno('Are you sure?', "Add\n[B]%s[/B]\nto My Furk Files?" % name) if resp: response = Furk.file_link(item_id) if response['status'] == 'ok': notification('{}'.format('Item added to My Furk Files'), 3500) else: notification( '{}'.format('Error - [B][I]%s[/I][/B]' % response['status']), 3500) return (None, None) dialog.close() else: return
def clear_favourites(self): fl = [('Movie Favourites', 'movie'), ('TV Show Favourites', 'tvshow'), ('Music Favourites', 'audio')] fl_choose = self.dialog.select("Choose Favourites to Erase", [i[0] for i in fl]) if fl_choose < 0: return selection = fl[fl_choose] self.db_type = selection[1] confirm = self.dialog.yesno( 'Are you sure?', 'Continuing will erase all your [B]%s[/B]' % selection[0]) if not confirm: return dbcon = database.connect(self.fav_database) dbcon.execute("DELETE FROM favourites WHERE db_type=?", (self.db_type, )) dbcon.execute("VACUUM") dbcon.commit() dbcon.close() notification('[B]%s[/B] Erased' % selection[0], 3000)
def add_to_remove_from_next_episode_excludes(): from urlparse import parse_qsl from resources.lib.modules.nav_utils import notification settings.check_database(WATCHED_DB) params = dict(parse_qsl(sys.argv[2].replace('?',''))) action = params.get('action') media_id = str(params.get('media_id')) title = str(params.get('title')) dbcon = database.connect(WATCHED_DB) if action == 'add': dbcon.execute("INSERT INTO exclude_from_next_episode VALUES (?, ?)", (media_id, title)) line1 = '[B]{}[/B] excluded from Fen Next Episode'.format(title.upper()) elif action == 'remove': dbcon.execute("DELETE FROM exclude_from_next_episode WHERE media_id=?", (media_id,)) line1 = '[B]{}[/B] included in Fen Next Episode'.format(title.upper()) dbcon.commit() dbcon.close() notification('{}'.format(line1), time=5000) xbmc.sleep(500) xbmc.executebuiltin("Container.Refresh")
def add_remove(self): self.add_remove_constants() if self.check_exists_database() and self.action == 'add': return notification( '{}'.format('[B]%s[/B] already in Subscriptions' % self.rootname), 4500) self.add_remove_movie( ) if self.db_type == 'movie' else self.add_remove_tvshow() if self.orig_mode in ('subscriptions_tvshows', 'subscriptions_movies' ) and self.action == 'remove': xbmc.executebuiltin('Container.Refresh')
def remove_from_files(name='', item_id=''): from resources.lib.modules.nav_utils import notification params = dict(parse_qsl(sys.argv[2].replace('?', ''))) name = params.get('name') item_id = params.get('item_id') resp = dialog.yesno('Are you sure?', "Remove [B][I]%s[/I][/B] from My Furk Files?" % name) if resp: response = Furk.file_unlink(item_id) if response['status'] == 'ok': notification('{}'.format('Item removed from My Furk Files'), 3500) xbmc.executebuiltin("Container.Refresh") else: notification( '{}'.format('Error - [B][I]%s[/I][/B]' % response['status']), 3500) return (None, None) dialog.close() else: return
def build_next_episode(): sync_watched_trakt_to_fen() try: threads = [] seen = set() ep_list = [] ne_settings = settings.nextep_content_settings() ne_display = settings.nextep_display_settings() if ne_settings['include_unwatched']: for i in get_unwatched_next_episodes(): ep_list.append(i) if settings.watched_indicators() in (1, 2): from resources.lib.modules.trakt import trakt_get_next_episodes info = trakt_get_next_episodes() for item in info: try: ep_list.append({"tmdb_id": get_trakt_tvshow_id(item), "season": item['season'], "episode": item['number'], "last_played": item['show']['last_watched_at']}) except: pass else: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute('''SELECT media_id, season, episode, last_played FROM watched_status WHERE db_type=?''', ('episode',)) rows = dbcur.fetchall() rows = sorted(rows, key = lambda x: (x[0], x[1], x[2]), reverse=True) [ep_list.append({"tmdb_id": a, "season": int(b), "episode": int(c), "last_played": d}) for a, b, c, d in rows if not (a in seen or seen.add(a))] ep_list = [x for x in ep_list if x['tmdb_id'] not in check_for_next_episode_excludes()] ep_list = [i for i in ep_list if not i['tmdb_id'] == None] for item in ep_list: threads.append(Thread(process_eps, item, ne_settings, ne_display)) [i.start() for i in threads] [i.join() for i in threads] r = [i for i in result if i is not None] r = sort_next_eps(r, ne_settings) listitems = [i['listitem'] for i in r] xbmcplugin.addDirectoryItems(__handle__, listitems, len(listitems)) xbmcplugin.setContent(__handle__, 'episodes') xbmcplugin.endOfDirectory(__handle__) setView('view.progress_next_episode') except: from resources.lib.modules.nav_utils import notification notification('Error getting Next Episode Info', time=3500) pass
def mark_episode_as_watched_unwatched(params=None): from resources.lib.modules.next_episode import add_next_episode_unwatched params = dict(parse_qsl(sys.argv[2].replace('?', ''))) if not params else params action = 'mark_as_watched' if params.get( 'action') == 'mark_as_watched' else 'mark_as_unwatched' media_id = params.get('media_id') tvdb_id = int(params.get('tvdb_id', '0')) imdb_id = params.get('imdb_id') season = int(params.get('season')) episode = int(params.get('episode')) title = params.get('title') year = params.get('year') from_search = params.get('from_search', 'false') watched_indicators = settings.watched_indicators() if season == 0: from resources.lib.modules.nav_utils import notification notification( 'Specials cannot be marked as %s' % ('Watched' if action == 'mark_as_watched' else 'Unwatched'), time=5000) return if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'episode', imdb_id, tvdb_id, season, episode) clear_trakt_watched_data('tvshow', imdb_id) erase_bookmark('episode', media_id, season, episode) if watched_indicators in (0, 1): mark_as_watched_unwatched('episode', media_id, action, season, episode, title) if action == 'mark_as_watched': add_next_episode_unwatched('remove', media_id, silent=True) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library('episode', action, title, year, season, episode) refresh_container(from_search)
def clear_search_history(): import xbmcgui from resources.lib.modules.nav_utils import notification dialog = xbmcgui.Dialog() choice_list = [('Delete Movie Search History', 'movie_queries', 'Movie'), ('Delete TV Show Search History', 'tvshow_queries', 'TV Show'), ('Delete Furk Video Search History', 'furk_video_queries', 'Furk Video'), ('Delete Furk Audio Search History', 'furk_audio_queries', 'Furk Audio'), ('Delete Easynews Video Search History', 'easynews_video_queries', 'Easynews Video')] try: selection = dialog.select('Choose Search History to Delete', [i[0] for i in choice_list]) if selection < 0: return setting = choice_list[selection][1] _cache.set(setting, '', expiration=timedelta(days=365)) notification("%s Search History Removed" % choice_list[selection][2], 3500) except: return
def next_episode_options_choice(setting=None): from urlparse import parse_qsl from resources.lib.modules.nav_utils import notification from resources.lib.modules.utils import selection_dialog params = dict(parse_qsl(sys.argv[2].replace('?',''))) choices = [('Sort Type', 'nextep.sort_type', [('RECENTLY WATCHED', '0'), ('AIRDATE', '1'), ('TITLE', '2')]), ('Sort Order', 'nextep.sort_order', [('DESCENDING', '0'), ('ASCENDING', '1')]), ('Include Unaired', 'nextep.include_unaired', [('OFF', 'false'), ('ON', 'true')]), ('Include Trakt or Fen Unwatched', 'nextep.include_unwatched', [('OFF', 'false'), ('ON', 'true')]), ('Include Airdate in Title', 'nextep.include_airdate', [('OFF', 'false'), ('ON', 'true')]), ('Attempt to Make Skin Honor Full Labels', 'nextep.force_display', [('OFF', 'false'), ('ON', 'true')]), ('Airdate Format', 'nextep.airdate_format', [('DAY-MONTH-YEAR', '0'), ('YEAR-MONTH-DAY', '1'), ('MONTH-DAY-YEAR', '2')])] prelim_setting = params.get('setting') if not setting else setting title, setting = [(i[0], i[1]) for i in choices if i[0] == prelim_setting][0] string = 'Please Choose Setting for %s' % title full_list = [i[2] for i in choices if i[0] == prelim_setting][0] dialog_list = [i[0] for i in full_list] function_list = [i[1] for i in full_list] selection = selection_dialog(dialog_list, function_list, string) if not selection: return setting_name = [i[0] for i in full_list if i[1] == selection][0] __addon__.setSetting(setting, selection) notification('%s set to %s' % (title, setting_name), 6000)
def add_list_to_subscriptions(self, user, list_slug): if not xbmcgui.Dialog().yesno( 'Are you sure?', 'Fen will add all Movies and/or TV Shows from this list to your Fen Subscriptions. Do you wish to continue?' ): return from resources.lib.modules.trakt import call_trakt info = [] self.action = 'add' bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', 'Preparing Trakt List Info...') data = call_trakt("users/{0}/lists/{1}/items?extended=full".format( user, list_slug), method='sort_by_headers') for count, item in enumerate(data, 1): try: self.db_type, trakt_type = ( 'movie', 'movie') if item['type'] == 'movie' else ('tvshow', 'show') ids = item[trakt_type]['ids'] self.tmdb_id = ids['tmdb'] self.path = settings.movies_directory( ) if self.db_type == 'movie' else settings.tv_show_directory() self.add_remove_constants() self.add_remove_movie( silent=True ) if self.db_type == 'movie' else self.add_remove_tvshow( silent=True) display = 'Adding to Subscriptions: [I][B]%s[/B][/I]' % self.rootname bg_dialog.update(int(float(count) / float(len(data)) * 100), 'Please Wait', '%s' % display) except: pass bg_dialog.close() notification('List added to Subscriptions', 4500) return True
def mark_as_watched_unwatched(db_type='', media_id='', action='', season='', episode='', title=''): try: settings.check_database(WATCHED_DB) last_played = datetime.now().strftime('%Y-%m-%d %H:%M:%S') dbcon = database.connect(WATCHED_DB, timeout=40.0) erase_bookmark(db_type, media_id, season, episode) if action == 'mark_as_watched': dbcon.execute( "INSERT OR IGNORE INTO watched_status VALUES (?, ?, ?, ?, ?, ?)", (db_type, media_id, season, episode, last_played, to_unicode(title))) elif action == 'mark_as_unwatched': dbcon.execute( "DELETE FROM watched_status WHERE (db_type = ? and media_id = ? and season = ? and episode = ?)", (db_type, media_id, season, episode)) dbcon.commit() except: from resources.lib.modules.nav_utils import notification notification('Error Marking Watched in Fen', time=5000)
def build_next_episode_manager(): from urlparse import parse_qsl from resources.lib.indexers.tvshows import aired_episode_number_tvshow from resources.lib.modules.nav_utils import add_dir from resources.lib.modules.indicators_bookmarks import get_watched_status_tvshow params = dict(parse_qsl(sys.argv[2].replace('?',''))) NEXT_EP_UNWATCHED = __addon__.getSetting('nextep.unwatched_colour') if not NEXT_EP_UNWATCHED or NEXT_EP_UNWATCHED == '': NEXT_EP_UNWATCHED = 'red' VIEW_NEM = __addon__.getSetting('view.main') sorted_list = [] action = params['action'] if action == 'manage_unwatched': tmdb_list = [i['tmdb_id'] for i in get_unwatched_next_episodes()] heading = 'Select Show to remove from Fen Next Episode:' elif settings.watched_indicators() in (1, 2): from resources.lib.modules.trakt import trakt_get_next_episodes tmdb_list, exclude_list = trakt_get_next_episodes(include_hidden=True) heading = 'Select Show to Hide/Unhide from Trakt Progress:' else: settings.check_database(WATCHED_DB) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute('''SELECT media_id FROM watched_status WHERE db_type=? GROUP BY media_id''', ('episode',)) rows = dbcur.fetchall() tmdb_list = [row[0] for row in rows] exclude_list = check_for_next_episode_excludes() heading = 'Select Show to Include/Exclude in Fen Next Episode:' add_dir({'mode': 'nill'}, '[I][COLOR=grey][B]INFO:[/B][/COLOR] [COLOR=grey2]%s[/COLOR][/I]' % heading, iconImage='settings.png') if not tmdb_list: from resources.lib.modules.nav_utils import notification notification('No Shows Present', time=5000) else: for tmdb_id in tmdb_list: try: meta = make_fresh_tvshow_meta('tmdb_id', tmdb_id) if action == 'manage_unwatched': action, display = 'remove', '[COLOR=%s][UNWATCHED][/COLOR] %s' % (NEXT_EP_UNWATCHED, meta['title']) url_params = {'mode': 'add_next_episode_unwatched', 'action': 'remove', 'tmdb_id': meta['tmdb_id'], 'title': meta['title']} elif settings.watched_indicators() in (1, 2): action, display = 'unhide' if str(meta['tmdb_id']) in exclude_list else 'hide', '[COLOR=red][EXCLUDED][/COLOR] %s' % meta['title'] if str(meta['tmdb_id']) in exclude_list else '[COLOR=green][INCLUDED][/COLOR] %s' % meta['title'] url_params = {"mode": "hide_unhide_trakt_items", "action": action, "media_type": "shows", "media_id": meta['imdb_id'], "section": "progress_watched"} else: action, display = 'remove' if str(meta['tmdb_id']) in exclude_list else 'add', '[COLOR=red][EXCLUDED][/COLOR] %s' % meta['title'] if str(meta['tmdb_id']) in exclude_list else '[COLOR=green][INCLUDED][/COLOR] %s' % meta['title'] url_params = {'mode': 'add_to_remove_from_next_episode_excludes', 'action': action, 'title': meta['title'], 'media_id': meta['tmdb_id']} sorted_list.append({'tmdb_id': tmdb_id, 'display': display, 'url_params': url_params, 'meta': json.dumps(meta)}) except: pass sorted_items = sorted(sorted_list, key=lambda k: k['display']) for i in sorted_items: try: cm = [] meta = json.loads(i['meta']) rootname = meta['title'] + " (" + str(meta['year']) + ")" meta['rootname'] = rootname aired_episodes = aired_episode_number_tvshow(meta) playcount, overlay, total_watched, total_unwatched = get_watched_status_tvshow(meta['tmdb_id'], aired_episodes) url = build_url(i['url_params']) browse_url = build_url({'mode': 'build_season_list', 'meta': i['meta']}) cm.append(("[B]Browse...[/B]",'XBMC.Container.Update(%s)' % browse_url)) listitem = xbmcgui.ListItem(i['display']) listitem.setProperty('watchedepisodes', str(total_watched)) listitem.setProperty('unwatchedepisodes', str(total_unwatched)) listitem.setProperty('totalepisodes', str(aired_episodes)) listitem.setProperty('totalseasons', str(meta['number_of_seasons'])) listitem.addContextMenuItems(cm) listitem.setArt({'poster': meta['poster'], 'fanart': meta['fanart'], 'banner': meta['banner'], 'clearart': meta['clearart'], 'clearlogo': meta['clearlogo'], 'landscape': meta['landscape']}) listitem.setCast(meta['cast']) listitem.setInfo( 'video', { 'title': meta['title'], 'size': '0', 'duration': meta['duration'], 'plot': meta['plot'], 'rating': meta['rating'], 'premiered': meta['premiered'], 'studio': meta['studio'],'year': meta['year'], 'genre': meta['genre'],'imdbnumber': meta['imdb_id'], 'votes': meta['votes'], 'playcount': playcount, 'overlay': overlay}) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'tvshows') xbmcplugin.endOfDirectory(__handle__, cacheToDisc=False) setView(VIEW_NEM)
def mark_tv_show_as_watched_unwatched(): from resources.lib.modules.next_episode import add_next_episode_unwatched params = dict(parse_qsl(sys.argv[2].replace('?', ''))) action = 'mark_as_watched' if params.get( 'action') == 'mark_as_watched' else 'mark_as_unwatched' media_id = params.get('media_id') tvdb_id = int(params.get('tvdb_id', '0')) imdb_id = params.get('imdb_id') from_search = params.get('from_search', 'false') watched_indicators = settings.watched_indicators() if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'shows', imdb_id, tvdb_id) clear_trakt_watched_data('tvshow', imdb_id) if watched_indicators in (0, 1): import tikimeta from resources.lib.indexers.tvshows import make_fresh_tvshow_meta title = params.get('title', '') year = params.get('year', '') bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', '') se_list = [] count = 1 s_data = make_fresh_tvshow_meta('tmdb_id', media_id) season_data = s_data['season_data'] total = sum([ i['episode_count'] for i in season_data if i['season_number'] > 0 ]) for item in season_data: season_number = int(item['season_number']) if season_number <= 0: continue season_id = item['id'] infoLabels = tikimeta.season_episodes_meta(media_id, season_number) ep_data = infoLabels['episodes'] for item in ep_data: season_number = item['season_number'] ep_number = item['episode_number'] season_ep = '%.2d<>%.2d' % (int(season_number), int(ep_number)) display = 'Updating - S%.2dE%.2d' % (int(season_number), int(ep_number)) bg_dialog.update(int(float(count) / float(total) * 100), 'Please Wait', '%s' % display) count += 1 try: first_aired = item['air_date'] d = first_aired.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) except: episode_date = date(2100, 10, 24) if not settings.adjusted_datetime() > episode_date: continue mark_as_watched_unwatched('episode', media_id, action, season_number, ep_number, title) se_list.append(season_ep) bg_dialog.close() if action == 'mark_as_watched': add_next_episode_unwatched('remove', media_id, silent=True) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import get_library_video, batch_mark_episodes_as_watched_unwatched_kodi_library in_library = get_library_video('tvshow', title, year) if not in_library: refresh_container(from_search) return from resources.lib.modules.nav_utils import notification notification('Browse back to Kodi Home Screen!!', time=7000) xbmc.sleep(8500) ep_dict = { 'action': action, 'tvshowid': in_library['tvshowid'], 'season_ep_list': se_list } if batch_mark_episodes_as_watched_unwatched_kodi_library( in_library, ep_dict): notification('Kodi Library Sync Complete', time=5000) refresh_container(from_search)
def download(name, image, url): from resources.lib.modules import settings # from resources.lib.modules.utils import logger if url == None: from resources.lib.modules.nav_utils import notification notification('No URL found for Download. Pick another Source', 6000) return params = dict(urlparse.parse_qsl(sys.argv[2].replace('?', ''))) json_meta = params.get('meta') if json_meta: meta = json.loads(json_meta) db_type = meta.get('vid_type') title = meta.get('title') year = meta.get('year') image = meta.get('poster') season = meta.get('season') episode = meta.get('episode') else: db_type = params.get('db_type') image = params.get('image') media_folder = settings.download_directory(db_type) if not media_folder: resp = xbmcgui.Dialog().yesno( "No Download folder set!", "Fen requires you to set Download Folders.", "Would you like to set a folder now?") if resp: from resources.lib.modules.nav_utils import open_settings open_settings('7.0') else: return if db_type in ('movie', 'episode'): folder_rootname = '%s (%s)' % (title, year) folder = os.path.join(media_folder, folder_rootname + '/') else: folder = media_folder if not xbmcvfs.exists(folder): xbmcvfs.mkdir(folder) if db_type == 'episode': folder = os.path.join(folder, 'Season ' + str(season)) if not xbmcvfs.exists(folder): xbmcvfs.mkdir(folder) try: headers = dict(urlparse.parse_qsl(url.rsplit('|', 1)[1])) except: headers = dict('') dest = None url = url.split('|')[0] if not 'http' in url: from resources.lib.modules.furk_api import FurkAPI from resources.lib.indexers.furk import filter_furk_tlist, seas_ep_query_list t_files = FurkAPI().t_files(url) t_files = [i for i in t_files if 'video' in i['ct'] and 'bitrate' in i] name, url = filter_furk_tlist( t_files, (None if db_type == 'movie' else seas_ep_query_list( season, episode)))[0:2] dest = os.path.join(folder, name) if db_type == 'archive': ext = 'zip' else: ext = os.path.splitext(urlparse.urlparse(url).path)[1][1:] if not ext in ['mp4', 'mkv', 'flv', 'avi', 'mpg']: ext = 'mp4' if not dest: transname = name.translate(None, '\/:*?"<>|').strip('.') dest = os.path.join(folder, transname + '.' + ext) sysheaders = urllib.quote_plus(json.dumps(headers)) sysurl = urllib.quote_plus(url) systitle = urllib.quote_plus(name) sysimage = urllib.quote_plus(image) sysdest = urllib.quote_plus(dest) script = inspect.getfile(inspect.currentframe()) cmd = 'RunScript(%s, %s, %s, %s, %s, %s)' % ( script, sysurl, sysdest, systitle, sysimage, sysheaders) xbmc.executebuiltin(cmd)
def mark_season_as_watched_unwatched(): from resources.lib.modules.next_episode import add_next_episode_unwatched params = dict(parse_qsl(sys.argv[2].replace('?', ''))) action = 'mark_as_watched' if params.get( 'action') == 'mark_as_watched' else 'mark_as_unwatched' season = int(params.get('season')) title = params.get('title') year = params.get('year') media_id = params.get('media_id') tvdb_id = int(params.get('tvdb_id', '0')) imdb_id = params.get('imdb_id') watched_indicators = settings.watched_indicators() if season == 0: from resources.lib.modules.nav_utils import notification notification( 'Specials cannot be marked as %s' % ('Watched' if action == 'mark_as_watched' else 'Unwatched'), time=5000) return if watched_indicators in (1, 2): from resources.lib.modules.trakt import trakt_watched_unwatched trakt_watched_unwatched(action, 'season', imdb_id, tvdb_id, season) clear_trakt_watched_data('tvshow', imdb_id) if watched_indicators in (0, 1): import tikimeta bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', '') infoLabels = tikimeta.season_episodes_meta(media_id, season) ep_data = infoLabels['episodes'] count = 1 se_list = [] for item in ep_data: season_number = item['season_number'] ep_number = item['episode_number'] season_ep = '%.2d<>%.2d' % (season_number, ep_number) display = 'Updating - S%.2dE%.2d' % (season_number, ep_number) try: first_aired = item['air_date'] d = first_aired.split('-') episode_date = date(int(d[0]), int(d[1]), int(d[2])) except: episode_date = date(2100, 10, 24) if not settings.adjusted_datetime() > episode_date: continue display = 'Updating - S%.2dE%.2d' % (season_number, ep_number) bg_dialog.update(int(float(count) / float(len(ep_data)) * 100), 'Please Wait', '%s' % display) count += 1 mark_as_watched_unwatched('episode', media_id, action, season_number, ep_number, title) se_list.append(season_ep) bg_dialog.close() if action == 'mark_as_watched': add_next_episode_unwatched('remove', media_id, silent=True) if settings.sync_kodi_library_watchstatus(): from resources.lib.modules.kodi_library import get_library_video, batch_mark_episodes_as_watched_unwatched_kodi_library in_library = get_library_video('tvshow', title, year) if not in_library: xbmc.executebuiltin("Container.Refresh") return ep_dict = { 'action': action, 'tvshowid': in_library['tvshowid'], 'season_ep_list': se_list } if batch_mark_episodes_as_watched_unwatched_kodi_library( in_library, ep_dict): from resources.lib.modules.nav_utils import notification notification('Kodi Library Sync Complete', time=5000) refresh_container()