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 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 clear_history(): history = container.history() history.clear() plugin.refresh()