def set_bookmark(db_type, tmdb_id, curr_time, total_time, season='', episode=''): try: erase_bookmark(db_type, tmdb_id, season, episode) adjusted_current_time = float(curr_time) - 5 resume_point = round(adjusted_current_time / float(total_time) * 100, 1) watched_indicators = settings.watched_indicators() if watched_indicators == 1: trakt_progress('set_progress', db_type, tmdb_id, resume_point, season, episode) database_file = TRAKT_DB else: database_file = WATCHED_DB dbcon = database.connect(database_file) dbcur = dbcon.cursor() dbcur.execute("INSERT INTO progress VALUES (?, ?, ?, ?, ?, ?)", (db_type, tmdb_id, season, episode, str(resume_point), str(curr_time))) dbcon.commit() if settings.sync_kodi_library_watchstatus(): from modules.kodi_library import set_bookmark_kodi_library set_bookmark_kodi_library(db_type, tmdb_id, curr_time, total_time, season, episode) except: pass
def mark_as_watched_unwatched_movie(params): action = params.get('action') db_type = 'movie' tmdb_id = params.get('tmdb_id') title = params.get('title') year = params.get('year') refresh = params.get('refresh', 'true') from_playback = params.get('from_playback', 'false') watched_indicators = settings.watched_indicators() if watched_indicators == 1: if from_playback == 'true' and trakt_official_status(db_type) == False: skip_trakt_mark = True else: skip_trakt_mark = False if skip_trakt_mark: kodi_utils.sleep(3000) elif not trakt_watched_unwatched(action, 'movies', tmdb_id): return kodi_utils.notification(32574) clear_trakt_collection_watchlist_data('watchlist', db_type) data_base = TRAKT_DB data_base = TRAKT_DB else: data_base = WATCHED_DB mark_as_watched_unwatched(db_type, tmdb_id, action, title=title, data_base=data_base) erase_bookmark(db_type, tmdb_id) if settings.sync_kodi_library_watchstatus(): from modules.kodi_library import mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library(db_type, action, title, year) refresh_container(refresh)
def mark_as_watched_unwatched_tvshow(params): action = params.get('action') tmdb_id = params.get('tmdb_id') try: tvdb_id = int(params.get('tvdb_id', '0')) except: tvdb_id = 0 watched_indicators = settings.watched_indicators() kodi_utils.progressDialogBG.create(ls(32577), '') if watched_indicators == 1: if not trakt_watched_unwatched(action, 'shows', tmdb_id, tvdb_id): return kodi_utils.notification(32574) clear_trakt_collection_watchlist_data('watchlist', 'tvshow') data_base = TRAKT_DB else: data_base = WATCHED_DB title = params.get('title', '') year = params.get('year', '') meta_user_info = metadata.retrieve_user_info() adjust_hours = settings.date_offset() current_date = get_datetime() insert_list = [] insert_append = insert_list.append meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info) season_data = meta['season_data'] season_data = [i for i in season_data if i['season_number'] > 0] total = len(season_data) last_played = get_last_played_value(data_base) for count, item in enumerate(season_data, 1): season_number = item['season_number'] ep_data = metadata.season_episodes_meta(season_number, meta, meta_user_info) for ep in ep_data: season_number = ep['season'] ep_number = ep['episode'] display = 'S%.2dE%.2d' % (int(season_number), int(ep_number)) kodi_utils.progressDialogBG.update( int(float(count) / float(total) * 100), ls(32577), '%s' % display) episode_date, premiered = adjust_premiered_date( ep['premiered'], adjust_hours) if not episode_date or current_date < episode_date: continue insert_append( make_batch_insert(action, 'episode', tmdb_id, season_number, ep_number, last_played, title)) batch_mark_as_watched_unwatched(insert_list, action, data_base) batch_erase_bookmark(insert_list, action, watched_indicators) kodi_utils.progressDialogBG.close() if settings.sync_kodi_library_watchstatus(): batch_mark_kodi_library(action, insert_list, title, year) refresh_container()
def mark_episode_as_watched_unwatched(params=None): from 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') refresh = params.get('refresh', 'true') from_playback = params.get('from_playback', 'false') watched_indicators = settings.watched_indicators() if season == 0: from 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): import time from apis.trakt_api import trakt_watched_unwatched, trakt_official_status if from_playback == 'true' and trakt_official_status( 'episode') == False: skip_trakt_mark = True else: skip_trakt_mark = False if not skip_trakt_mark: trakt_watched_unwatched(action, 'episode', imdb_id, tvdb_id, season, episode) if skip_trakt_mark: time.sleep(3) clear_trakt_watched_data('tvshow') clear_trakt_collection_watchlist_data('watchlist', 'tvshow') if watched_indicators in (0, 1): mark_as_watched_unwatched('episode', media_id, action, season, episode, title) erase_bookmark('episode', media_id, season, episode) 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 mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library('episode', action, title, year, season, episode) refresh_container(refresh)
def set_bookmark(db_type, media_id, curr_time, total_time, season='', episode=''): settings.check_database(WATCHED_DB) erase_bookmark(db_type, media_id, season, episode) adjusted_current_time = float(curr_time) - 5 resume_point = round(adjusted_current_time / float(total_time) * 100, 1) dbcon = database.connect(WATCHED_DB) dbcur = dbcon.cursor() dbcur.execute("INSERT INTO progress VALUES (?, ?, ?, ?, ?, ?)", (db_type, media_id, season, episode, str(resume_point), str(curr_time))) dbcon.commit() if settings.sync_kodi_library_watchstatus(): from modules.kodi_library import set_bookmark_kodi_library set_bookmark_kodi_library(db_type, media_id, curr_time, season, episode)
def mark_as_watched_unwatched_episode(params): action = params.get('action') db_type = 'episode' tmdb_id = params.get('tmdb_id') try: tvdb_id = int(params.get('tvdb_id', '0')) except: tvdb_id = 0 season = int(params.get('season')) episode = int(params.get('episode')) title = params.get('title') year = params.get('year') refresh = params.get('refresh', 'true') from_playback = params.get('from_playback', 'false') watched_indicators = settings.watched_indicators() if season == 0: kodi_utils.notification(32490) return if watched_indicators == 1: if from_playback == 'true' and trakt_official_status(db_type) == False: skip_trakt_mark = True else: skip_trakt_mark = False if skip_trakt_mark: kodi_utils.sleep(3000) elif not trakt_watched_unwatched(action, db_type, tmdb_id, tvdb_id, season, episode): return kodi_utils.notification(32574) clear_trakt_collection_watchlist_data('watchlist', 'tvshow') data_base = TRAKT_DB else: data_base = WATCHED_DB mark_as_watched_unwatched(db_type, tmdb_id, action, season, episode, title, data_base) erase_bookmark(db_type, tmdb_id, season, episode) if settings.sync_kodi_library_watchstatus(): from modules.kodi_library import mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library(db_type, action, title, year, season, episode) refresh_container(refresh)
def mark_movie_as_watched_unwatched(params=None): params = dict(parse_qsl(sys.argv[2].replace('?', ''))) if not params else params action = params.get('action') db_type = 'movie' media_id = params.get('media_id') title = params.get('title') year = params.get('year') refresh = params.get('refresh', 'true') watched_indicators = settings.watched_indicators() if watched_indicators in (1, 2): from apis.trakt_api import trakt_watched_unwatched trakt_watched_unwatched(action, 'movies', media_id) clear_trakt_watched_data(db_type) clear_trakt_collection_watchlist_data('watchlist', 'movie') if watched_indicators in (0, 1): mark_as_watched_unwatched(db_type, media_id, action, title=title) erase_bookmark(db_type, media_id) if settings.sync_kodi_library_watchstatus(): from modules.kodi_library import mark_as_watched_unwatched_kodi_library mark_as_watched_unwatched_kodi_library(db_type, action, title, year) refresh_container()
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()