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 download_torrent(url): client = container.torrent_client() client.add(container.torrent(url), save_path(local=True)) if isinstance(client, TransmissionClient): name = 'Transmission' addon_id = 'script.transmission' elif isinstance(client, UTorrentClient): name = 'UTorrent' addon_id = 'plugin.program.utorrent' else: return if xbmcgui.Dialog().yesno(lang(40316), *(lang(40317) % name).split("|")): xbmc.executebuiltin('XBMC.RunAddon(%s)' % addon_id)