Ejemplo n.º 1
0
def itemify_search_results(section, results):
    """
    :type results: list[Media]
    """
    ids = [result.id for result in results]
    scraper = container.scraper()
    meta_cache = container.meta_cache()
    all_details = scraper.get_details_bulk(section, ids)
    watched_items = container.watched_items()
    items = []
    for media in results:
        details = all_details[media.id]
        is_series = details.section.is_series()
        watched = watched_items.is_watched(media.id, date_added=media.date if is_series else None)
        meta = meta_cache.setdefault(media.id, {})
        meta.update({
            'date_added': media.date,
            'is_series': is_series,
        })
        item = itemify_details(details)
        item.update({
            'label': tf.media_title(media),
            'label2': date_to_str(media.date),
            'context_menu': search_result_context_menu(details, media.date),
        })
        item['info'].update({
            'date': date_to_str(media.date),
            'playcount': int(watched),
        })
        items.append(item)
    return items
Ejemplo n.º 2
0
def itemify_single_result(result, folders=None):
    """
    :type result: Details
    """
    media_id = result.media_id
    scraper = container.scraper()
    folders = folders or scraper.get_folders_cached(media_id)
    watched_items = container.watched_items()
    total_size = sum(f.size for f in folders)
    is_series = result.section.is_series()
    watched = watched_items.is_watched(media_id, total_size=total_size if is_series else None)
    meta_cache = container.meta_cache()
    meta = meta_cache.setdefault(media_id, {})
    meta.update({
        'total_size': total_size,
        'is_series': is_series,
    })
    item = itemify_details(result)
    item.update({
        'label': tf.bookmark_title(result, folders),
        'context_menu': search_result_context_menu(result, total_size=total_size),
    })
    item['info'].update({
        'playcount': int(watched),
    })
    return item
Ejemplo n.º 3
0
def mark_watched_context_menu(section, media_id, date_added=None, total_size=None):
    watched_items = container.watched_items()
    if media_id in watched_items:
        return [(lang(40302), actions.background(plugin.url_for('mark_unwatched', media_id=media_id)))]
    else:
        return [(lang(40301), actions.background(plugin.url_for('mark_watched',
                                                                section=section.filter_val,
                                                                media_id=media_id,
                                                                date_added=date_added,
                                                                total_size=total_size)))]
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
 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"))
Ejemplo n.º 6
0
def mark_unwatched(media_id):
    watched_items = container.watched_items()
    watched_items.mark(media_id, False)
    plugin.refresh()