def batch_mark_kodi_library(action, insert_list, title, year): from 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: return if batch_mark_episodes_as_watched_unwatched_kodi_library( action, in_library, insert_list): kodi_utils.notification(32787, time=5000)
def add_trakt_subscription_listitem(self, db_type, ids, count, total, path, dialog): try: get_ids = get_trakt_movie_id if db_type in ( 'movie', 'movies') else get_trakt_tvshow_id meta_action = tikimeta.movie_meta if db_type in ( 'movie', 'movies') else tikimeta.tvshow_meta tmdb_id = get_ids(ids) address_insert = 'movie' if db_type in ('movie', 'movies') else 'tv' meta = meta_action('tmdb_id', tmdb_id, self.meta_user_info) title = clean_file_name(meta['title']) year = meta['year'] if 'year' in meta else '0' rootname = '{0} ({1})'.format(title, year) if year != '0' else title folder = os.path.join(path, rootname + '/') nfo_filename = rootname + '.nfo' if db_type in ( 'movie', 'movies') else 'tvshow.nfo' nfo_filepath = os.path.join(folder, nfo_filename) nfo_content = "https://www.themoviedb.org/%s/%s-%s" % ( address_insert, str(meta['tmdb_id']), title.lower().replace( ' ', '-')) self.make_folder(folder) self.make_nfo(nfo_filepath, nfo_content) if db_type in ('movie', 'movies'): in_library = get_library_video( 'movie', title, year) if settings.skip_duplicates() else False if in_library: return stream_file = self.create_movie_strm_files(folder, rootname) params = to_utf8({ 'mode': 'play_media', 'library': 'True', 'query': rootname, 'poster': meta['poster'], 'year': year, 'plot': meta['plot'], 'title': title, 'tmdb_id': meta['tmdb_id'], 'vid_type': 'movie' }) self.make_stream(stream_file, params) else: self.create_tvshow_strm_files(meta, folder, tmdb_id, title, year) dialog.update(int(float(count) / float(total) * 100), '', 'Adding: [B]%s[/B]' % rootname) except Exception as e: logger('add_trakt_subscription_listitem Exception', e) pass
def add_remove_movie(self, silent=False): 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(self.notify % self.rootname, 4500)
def mark_tv_show_as_watched_unwatched(): from 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') watched_indicators = settings.watched_indicators() if watched_indicators in (1, 2): from apis.trakt_api import trakt_watched_unwatched trakt_watched_unwatched(action, 'shows', imdb_id, tvdb_id) clear_trakt_watched_data('tvshow') clear_trakt_collection_watchlist_data('watchlist', 'tvshow') if watched_indicators in (0, 1): import tikimeta bg_dialog = xbmcgui.DialogProgressBG() bg_dialog.create('Please Wait', '') title = params.get('title', '') year = params.get('year', '') try: meta_user_info = json.loads(params.get('meta_user_info', )) except: meta_user_info = tikimeta.retrieve_user_info() se_list = [] count = 1 meta = tikimeta.tvshow_meta('tmdb_id', media_id, meta_user_info) season_data = tikimeta.all_episodes_meta( media_id, tvdb_id, meta['tvdb_summary']['airedSeasons'], meta['season_data'], meta_user_info) total = sum([ i['episode_count'] for i in season_data if i['season_number'] > 0 ]) for item in season_data: season_number = item['season_number'] if season_number <= 0: continue ep_data = tikimeta.season_episodes_meta( media_id, tvdb_id, season_number, meta['tvdb_summary']['airedSeasons'], meta['season_data'], meta_user_info) for ep in ep_data: season_number = ep['season'] ep_number = ep['episode'] 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 = ep['premiered'] 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 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() return if not in_library: return from 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()
def create_tvshow_strm_files(self, meta=None, folder=None, tmdb_id=None, title=None, year=None): from datetime import date from modules.utils import to_utf8 from modules.kodi_library import get_library_video if not meta: meta = self.meta if not folder: folder = self.folder if not tmdb_id: tmdb_id = self.tmdb_id if not title: title = self.title if not year: year = self.year try: skip_duplicates = settings.skip_duplicates() season_data = tikimeta.all_episodes_meta( meta['tmdb_id'], meta['tvdb_id'], meta['tvdb_summary']['airedSeasons'], meta['season_data'], self.meta_user_info) season_data = [ i for i in season_data if not i['season_number'] == 0 ] for i in season_data: try: season_path = os.path.join( folder, 'Season ' + str(i['season_number'])) self.make_folder(season_path) ep_data = i['episodes_data'] for item in ep_data: try: in_library = get_library_video( 'episode', title, year, item['airedSeason'], item['airedEpisodeNumber'] ) if skip_duplicates else None if not in_library: first_aired = item[ 'firstAired'] if 'firstAired' in item else None try: d = first_aired.split('-') episode_date = date( int(d[0]), int(d[1]), int(d[2])) except: episode_date = date(2100, 10, 24) if date.today() > episode_date: display = "%s S%.2dE%.2d" % ( title, int(item['airedSeason']), int(item['airedEpisodeNumber'])) stream_file = os.path.join( season_path, str(display) + '.strm') params = to_utf8({ 'mode': 'play_media', 'library': 'True', 'query': title, 'year': year, 'plot': item['overview'], 'poster': meta['poster'], 'season': item['airedSeason'], 'episode': item['airedEpisodeNumber'], 'ep_name': item['episodeName'], 'premiered': item['firstAired'], 'tmdb_id': tmdb_id, 'vid_type': 'episode' }) self.make_stream(stream_file, params) except: pass except: pass except: logger('meta', meta['search_title']) pass