def show_files(section, media_id, folder_id): scraper = container.scraper() section = Section.find(section) plugin.set_content("movies") files = scraper.get_files_cached(section, media_id, folder_id) plugin.add_items(itemify_file(f) for f in files) plugin.finish(sort_methods=["unsorted", "title", "duration", "size"])
def play_file(section, media_id, url, title): stream = container.torrent_stream() scraper = container.scraper() history = container.history() meta_cache = container.meta_cache() meta = meta_cache.setdefault(media_id, {}) section = Section.find(section) details = scraper.get_details_cached(section, media_id) item = itemify_details(details) title = u"%s / %s" % (ensure_unicode(title), item["info"]["title"]) item["info"]["title"] = title history.add(media_id, details.section, title, plugin.request.url, url, details.poster) history.storage.sync() torrent = container.torrent(url=url) player = container.player() def check_and_mark_watched(event): log.info("Playback event: %s, current player progress: %d", event, player.get_percent()) if player.get_percent() >= 90 and plugin.request.arg("can_mark_watched"): watched_items = container.watched_items() watched_items.mark(media_id, date_added=meta.get("date_added"), total_size=meta.get("total_size")) player.attach([player.PLAYBACK_STOPPED, player.PLAYBACK_ENDED], check_and_mark_watched) temp_files = stream.play(player, torrent, item) if temp_files: save_files(temp_files, rename=not stream.saved_files_needed, on_finish=purge_temp_dir) else: purge_temp_dir()
def turn_off_auto_refresh(section, media_id): section = Section.find(section) scraper = container.scraper() scraper.get_details_cached(section, media_id) scraper.get_folders_cached(section, media_id) container.details_cache().protect_item(media_id) container.folders_cache().protect_item(media_id) not_refreshing_items = container.not_refreshing_items() not_refreshing_items[media_id] = True plugin.refresh()
def add_to_library(section, media_id, folder_id): scraper = container.scraper() section = Section.find(section) details = scraper.get_details_cached(section, media_id) folder = scraper.get_folder_cached(section, media_id, folder_id) library_manager = container.library_manager() library_manager.update_folder(details, folder) plugin.refresh() if plugin.get_setting('update-xbmc-library', bool): 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 explore(section): plugin.set_content("movies") section = Section.find(section) sf = container.search_filter(section) header = [ {"label": lang(34000), "path": plugin.url_for("search_index", section=section.filter_val)}, {"label": lang(34001), "path": plugin.url_for("genre_index", section=section.filter_val)} if section != Section.ANIME else None, {"label": lang(34002), "path": plugin.url_for("bookmarks_index", section=section.filter_val)}, {"label": lang(34011), "path": plugin.url_for("history_index", section=section.filter_val)}, ] header = [h for h in header if h is not None] make_search(sf, header)
def mark_watched(section, media_id): meta_cache = container.meta_cache() section = Section.find(section) watched_items = container.watched_items() meta = meta_cache.get(media_id, {}) total_size = meta.get('total_size') date_added = meta.get('date_added') if total_size is None: scraper = container.scraper() folders = scraper.get_folders_cached(section, media_id) total_size = sum(f.size for f in folders) meta['total_size'] = total_size meta_cache[media_id] = meta watched_items.mark(media_id, True, date_added=date_added, total_size=total_size) plugin.refresh()
def do_search(section, name): plugin.set_content('movies') section = Section.find(section) sf = container.search_filter(section=section, name=str(name)) if not make_search(sf): notify(lang(40312) % ensure_unicode(name)) elif plugin.request.arg('new'): storage = container.search_storage() recent = storage.get('search_recent', []) if name in recent: recent.remove(name) recent.append(name) storage['search_recent'] = recent count = plugin.get_setting('search-items-count', int) if len(recent) > count: del recent[:len(recent)-count]
def show_folders(section, media_id): section = Section.find(section) scraper = container.scraper() meta_cache = container.meta_cache() meta = meta_cache.setdefault(media_id, {}) plugin.set_content("movies") folders = scraper.get_folders_cached(section, media_id) total_size = sum(f.size for f in folders) meta["total_size"] = total_size for f in folders: if len(f.files) == 1 and not meta.get("is_series"): item = itemify_file(f.files[0], can_mark_watched=1) item["label"] = tf.folder_file_title(f, f.files[0]) item["context_menu"] += library_context_menu(section, media_id, f.id) else: item = itemify_folder(f) plugin.add_item(item) plugin.finish(sort_methods=["unsorted", "title", "duration", "size"])
def history_index(section): plugin.set_content("movies") section = Section.find(section) history = container.history() items = [] for item in reversed(history.get(section)): items.append( { "label": item.title, "thumbnail": item.poster, "path": item.path, "is_playable": True, "context_menu": toggle_watched_context_menu() + bookmark_context_menu(item.media_id, item.section, item.title) + download_torrent_context_menu(item.url) + clear_history_context_menu(), } ) return with_fanart(items)
def by_genre(section, genre): plugin.set_content("movies") section = Section.find(section) genre = Genre.find(genre) or unicode(genre) sf = container.search_filter(section, genres=[genre]) make_search(sf)
def add_bookmark(section, media_id, title): section = Section.find(section) bookmarks = container.bookmarks() bookmarks.add(media_id, section) # notify(lang(40308) % (Section.find(section).singular.localized, ensure_unicode(title))) plugin.refresh()