From 1156b0998758ee803c7e8ae0cc2beb5181c232a3 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Fri, 21 Jun 2019 21:41:41 -0700 Subject: Refactor search page --- youtube/templates/common_elements.html | 152 +++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 youtube/templates/common_elements.html (limited to 'youtube/templates/common_elements.html') diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html new file mode 100644 index 0000000..9f2aa3f --- /dev/null +++ b/youtube/templates/common_elements.html @@ -0,0 +1,152 @@ +{% 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 -%} + {%- else -%} + {{ runs }} + {%- endif -%} +{% endmacro %} + +{% macro small_item(info) %} +
+
+ {% if info['type'] == 'video' %} + + + {{ info['duration'] }} + + {{ info['title'] }} + +
{{ info['author'] }}
+ {{ info['views'] }} + + {% elif info['type'] == 'playlist' %} + + +
+ {{ info['size'] }} +
+
+ {{ info['title'] }} + +
{{ info['author'] }}
+ {% else %} + Error: unsupported item type + {% endif %} +
+ {% if info['type'] == 'video' %} + + {% endif %} +
+{% endmacro %} + +{% macro get_stats(info) %} + {% if 'author_url' is in(info) %} +
By {{ info['author'] }}
+ {% else %} +
{{ info['author'] }}
+ {% endif %} + {% if 'views' is in(info) %} + {{ info['views'] }} + {% endif %} + {% if 'published' is in(info) %} + + {% endif %} +{% endmacro %} + + + +{% macro medium_item(info) %} +
+
+ {% if info['type'] == 'video' %} + + + {{ info['duration'] }} + + + {{ info['title'] }} + +
+ {{ get_stats(info) }} +
+ + {{ text_runs(info['description']) }} + {{ info['badges']|join(' | ') }} + {% elif info['type'] == 'playlist' %} + + +
+ {{ info['size'] }} +
+
+ + {{ info['title'] }} + +
+ {{ get_stats(info) }} +
+ {% elif info['type'] == 'channel' %} + + + + + {{ info['title'] }} + + {{ info['subscriber_count'] }} + {{ info['size'] }} + + {{ text_runs(info['description']) }} + {% else %} + Error: unsupported item type + {% endif %} +
+ {% if info['type'] == 'video' %} + + {% endif %} +
+{% endmacro %} + + +{% macro item(info) %} + {% if info['item_size'] == 'small' %} + {{ small_item(info) }} + {% elif info['item_size'] == 'medium' %} + {{ medium_item(info) }} + {% else %} + Error: Unknown item size + {% 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 %} -- cgit v1.2.3 From 315039bebd8d47820e3c0baeb7ac258db6741582 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 4 Jul 2019 18:20:51 -0700 Subject: common_elements.html: accept missing description as blank --- youtube/templates/common_elements.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'youtube/templates/common_elements.html') diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html index 9f2aa3f..b140332 100644 --- a/youtube/templates/common_elements.html +++ b/youtube/templates/common_elements.html @@ -78,7 +78,7 @@ {{ get_stats(info) }} - {{ text_runs(info['description']) }} + {{ text_runs(info.get('description', '')) }} {{ info['badges']|join(' | ') }} {% elif info['type'] == 'playlist' %} -- cgit v1.2.3 From 64434b02ca50c2a6324caa1355559bd881ba687e Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sat, 6 Jul 2019 18:36:09 -0700 Subject: Convert channel page to flask framework --- youtube/templates/common_elements.html | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'youtube/templates/common_elements.html') diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html index b140332..0843c4b 100644 --- a/youtube/templates/common_elements.html +++ b/youtube/templates/common_elements.html @@ -14,7 +14,7 @@ {%- endif -%} {% endmacro %} -{% macro small_item(info) %} +{% macro small_item(info, include_author=true) %}
{% if info['type'] == 'video' %} @@ -47,11 +47,13 @@
{% endmacro %} -{% macro get_stats(info) %} - {% if 'author_url' is in(info) %} -
By {{ info['author'] }}
- {% else %} -
{{ info['author'] }}
+{% macro get_stats(info, include_author=true) %} + {% if include_author %} + {% if 'author_url' is in(info) %} +
By {{ info['author'] }}
+ {% else %} +
{{ info['author'] }}
+ {% endif %} {% endif %} {% if 'views' is in(info) %} {{ info['views'] }} @@ -63,7 +65,7 @@ -{% macro medium_item(info) %} +{% macro medium_item(info, include_author=true) %}
{% if info['type'] == 'video' %} @@ -75,7 +77,7 @@ {{ info['title'] }}
- {{ get_stats(info) }} + {{ get_stats(info, include_author) }}
{{ text_runs(info.get('description', '')) }} @@ -91,7 +93,7 @@ {{ info['title'] }}
- {{ get_stats(info) }} + {{ get_stats(info, include_author) }}
{% elif info['type'] == 'channel' %} @@ -115,11 +117,11 @@ {% endmacro %} -{% macro item(info) %} +{% macro item(info, include_author=true) %} {% if info['item_size'] == 'small' %} - {{ small_item(info) }} + {{ small_item(info, include_author) }} {% elif info['item_size'] == 'medium' %} - {{ medium_item(info) }} + {{ medium_item(info, include_author) }} {% else %} Error: Unknown item size {% endif %} -- cgit v1.2.3 From 728b2b73d49d9112b8874783e038d901244dd7d8 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sun, 7 Jul 2019 17:32:11 -0700 Subject: common_elements.html: Accept missing channel description as blank --- youtube/templates/common_elements.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'youtube/templates/common_elements.html') diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html index 0843c4b..a6921e1 100644 --- a/youtube/templates/common_elements.html +++ b/youtube/templates/common_elements.html @@ -105,7 +105,7 @@ {{ info['subscriber_count'] }} {{ info['size'] }} - {{ text_runs(info['description']) }} + {{ text_runs(info.get('description', '')) }} {% else %} Error: unsupported item type {% endif %} -- cgit v1.2.3 From eb89c7426d8918332558aaba9ff4b7547c507f96 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Wed, 24 Jul 2019 00:02:04 -0700 Subject: Add 'subscribers' and 'videos' after corresponding numbers in channel item in search results --- youtube/templates/common_elements.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'youtube/templates/common_elements.html') diff --git a/youtube/templates/common_elements.html b/youtube/templates/common_elements.html index a6921e1..49e2fad 100644 --- a/youtube/templates/common_elements.html +++ b/youtube/templates/common_elements.html @@ -102,8 +102,8 @@ {{ info['title'] }} - {{ info['subscriber_count'] }} - {{ info['size'] }} + {{ info['subscriber_count'] }} subscribers + {{ info['size'] }} videos {{ text_runs(info.get('description', '')) }} {% else %} -- cgit v1.2.3