Commit 29bace3450fcbaee33956eb93d25774d5485e71b
Support multiple entries in response
cel committed on 1/27/2019, 12:18:09 AMParent: 58a3d11c862df8cdb00f077e91d0303ba78618a3
Files changed
ydl.dpi | changed |
ydl.dpi | |||
---|---|---|---|
@@ -87,17 +87,39 @@ | |||
87 | 87 … | "<td>" + (html.escape(str(acodec)) if acodec else "") + "</td>" + | |
88 | 88 … | "<td>" + (html.escape(str(vcodec)) if vcodec else "") + "</td>" + | |
89 | 89 … | "<!--<td><pre>" + json.dumps(form) + "</pre></td>-->") | |
90 | 90 … | ||
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 … | + | ||
91 | 117 … | def serveResult(conn, origUrl, res): | |
92 | 118 … | writeHeader(conn, origUrl, "text/html") | |
93 | 119 … | title = res.get('title') | |
94 | 120 … | 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] | ||
100 | 122 … | conn.send(("<!doctype html>" + | |
101 | 123 … | "<html>" + | |
102 | 124 … | "<head>" + | |
103 | 125 … | "<title>" + html.escape(title) + "</title></head>" + | |
@@ -106,19 +128,9 @@ | |||
106 | 128 … | ("<a href='" + html.escape(webpage_url) + "'>" if webpage_url else "") + | |
107 | 129 … | html.escape(title) + | |
108 | 130 … | ("</a>" if webpage_url else "") + | |
109 | 131 … | "</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]) + | ||
121 | 133 … | "<!--<pre>" + json.dumps(res, indent=True) + "</pre>-->\n" + | |
122 | 134 … | "</body></html>").encode('utf-8')) | |
123 | 135 … | conn.shutdown(socket.SHUT_WR) | |
124 | 136 … |
Built with git-ssb-web