aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/templates/common_elements.html
diff options
context:
space:
mode:
Diffstat (limited to 'youtube/templates/common_elements.html')
-rw-r--r--youtube/templates/common_elements.html136
1 files changed, 95 insertions, 41 deletions
diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html
index 67655b3..bacc513 100644
--- a/youtube/templates/common_elements.html
+++ b/youtube/templates/common_elements.html
@@ -9,59 +9,75 @@
{{ text_run["text"] }}
{%- endif -%}
{%- endfor -%}
- {%- else -%}
+ {%- elif runs -%}
{{ runs }}
{%- endif -%}
{% endmacro %}
-{% macro item(info, description=false, horizontal=true, include_author=true) %}
- <div class="item-box {{ info['type'] + '-item-box' }} {{'horizontal-item-box' if horizontal else 'vertical-item-box'}} {{'has-description' if description else 'no-description'}}">
- <div class="item {{ info['type'] + '-item' }}">
- <a class="thumbnail-box" href="{{ info['url'] }}" title="{{ info['title'] }}">
- <img class="thumbnail-img" src="{{ info['thumbnail'] }}">
- {% if info['type'] != 'channel' %}
- <div class="thumbnail-info">
- <span>{{ info['size'] if info['type'] == 'playlist' else info['duration'] }}</span>
- </div>
- {% endif %}
- </a>
+{% macro item(info, description=false, horizontal=true, include_author=true, include_badges=true, lazy_load=false) %}
+ <article class="item-box">
+ {% if info['error'] %}
+ {{ info['error'] }}
+ {% else %}
+ <div class="item-video {{ info['type'] + '-item' }}">
+ <a class="thumbnail-box" href="{{ info['url'] }}" title="{{ info['title'] }}">
+ <div class="thumbnail {% if info['type'] == 'channel' %} channel {% endif %}">
+ {% if lazy_load %}
+ <img class="thumbnail-img lazy" alt="&#x20;" data-src="{{ info['thumbnail'] }}">
+ {% elif info['type'] == 'channel' %}
+ <img class="thumbnail-img channel" alt="&#x20;" src="{{ info['thumbnail'] }}">
+ {% else %}
+ <img class="thumbnail-img" alt="&#x20;" src="{{ info['thumbnail'] }}">
+ {% endif %}
- <div class="title"><a class="title" href="{{ info['url'] }}" title="{{ info['title'] }}">{{ info['title'] }}</a></div>
+ {% if info['type'] != 'channel' %}
+ <p class="length">{{ (info['video_count']|commatize + ' videos') if info['type'] == 'playlist' else info['duration'] }}</p>
+ {% endif %}
+ </div>
+ </a>
+ <h4 class="title"><a href="{{ info['url'] }}" title="{{ info['title'] }}">{{ info['title'] }}</a></h4>
- <ul class="stats {{'vertical-stats' if horizontal and not description and include_author else 'horizontal-stats'}}">
- {% if info['type'] == 'channel' %}
- <li><span>{{ info['subscriber_count'] }} subscribers</span></li>
- <li><span>{{ info['size'] }} videos</span></li>
- {% else %}
- {% if include_author %}
- {% if 'author_url' is in(info) %}
- <li><address title="{{ info['author'] }}">By <a href="{{ info['author_url'] }}">{{ info['author'] }}</a></address></li>
- {% else %}
- <li><address title="{{ info['author'] }}"><b>{{ info['author'] }}</b></address></li>
+ {% if include_author %}
+ {% set author_description = info['author'] %}
+ {% set AUTHOR_DESC_LENGTH = 35 %}
+ {% if author_description != None %}
+ {% if author_description|length >= AUTHOR_DESC_LENGTH %}
+ {% set author_description = author_description[:AUTHOR_DESC_LENGTH].split(' ')[:-1]|join(' ') %}
+ {% if not author_description[-1] in ['.', '?', ':', '!'] %}
+ {% set author_more = author_description + '…' %}
+ {% set author_description = author_more|replace('"','') %}
+ {% endif %}
{% endif %}
{% endif %}
- {% if 'views' is in(info) %}
- <li><span class="views">{{ info['views'] }}</span></li>
- {% endif %}
- {% if 'published' is in(info) %}
- <li><time>{{ info['published'] }}</time></li>
+ {% if info.get('author_url') %}
+ <address title="{{ info['author'] }}"><b><a href="{{ info['author_url'] }}">{{ author_description }}</a></b></address>
+ {% else %}
+ <address title="{{ info['author'] }}"><b>{{ author_description }}</b></address>
{% endif %}
{% endif %}
- </ul>
- {% if description %}
- <span class="description">{{ text_runs(info.get('description', '')) }}</span>
+ <div class="stats {{'horizontal-stats' if horizontal else 'vertical-stats'}}">
+ {% if info['type'] == 'channel' %}
+ <div>{{ info['approx_subscriber_count'] }} subscribers</div>
+ <div>{{ info['video_count']|commatize }} videos</div>
+ {% else %}
+ {% if info.get('time_published') %}
+ <span>{{ info['time_published'] }}</span>
+ {% endif %}
+ {% if info.get('approx_view_count') %}
+ <div class="views">{{ info['approx_view_count'] }} views</div>
+ {% endif %}
+ {% endif %}
+ </div>
+ </div>
+ {% if info['type'] == 'video' %}
+ <input class="item-checkbox" type="checkbox" name="video_info_list" value="{{ info['video_info'] }}" form="playlist-edit">
{% endif %}
- <span class="badges">{{ info['badges']|join(' | ') }}</span>
- </div>
- {% if info['type'] == 'video' %}
- <input class="item-checkbox" type="checkbox" name="video_info_list" value="{{ info['video_info'] }}" form="playlist-edit">
{% endif %}
- </div>
-
+ </article>
{% endmacro %}
-{% macro page_buttons(estimated_pages, url, parameters_dictionary) %}
+{% 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) %}
@@ -72,15 +88,53 @@
{% 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) %}
+ <a class="page-link first-page-button" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ 1 }}</a>
+ {% endif %}
+
{% for page in range(page_start, page_end+1) %}
{% if page == current_page %}
- <div class="page-button">{{ page }}</div>
+ <a class="page-link is-current">{{ page }}</a>
{% 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) %}
- <a class="page-button" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ page }}</a>
+ <a class="page-link" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ page }}</a>
{% endif %}
{% endfor %}
+ {% if include_ends and page_end is lt(estimated_pages) %}
+ {% set _ = parameters_dictionary.__setitem__('page', estimated_pages) %}
+ <a class="page-link last-page-button" href="{{ url + '?' + parameters_dictionary|urlencode }}">{{ estimated_pages }}</a>
+ {% 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) %}
+ <a class="page-link previous-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Previous page</a>
+ {% endif %}
+
+ {% if not is_last_page %}
+ {% set _ = parameters_dictionary.__setitem__('page', current_page + 1) %}
+ <a class="page-link next-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Next page</a>
+ {% endif %}
+{% endmacro %}
+
+{% 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) %}
+ <a class="page-link previous-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Previous page</a>
+ {% endif %}
+
+ {% if next_ctoken %}
+ {% set _ = parameters_dictionary.__setitem__('ctoken', next_ctoken) %}
+ <a class="page-link next-page" href="{{ url + '?' + parameters_dictionary|urlencode }}">Next page</a>
+ {% endif %}
{% endmacro %}