diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-07-07 17:29:25 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-07-07 17:29:25 -0700 |
commit | b89d90a0d35a239ee4eb476eaf5e2d3404fe65ea (patch) | |
tree | 4e81324f60ca969c777e649ff3497ae0d1ca0241 /youtube | |
parent | 6261add37de1800c90b0942a77cca99baf0b1973 (diff) | |
download | yt-local-b89d90a0d35a239ee4eb476eaf5e2d3404fe65ea.tar.lz yt-local-b89d90a0d35a239ee4eb476eaf5e2d3404fe65ea.tar.xz yt-local-b89d90a0d35a239ee4eb476eaf5e2d3404fe65ea.zip |
watch_page: refactor music list into flask template
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/templates/watch.html | 21 | ||||
-rw-r--r-- | youtube/watch.py | 53 |
2 files changed, 33 insertions, 41 deletions
diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html index 122958c..85c87ae 100644 --- a/youtube/templates/watch.html +++ b/youtube/templates/watch.html @@ -185,14 +185,31 @@ <span>{{ format['resolution'] }}</span> <span>{{ format['note'] }}</span> </a> -{% endfor %} +{% endfor %} </div> </div> <input class="checkbox" name="video_info_list" value="{{ video_info }}" form="playlist-edit" type="checkbox"> <span class="description">{{ description }}</span> <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> {{ comments|safe }} </article> diff --git a/youtube/watch.py b/youtube/watch.py index 1f7a352..6a1a199 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -110,46 +110,20 @@ def get_subtitle_sources(info): return sources -def get_music_list_html(music_list): - if len(music_list) == 0: - music_list_html = '' - else: - # 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 - used_attributes = set() - for track in music_list: - used_attributes = used_attributes | track.keys() - - # now put them in the right order - ordered_attributes = [] - for attribute in ('Artist', 'Title', 'Album'): - if attribute.lower() in used_attributes: - ordered_attributes.append(attribute) - - music_list_html = '''<hr> -<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 get_ordered_music_list_attributes(music_list): + # 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 + used_attributes = set() + for track in music_list: + used_attributes = used_attributes | track.keys() + # now put them in the right order + ordered_attributes = [] + for attribute in ('Artist', 'Title', 'Album'): + if attribute.lower() in used_attributes: + ordered_attributes.append(attribute) + return ordered_attributes def extract_info(downloader, *args, **kwargs): @@ -231,10 +205,11 @@ def get_watch_page(): video_sources = get_video_sources(info), subtitle_sources = get_subtitle_sources(info), related = related_videos, + music_list = info['music_list'], + music_attributes = get_ordered_music_list_attributes(info['music_list']), # TODO: refactor these comments = comments_html, - music_list = get_music_list_html(info['music_list']), title = info['title'], uploader = info['uploader'], |