diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-06-21 21:59:33 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-06-21 21:59:33 -0700 |
commit | 02962df0526cf265965c442bf9a261ceba55864e (patch) | |
tree | 8094c558b4fea0fecae66240bb76155c219cbaa9 | |
parent | 1156b0998758ee803c7e8ae0cc2beb5181c232a3 (diff) | |
download | yt-local-02962df0526cf265965c442bf9a261ceba55864e.tar.lz yt-local-02962df0526cf265965c442bf9a261ceba55864e.tar.xz yt-local-02962df0526cf265965c442bf9a261ceba55864e.zip |
Refactor watch page related videos to use item rendering macro
-rw-r--r-- | youtube/templates/watch.html | 5 | ||||
-rw-r--r-- | youtube/watch.py | 27 |
2 files changed, 20 insertions, 12 deletions
diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html index f00413d..122958c 100644 --- a/youtube/templates/watch.html +++ b/youtube/templates/watch.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% import "common_elements.html" as common_elements %} {% block page_title %}{{ title }}{% endblock %} {% block style %} main{ @@ -200,7 +201,9 @@ <nav id="related"> -{{ related|safe }} + {% for info in related %} + {{ common_elements.item(info) }} + {% endfor %} </nav> {% endblock main %} diff --git a/youtube/watch.py b/youtube/watch.py index ac70fd4..818abf2 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -1,5 +1,5 @@ from youtube import yt_app -from youtube import util, html_common, comments, local_playlist +from youtube import util, html_common, comments, local_playlist, yt_data_extract import settings from flask import request @@ -13,16 +13,17 @@ import gevent import os -def get_related_items_html(info): - result = "" +def get_related_items(info): + results = [] for item in info['related_vids']: if 'list' in item: # playlist: - item = watch_page_related_playlist_info(item) - result += html_common.playlist_item_html(item, html_common.small_playlist_item_template) + result = watch_page_related_playlist_info(item) else: - item = watch_page_related_video_info(item) - result += html_common.video_item_html(item, html_common.small_video_item_template) - return result + result = watch_page_related_video_info(item) + yt_data_extract.prefix_urls(result) + yt_data_extract.add_extra_html_info(result) + results.append(result) + return results # json of related items retrieved directly from the watch page has different names for everything @@ -35,6 +36,8 @@ def watch_page_related_video_info(item): except KeyError: result['views'] = '' result['thumbnail'] = util.get_thumbnail_url(item['id']) + result['item_size'] = 'small' + result['type'] = 'video' return result def watch_page_related_playlist_info(item): @@ -44,6 +47,8 @@ def watch_page_related_playlist_info(item): 'id': item['list'], 'first_video_id': item['video_id'], 'thumbnail': util.get_thumbnail_url(item['video_id']), + 'item_size': 'small', + 'type': 'playlist', } def get_video_sources(info): @@ -192,9 +197,9 @@ def get_watch_page(): upload_date = upload_month + "/" + upload_day + "/" + upload_year if settings.enable_related_videos: - related_videos_html = get_related_items_html(info) + related_videos = get_related_items(info) else: - related_videos_html = '' + related_videos = [] if settings.gather_googlevideo_domains: @@ -225,9 +230,9 @@ def get_watch_page(): video_info = json.dumps(video_info), video_sources = get_video_sources(info), subtitle_sources = get_subtitle_sources(info), + related = related_videos, # TODO: refactor these - related = related_videos_html, comments = comments_html, music_list = get_music_list_html(info['music_list']), |