Example #1
0
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()
Example #2
0
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]