示例#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
示例#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