watch_page: refactor music list into flask template
This commit is contained in:
parent
6261add37d
commit
b89d90a0d3
@ -192,7 +192,24 @@
|
|||||||
|
|
||||||
<span class="description">{{ description }}</span>
|
<span class="description">{{ description }}</span>
|
||||||
<div class="music-list">
|
<div class="music-list">
|
||||||
{{ music_list|safe }}
|
{% if music_list.__len__() != 0 %}
|
||||||
|
<hr>
|
||||||
|
<table>
|
||||||
|
<caption>Music</caption>
|
||||||
|
<tr>
|
||||||
|
{% for attribute in music_attributes %}
|
||||||
|
<th>{{ attribute }}</th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% for track in music_list %}
|
||||||
|
<tr>
|
||||||
|
{% for attribute in music_attributes %}
|
||||||
|
<td>{{ track.get(attribute.lower(), '') }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{{ comments|safe }}
|
{{ comments|safe }}
|
||||||
</article>
|
</article>
|
||||||
|
@ -110,10 +110,7 @@ def get_subtitle_sources(info):
|
|||||||
return sources
|
return sources
|
||||||
|
|
||||||
|
|
||||||
def get_music_list_html(music_list):
|
def get_ordered_music_list_attributes(music_list):
|
||||||
if len(music_list) == 0:
|
|
||||||
music_list_html = ''
|
|
||||||
else:
|
|
||||||
# get the set of attributes which are used by atleast 1 track
|
# get the set of attributes which are used by atleast 1 track
|
||||||
# so there isn't an empty, extraneous album column which no tracks use, for example
|
# so there isn't an empty, extraneous album column which no tracks use, for example
|
||||||
used_attributes = set()
|
used_attributes = set()
|
||||||
@ -126,30 +123,7 @@ def get_music_list_html(music_list):
|
|||||||
if attribute.lower() in used_attributes:
|
if attribute.lower() in used_attributes:
|
||||||
ordered_attributes.append(attribute)
|
ordered_attributes.append(attribute)
|
||||||
|
|
||||||
music_list_html = '''<hr>
|
return ordered_attributes
|
||||||
<table>
|
|
||||||
<caption>Music</caption>
|
|
||||||
<tr>
|
|
||||||
'''
|
|
||||||
# table headings
|
|
||||||
for attribute in ordered_attributes:
|
|
||||||
music_list_html += "<th>" + attribute + "</th>\n"
|
|
||||||
music_list_html += '''</tr>\n'''
|
|
||||||
|
|
||||||
for track in music_list:
|
|
||||||
music_list_html += '''<tr>\n'''
|
|
||||||
for attribute in ordered_attributes:
|
|
||||||
try:
|
|
||||||
value = track[attribute.lower()]
|
|
||||||
except KeyError:
|
|
||||||
music_list_html += '''<td></td>'''
|
|
||||||
else:
|
|
||||||
music_list_html += '''<td>''' + html.escape(value) + '''</td>'''
|
|
||||||
music_list_html += '''</tr>\n'''
|
|
||||||
music_list_html += '''</table>\n'''
|
|
||||||
return music_list_html
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def extract_info(downloader, *args, **kwargs):
|
def extract_info(downloader, *args, **kwargs):
|
||||||
@ -231,10 +205,11 @@ def get_watch_page():
|
|||||||
video_sources = get_video_sources(info),
|
video_sources = get_video_sources(info),
|
||||||
subtitle_sources = get_subtitle_sources(info),
|
subtitle_sources = get_subtitle_sources(info),
|
||||||
related = related_videos,
|
related = related_videos,
|
||||||
|
music_list = info['music_list'],
|
||||||
|
music_attributes = get_ordered_music_list_attributes(info['music_list']),
|
||||||
|
|
||||||
# TODO: refactor these
|
# TODO: refactor these
|
||||||
comments = comments_html,
|
comments = comments_html,
|
||||||
music_list = get_music_list_html(info['music_list']),
|
|
||||||
|
|
||||||
title = info['title'],
|
title = info['title'],
|
||||||
uploader = info['uploader'],
|
uploader = info['uploader'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user