{% 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) %}
{% if info['error'] %} {{ info['error'] }} {% else %}
{% if info['type'] != 'channel' %}
{{ (info['video_count']|string + ' videos') if info['type'] == 'playlist' else info['duration'] }}
{% endif %}
{% if description %} {{ text_runs(info.get('description', '')) }} {% endif %} {% if include_badges %} {{ info['badges']|join(' | ') }} {% endif %}
{% if info['type'] == 'video' %} {% endif %} {% endif %}
{% endmacro %} {% macro page_buttons(estimated_pages, url, parameters_dictionary) %} {% 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 %} {% for page in range(page_start, page_end+1) %} {% if page == current_page %}
{{ page }}
{% else %} {# IMPORTANT: Jinja SUCKS #} {# 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 %} {% endmacro %}