def get_tvshows_in_directory(self, directory): ''' Get all TV shows in the directory, and tag the items ''' dir_items = self.filter_blocked_items(list( utils.load_directory_items(progressdialog=None, dir_path=directory, allow_directories=True, recursive=True, sync_type='tvshow')), mediatype='tvshow') all_items = [] # Check every tvshow in list for dir_item in dir_items: show_title = dir_item['label'] # Load results if show isn't blocked show_path = dir_item['file'] show_items = self.filter_blocked_items(list( utils.load_directory_items(progressdialog=None, dir_path=show_path, recursive=True, sync_type='tvshow')), mediatype='episode') for show_item in show_items: # Add formatted item show_item['mediatype'] = 'tvshow' show_item['show_title'] = show_title all_items += show_items return all_items
def sync_tvshow_directory(self, dir_label, dir_path): ''' Sync all TV shows in directory and stage items''' STR_GETTING_ITEMS_IN_DIR = utils.ADDON.getLocalizedString(32125) STR_GETTING_ITEMS_IN_x = utils.ADDON.getLocalizedString(32126) STR_i_EPISODES_STAGED = utils.ADDON.getLocalizedString(32112) p_dialog = xbmcgui.DialogProgress() p_dialog.create(utils.ADDON_NAME) try: # add synced directory to database self.dbh.add_synced_dir(dir_label, dir_path, 'tvshow') # query json-rpc to get files in directory p_dialog.update(0, line1=STR_GETTING_ITEMS_IN_DIR) dir_items = utils.load_directory_items(dir_path, allow_directories=True) items_to_stage = 0 for index, dir_item in enumerate(dir_items): # Get name of show and skip if blocked tvshow_label = dir_item['label'] if self.dbh.check_blocked(tvshow_label, 'tvshow'): continue # Update progress percent = 100 * index / len(dir_items) p_dialog.update(percent, line1=(STR_GETTING_ITEMS_IN_x % tvshow_label)) # Get everything inside tvshow path tvshow_path = dir_item['file'] show_items = utils.load_directory_items(tvshow_path, recursive=True) # Get all items to stage in show for show_item in show_items: # Check for duplicate paths and blocked items if self.dbh.path_exists( show_item['file']) or self.dbh.check_blocked( show_item['label'], 'episode'): continue # Update progress p_dialog.update(percent, line2=show_item['label']) self.dbh.add_content_item(show_item['file'], show_item['label'], 'tvshow', tvshow_label) items_to_stage += 1 p_dialog.update(percent, line2=' ') p_dialog.update(percent, line1=' ') utils.notification(STR_i_EPISODES_STAGED % items_to_stage) finally: p_dialog.close()
def sync_single_tvshow(self, show_label, show_path): ''' Sync single tvshow directory and stage items ''' STR_i_NEW_i_STAGED_i_MANAGED = utils.ADDON.getLocalizedString(32106) STR_i_NEW = utils.ADDON.getLocalizedString(32107) # Add synced directory to database self.dbh.add_synced_dir(show_label, show_path, 'single-tvshow') # Get everything inside tvshow path dir_items = utils.load_directory_items(show_path, recursive=True) # Get all items to stage items_to_stage = 0 num_already_staged = 0 num_already_managed = 0 for dir_item in dir_items: item_label = dir_item['label'] item_path = dir_item['file'] if self.dbh.path_exists(item_path, 'staged'): num_already_staged += 1 continue elif self.dbh.path_exists(item_path, 'managed'): num_already_managed += 1 continue elif self.dbh.check_blocked(item_label, 'episode'): continue self.dbh.add_content_item(item_path, item_label, 'tvshow', show_label) items_to_stage += 1 if num_already_staged > 0 or num_already_managed > 0: utils.notification( STR_i_NEW_i_STAGED_i_MANAGED % (items_to_stage, num_already_staged, num_already_managed) ) else: utils.notification(STR_i_NEW % items_to_stage)
def sync_movie_directory(self, dir_label, dir_path): ''' Sync movie directory and stage items ''' STR_GETTING_ITEMS_IN_DIR = utils.ADDON.getLocalizedString(32125) STR_i_MOVIES_STAGED = utils.ADDON.getLocalizedString(32111) p_dialog = xbmcgui.DialogProgress() p_dialog.create(utils.ADDON_NAME) try: # Add synced directory to database self.dbh.add_synced_dir(dir_label, dir_path, 'movie') # Query json-rpc to get files in directory p_dialog.update(0, line1=STR_GETTING_ITEMS_IN_DIR) dir_items = utils.load_directory_items(dir_path, recursive=True) # Loop through all items and get titles and paths and stage them items_to_stage = 0 for index, dir_item in enumerate(dir_items): # Get label & path for item item_label = dir_item['label'] item_path = dir_item['file'] if self.dbh.path_exists(item_path) or self.dbh.check_blocked(item_label, 'movie'): continue # Update progress percent = 100 * index / len(dir_items) p_dialog.update(percent, line2=item_label) # Add item to database self.dbh.add_content_item(item_path, item_label, 'movie') items_to_stage += 1 p_dialog.update(percent, line2=' ') utils.notification(STR_i_MOVIES_STAGED % items_to_stage) finally: p_dialog.close()
def get_movies_in_directory(self, directory): ''' Get all movies in the directory and tags them ''' dir_items = self.filter_blocked_items( utils.load_directory_items(directory, recursive=True), 'movie') for item in dir_items: # Add tag to items item['mediatype'] = 'movie' return dir_items
def get_single_tvshow(self, directory, show_title): ''' Get the single TV show in the directory, and tag the items''' show_items = self.filter_blocked_items( utils.load_directory_items(directory, recursive=True), 'episode') for item in show_items: # Add tag to items item['mediatype'] = 'tvshow' item['show_title'] = show_title return show_items
def get_movies_in_directory(self, directory): ''' Get all movies in the directory and tags them ''' dir_items = self.filter_blocked_items(list( utils.load_directory_items(progressdialog=None, dir_path=directory, recursive=True, sync_type='movie')), mediatype='movie') for item in dir_items: # Add tag to items item['mediatype'] = 'movie' return dir_items
def get_single_tvshow(self, directory, show_title): ''' Get the single TV show in the directory, and tag the items''' show_items = self.filter_blocked_items(list( utils.load_directory_items(progressdialog=None, dir_path=directory, recursive=True, sync_type='tvshow')), mediatype='episode') for item in show_items: # Add tag to items item['mediatype'] = 'tvshow' item['show_title'] = show_title return show_items
def sync_all_items_in_directory(self, sync_type, dir_label, dir_path): ''' Synchronize all items in a directory (movies/series or all), based on the user's choice and stage items ''' # TODO: new notification label to show movies, # TV shows and episodes that have been added contentdata = None content_title = None STR_GETTING_ITEMS_IN_DIR = utils.getlocalizedstring(32125) STR_GETTING_ITEMS_IN_x = utils.getlocalizedstring(32126) STR_i_EPISODES_STAGED = utils.getlocalizedstring(32112) STR_MOVIE_STAGED = utils.getlocalizedstring(32165) progressdialog = xbmcgui.DialogProgress() progressdialog.create(utils.ADDON_NAME) try: # add synced directory to database # check it in future self.dbh.add_synced_dir(dir_label, dir_path, 'tvshow') # query json-rpc to get files in directory progressdialog.update(0, line1=STR_GETTING_ITEMS_IN_DIR) files_list = list( utils.load_directory_items(progressdialog=progressdialog, dir_path=dir_path, allow_directories=True, recursive=True, sync_type=sync_type)) items_to_stage = 0 for index, content_file in enumerate(files_list): if progressdialog.iscanceled() is True: progressdialog.close() break try: content_title = content_file['movie_title'] contentdata = MovieItem( link_stream_path=content_file['file'], title=content_file['movie_title'], mediatype='movie', year=content_file['year']).returasjson() sync_type = 'movie' except KeyError: content_title = content_file['showtitle'] contentdata = EpisodeItem( link_stream_path=content_file['file'], title=content_file['title'], mediatype='tvshow', show_title=content_file['showtitle'], season=content_file['season'], epnumber=content_file['episode'], year=content_file['year']).returasjson() sync_type = 'tvshow' # Get name of show and skip if blocked # Get everything inside tvshow path # # # # # # # # # # # # # # # # # # # # type: movie or episode if self.dbh.check_blocked(content_title, content_file['type']): continue if self.dbh.path_exists( path=contentdata['link_stream_path'], status=['staged', 'managed'], # TODO: future dosen't use sync_type here mediatype=sync_type): continue # Update progress percent = 100 * index / len(files_list) # Check for duplicate paths and blocked items try: progressdialog.update( percent, line1=STR_GETTING_ITEMS_IN_x % contentdata['show_title'], line2=contentdata['episode_title_with_id']) # try add tvshow self.dbh.add_content_item(contentdata, 'tvshow') xbmc.sleep(300) except KeyError: # TODO: new dialog str to movie progressdialog.update( percent, line1=STR_MOVIE_STAGED % content_title, ) # try add movie self.dbh.add_content_item(contentdata, 'movie') xbmc.sleep(500) items_to_stage += 1 utils.notification(STR_i_EPISODES_STAGED % items_to_stage) finally: progressdialog.close()
def sync_single_tvshow(self, title, year, link_stream_path): ''' Sync single tvshow directory and stage items ''' STR_i_NEW_i_STAGED_i_MANAGED = utils.getlocalizedstring(32106) STR_i_NEW = utils.getlocalizedstring(32107) STR_GETTING_ITEMS_IN_DIR = utils.getlocalizedstring(32125) STR_GETTING_ITEMS_IN_x = utils.getlocalizedstring(32126) progressdialog = xbmcgui.DialogProgress() progressdialog.create(utils.ADDON_NAME) # Add synced directory to database self.dbh.add_synced_dir(title, link_stream_path, 'single-tvshow') # Get everything inside tvshow path files_list = list( utils.load_directory_items(progressdialog=progressdialog, dir_path=link_stream_path, allow_directories=True, recursive=True, year=year, showtitle=title, sync_type='tvshow')) # Get all items to stage items_to_stage = 0 num_already_staged = 0 num_already_managed = 0 progressdialog.update(0, line1=STR_GETTING_ITEMS_IN_DIR) for index, showfile in enumerate(files_list): if progressdialog.iscanceled() is True: progressdialog.close() break try: contentdata = EpisodeItem( # IDEA: in future, pass a json and not separeted values link_stream_path=showfile['file'], title=showfile['title'], mediatype='tvshow', show_title=title.decode('utf-8'), season=showfile['season'], epnumber=showfile['episode'], year=year if year else showfile['year']).returasjson() # Update progress percent = 100 * index / len(files_list) progressdialog.update(percent, line1=(STR_GETTING_ITEMS_IN_x % contentdata['show_title'])) if (self.dbh.path_exists(path=contentdata['link_stream_path'], status='staged', mediatype='tvshow')): num_already_staged += 1 continue elif (self.dbh.path_exists( path=contentdata['link_stream_path'], status='managed', mediatype='tvshow')): num_already_managed += 1 continue elif self.dbh.check_blocked(contentdata['show_title'], 'episode'): continue # Update progress progressdialog.update(percent, line2=contentdata['show_title']) progressdialog.update( percent, line2=contentdata['episode_title_with_id']) self.dbh.add_content_item(contentdata, 'tvshow') items_to_stage += 1 xbmc.sleep(300) except TypeError: utils.notification(utils.getlocalizedstring(32166), 4000) if num_already_staged > 0 or num_already_managed > 0: utils.notification( STR_i_NEW_i_STAGED_i_MANAGED % (items_to_stage, num_already_staged, num_already_managed)) else: utils.notification(STR_i_NEW % items_to_stage)