Add channel_name to videos before returning them, show on listings.
Previously, when viewing a /videos listing, there was a link called (Chan) to bring you to the channel page, but since videos only carried author_id and not author_name it was always kind of ugly. This will inject that attribute on the way out. I know, this would be more properly written as an SQL join in the first place, but my row-dict conversion isn't set up for that and I'm planning on converting this all to object-based returns instead of dicts soon.
This commit is contained in:
parent
1b456bf900
commit
718399806a
2 changed files with 15 additions and 4 deletions
|
@ -127,7 +127,7 @@ https://stackoverflow.com/a/35153397
|
|||
<span>({{video['duration'] | seconds_to_hms}})</span>
|
||||
<span>({{video['views']}})</span>
|
||||
{% if channel is none %}
|
||||
<a href="/channel/{{video['author_id']}}">(Chan)</a>
|
||||
<a href="/channel/{{video['author_id']}}">({{video.get('author_name', 'Chan')}})</a>
|
||||
{% endif %}
|
||||
<div class="action_toolbox">
|
||||
<button
|
||||
|
|
|
@ -256,11 +256,22 @@ class YCDLDB:
|
|||
|
||||
query = 'SELECT * FROM videos' + wheres + orderbys
|
||||
self.cur.execute(query, bindings)
|
||||
videos = self.cur.fetchall()
|
||||
if not videos:
|
||||
rows = self.cur.fetchall()
|
||||
if not rows:
|
||||
return []
|
||||
|
||||
videos = [{key: video[SQL_VIDEO[key]] for key in SQL_VIDEO} for video in videos]
|
||||
videos = []
|
||||
channels = {}
|
||||
for row in rows:
|
||||
video = {key: row[SQL_VIDEO[key]] for key in SQL_VIDEO}
|
||||
author_id = video['author_id']
|
||||
if author_id in channels:
|
||||
video['author_name'] = channels[author_id]
|
||||
author = self.get_channel(author_id)
|
||||
if author:
|
||||
channels[author_id] = author['name']
|
||||
video['author_name'] = author['name']
|
||||
videos.append(video)
|
||||
return videos
|
||||
|
||||
def insert_playlist(self, playlist_id, commit=True):
|
||||
|
|
Loading…
Reference in a new issue