{% macro text_runs(runs) %} {%- if runs[0] is mapping -%} {%- for text_run in runs -%} {%- if text_run.get("bold", false) -%} {{ text_run["text"] }} {%- elif text_run.get('italics', false) -%} {{ text_run["text"] }} {%- else -%} {{ text_run["text"] }} {%- endif -%} {%- endfor -%} {%- elif runs -%} {{ runs }} {%- endif -%} {% endmacro %} {% macro item(info, description=false, horizontal=true, include_author=true, include_badges=true, lazy_load=false) %}
{% if info['error'] %} {{ info['error'] }} {% else %}
{% if lazy_load %} thumbnail {% elif info['type'] == 'channel' %} thumbnail {% else %} thumbnail {% endif %} {% if info['type'] != 'channel' %}

{{ (info['video_count']|commatize + ' videos') if info['type'] == 'playlist' else info['duration'] }}

{% endif %}

{{ info['title'] }}

{% if include_author %} {% if info.get('author_url') %}
{{ info['author'] }}
{% else %}
{{ info['author'] }}
{% endif %} {% endif %}
{% if info['type'] == 'channel' %}
{{ info['approx_subscriber_count'] }} subscribers
{{ info['video_count']|commatize }} videos
{% else %} {% if info.get('time_published') %} {{ info['time_published'] }} {% endif %} {% if info.get('approx_view_count') %}
{{ info['approx_view_count'] }} views
{% endif %} {% endif %}
{% if info['type'] == 'video' %} {% endif %} {% endif %}
{% endmacro %} {% macro page_buttons(estimated_pages, url, parameters_dictionary, include_ends=false) %} {% set current_page = parameters_dictionary.get('page', 1)|int %} {% set parameters_dictionary = parameters_dictionary.to_dict() %} {% if current_page is le(5) %} {% set page_start = 1 %} {% set page_end = [9, estimated_pages]|min %} {% else %} {% set page_start = current_page - 4 %} {% set page_end = [current_page + 4, estimated_pages]|min %} {% endif %} {% if include_ends and page_start is gt(1) %} {% set _ = parameters_dictionary.__setitem__('page', 1) %} {{ 1 }} {% endif %} {% for page in range(page_start, page_end+1) %} {% if page == current_page %} {{ page }} {% else %} {# https://stackoverflow.com/questions/36886650/how-to-add-a-new-entry-into-a-dictionary-object-while-using-jinja2 #} {% set _ = parameters_dictionary.__setitem__('page', page) %} {{ page }} {% endif %} {% endfor %} {% if include_ends and page_end is lt(estimated_pages) %} {% set _ = parameters_dictionary.__setitem__('page', estimated_pages) %} {{ estimated_pages }} {% endif %} {% endmacro %} {% macro next_previous_buttons(is_last_page, url, parameters_dictionary) %} {% set current_page = parameters_dictionary.get('page', 1)|int %} {% set parameters_dictionary = parameters_dictionary.to_dict() %} {% if current_page != 1 %} {% set _ = parameters_dictionary.__setitem__('page', current_page - 1) %} Previous page {% endif %} {% if not is_last_page %} {% set _ = parameters_dictionary.__setitem__('page', current_page + 1) %} Next page {% endif %} {% macro next_previous_ctoken_buttons(prev_ctoken, next_ctoken, url, parameters_dictionary) %} {% set parameters_dictionary = parameters_dictionary.to_dict() %} {% if prev_ctoken %} {% set _ = parameters_dictionary.__setitem__('ctoken', prev_ctoken) %} Previous page {% endif %} {% if next_ctoken %} {% set _ = parameters_dictionary.__setitem__('ctoken', next_ctoken) %} Next page {% endif %} {% endmacro %} {% endmacro %}