def update_library(): import mediapoisk.container as container from plugin import plugin from mediapoisk.common import lang, batch, abort_requested from xbmcswift2 import xbmcgui from contextlib import closing log = logging.getLogger(__name__) library_manager = container.library_manager() scraper = container.scraper() media_ids = library_manager.stored_media_ids() if media_ids: log.info("Starting MediaPoisk.info library update...") progress = xbmcgui.DialogProgressBG() with closing(progress): progress.create(lang(30000), lang(40322)) processed = 0 for section, media_ids in media_ids.iteritems(): for ids in batch(media_ids): all_details = scraper.get_details_bulk(section, ids) all_folders = scraper.get_folders_bulk(section, ids) for media_id, details in all_details.items(): if media_id in all_folders: for folder in all_folders[media_id]: if library_manager.has_folder(folder.id): library_manager.update_folder(details, folder) processed += len(ids) progress.update(processed*100/len(media_ids)) if abort_requested(): break log.info("MediaPoisk.ru library update finished.") if plugin.get_setting('update-xbmc-library', bool): log.info("Starting XBMC library update...") plugin.update_library('video', library_manager.path)
def bookmarks_index(section): plugin.set_content("movies") section = Section.find(section) bookmarks = container.bookmarks().get(section) total = len(bookmarks) for b in batch(reversed(bookmarks)): if abort_requested(): break items = itemify_bookmarks(b) plugin.add_items(items, total) plugin.finish(sort_methods=["unsorted", "title", "video_year", "video_rating"], cache_to_disc=False)
def library_items(): scraper = container.scraper() library_manager = container.library_manager() for section, media_ids in library_manager.stored_media_ids().items(): for ids in batch(media_ids): if abort_requested(): break all_folders = scraper.get_folders_bulk(section, ids) all_details = scraper.get_details_bulk(section, ids) items = [ itemify_library_folder(all_details[media_id], f) for media_id, folders in all_folders.iteritems() for f in folders if library_manager.has_folder(f.id) ] plugin.add_items(items) plugin.finish(sort_methods=["title"], cache_to_disc=False)
def make_search(sf, header=None, cache_to_disc=False, update_listing=False): skip = plugin.request.arg('skip') scraper = container.scraper() results = scraper.search_cached(sf, skip) if not results: return False if isinstance(results, Details): if header: plugin.add_items(with_fanart(header)) item = itemify_single_result(results) plugin.finish(items=[item], cache_to_disc=cache_to_disc, update_listing=update_listing) return True total = len(results) items = [] if skip: skip_prev = max(skip - sf.page_size, 0) total += 1 items.append({ 'label': lang(34003), 'path': plugin.request.url_with_params(skip=skip_prev) }) elif header: items.extend(header) total += len(header) plugin.add_items(with_fanart(items), total) for batch_res in batch(results): if abort_requested(): break items = itemify_search_results(sf.section, batch_res) plugin.add_items(items, total) items = [] if scraper.has_more: skip_next = (skip or 0) + sf.page_size items.append({ 'label': lang(34004), 'path': plugin.request.url_with_params(skip=skip_next) }) plugin.finish(items=with_fanart(items), sort_methods=['unsorted', 'date', 'title', 'video_year', 'video_rating'], cache_to_disc=cache_to_disc, update_listing=update_listing or skip is not None) return True