git ssb

0+

cel / dillo-ytdl



Commit 29bace3450fcbaee33956eb93d25774d5485e71b

Support multiple entries in response

cel committed on 1/27/2019, 12:18:09 AM
Parent: 58a3d11c862df8cdb00f077e91d0303ba78618a3

Files changed

ydl.dpichanged
ydl.dpiView
@@ -87,17 +87,39 @@
8787 "<td>" + (html.escape(str(acodec)) if acodec else "") + "</td>" +
8888 "<td>" + (html.escape(str(vcodec)) if vcodec else "") + "</td>" +
8989 "<!--<td><pre>" + json.dumps(form) + "</pre></td>-->")
9090
91 +def renderEntry(entry):
92 + thumbnails = entry.get('thumbnails', [])
93 + formats = entry.get('formats', [])
94 + uploader = entry.get('uploader')
95 + description = entry.get('description')
96 + duration = entry.get('duration')
97 + view_count = entry.get('view_count')
98 +
99 + if formats: del entry['formats']
100 + tags = entry.get('tags')
101 + return (
102 + ("<div>" +
103 + " ".join([renderThumbnail(thumb) + "\n" for thumb in thumbnails]) +
104 + "</div>\n" if len(thumbnails) > 0 else "") +
105 + ("<div>" + html.escape(uploader) + "</div>" if uploader else "") +
106 + ("<p>" + html.escape(description) + "</p>" if description else "") +
107 + ("<p>Duration: " + html.escape(str(duration)) + "</p>" if duration else "") +
108 + ("<p>View count: " + html.escape(str(view_count)) + "</p>" if view_count else "") +
109 + ("<p>Tags: " + ", ".join([html.escape(str(tag)) for tag in tags]) + "</p>" if tags else "") +
110 + ("<table>" +
111 + "<thead>" +
112 + "<tr><th>code</th><th>ext</th><th>size</th><th>format</th><th>resolution</th><th>audio</th><th>video</th></tr>" +
113 + "</thead>\n<tbody>" +
114 + "\n".join([renderFormat(form) + "\n" for form in formats]) +
115 + "</tbody></table>\n" if len(thumbnails) > 0 else ""))
116 +
91117 def serveResult(conn, origUrl, res):
92118 writeHeader(conn, origUrl, "text/html")
93119 title = res.get('title')
94120 webpage_url = res.get('webpage_url')
95- thumbnails = res.get('thumbnails', [])
96- formats = res.get('formats', [])
97- uploader = res.get('uploader')
98- description = res.get('description')
99- if formats: del res['formats']
121 + entries = res.get('entries', []) if res.get('_type', None) == 'playlist' else [res]
100122 conn.send(("<!doctype html>" +
101123 "<html>" +
102124 "<head>" +
103125 "<title>" + html.escape(title) + "</title></head>" +
@@ -106,19 +128,9 @@
106128 ("<a href='" + html.escape(webpage_url) + "'>" if webpage_url else "") +
107129 html.escape(title) +
108130 ("</a>" if webpage_url else "") +
109131 "</h1>\n" +
110- ("<div>" +
111- " ".join([renderThumbnail(thumb) + "\n" for thumb in thumbnails]) +
112- "</div>\n" if len(thumbnails) > 0 else "") +
113- ("<div>" + html.escape(uploader) + "</div>" if uploader else "") +
114- ("<p>" + html.escape(description) + "</p>" if description else "") +
115- ("<table>" +
116- "<thead>" +
117- "<tr><th>code</th><th>ext</th><th>size</th><th>format</th><th>resolution</th><th>audio</th><th>video</th></tr>" +
118- "</thead>\n<tbody>" +
119- "\n".join([renderFormat(form) + "\n" for form in formats]) +
120- "</tbody></table>\n" if len(thumbnails) > 0 else "") +
132 + "\n".join([renderEntry(entry) for entry in entries]) +
121133 "<!--<pre>" + json.dumps(res, indent=True) + "</pre>-->\n" +
122134 "</body></html>").encode('utf-8'))
123135 conn.shutdown(socket.SHUT_WR)
124136

Built with git-ssb-web