Commit c89ba43d authored by Christophe Benz's avatar Christophe Benz Committed by Romain Bignon

add merge option and some sorting

parent c272634a
......@@ -71,17 +71,25 @@ class VideoobWeb(BaseApplication):
nsfw = req.params.get('nsfw')
nsfw = False if not nsfw or nsfw == '0' else True
q = req.params.get('q', u'')
merge = req.params.get('merge')
merge = False if not merge or merge == '0' else True
c['merge'] = merge
c['form_data'] = dict(q=q)
c['results'] = {}
c['results'] = [] if merge else {}
if q:
for backend in self.weboob.iter_backends():
items = [dict(title=video.title,
videos = [dict(title=video.title,
page_url=video.page_url,
url=video.url if video.url else '/download?id=%s' % video.id
) \
for video in backend.iter_search_results(pattern=q, nsfw=nsfw)]
if items:
c['results'][backend.name] = items
if videos:
if merge:
c['results'].extend(videos)
else:
c['results'][backend.name] = videos
if merge:
c['results'] = sorted(c['results'], key=lambda video: video['title'].lower())
template = template_lookup.get_template('index.mako')
buf = StringIO()
ctx = Context(buf, **c)
......
......@@ -2,6 +2,11 @@
<%inherit file="base.mako"/>
<%def name="video_link(item)">
<a href="${item['page_url']}">${item['title']}</a>
## (<a href="${item['url']}"><em>download</em></a>)
</%def>
<%def name="body()">
<h1>Videoob Web</h1>
<div id="search">
......@@ -12,16 +17,21 @@
</form>
</div>
<div id="results">
% for backend, items in results.iteritems():
<h2>${backend}</h2>
% if merge:
<ul>
% for item in items:
<li>
<a href="${item['page_url']}">${item['title']}</a>
## (<a href="${item['url']}"><em>download</em></a>)
</li>
% for item in results:
<li>${video_link(item)}</li>
% endfor
</ul>
% endfor
% else:
% for backend, items in sorted(results.iteritems()):
<h2>${backend}</h2>
<ul>
% for item in items:
<li>${video_link(item)}</li>
% endfor
</ul>
% endfor
% endif
</div>
</%def>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment