add thumbnails to videoob web
This commit is contained in:
parent
aa1a2a2921
commit
887f7d98de
4 changed files with 51 additions and 23 deletions
|
|
@ -36,7 +36,7 @@ from weboob.tools.application import BaseApplication
|
|||
__all__ = ['VideoobWeb']
|
||||
|
||||
|
||||
template_lookup = TemplateLookup(directories=['%s/templates' % os.path.dirname(__file__)],
|
||||
template_lookup = TemplateLookup(directories=[os.path.join(os.path.dirname(__file__), 'templates')],
|
||||
output_encoding='utf-8', encoding_errors='replace')
|
||||
|
||||
|
||||
|
|
@ -50,13 +50,28 @@ class VideoobWeb(BaseApplication):
|
|||
map.connect('index', '/', method='index')
|
||||
|
||||
results = map.routematch(environ=req.environ)
|
||||
if not results:
|
||||
return exc.HTTPNotFound()
|
||||
match, route = results
|
||||
req.urlvars = ((), match)
|
||||
kwargs = match.copy()
|
||||
method = kwargs.pop('method')
|
||||
return getattr(self, method)(req, **kwargs)
|
||||
if results:
|
||||
match, route = results
|
||||
req.urlvars = ((), match)
|
||||
kwargs = match.copy()
|
||||
method = kwargs.pop('method')
|
||||
return getattr(self, method)(req, **kwargs)
|
||||
else:
|
||||
public_path = os.path.join(os.path.dirname(__file__), 'public')
|
||||
if not os.path.exists(public_path):
|
||||
return exc.HTTPNotFound()
|
||||
path = req.path
|
||||
if path.startswith('/'):
|
||||
path = path[1:]
|
||||
public_file_path = os.path.join(public_path, path)
|
||||
if os.path.exists(public_file_path):
|
||||
if path.endswith('.css'):
|
||||
req.response.content_type = 'text/css'
|
||||
elif path.endswith('.js'):
|
||||
req.response.content_type = 'text/javascript'
|
||||
return open(public_file_path, 'r').read().strip()
|
||||
else:
|
||||
return exc.HTTPNotFound()
|
||||
|
||||
def main(self, argv):
|
||||
self.load_config()
|
||||
|
|
@ -79,8 +94,9 @@ class VideoobWeb(BaseApplication):
|
|||
if q:
|
||||
for backend in self.weboob.iter_backends():
|
||||
videos = [dict(title=video.title,
|
||||
page_url=video.page_url,
|
||||
url=video.url if video.url else '/download?id=%s' % video.id
|
||||
page_url=video.page_url,
|
||||
url=video.url if video.url else '/download?id=%s' % video.id,
|
||||
thumbnail_url=video.thumbnail_url,
|
||||
) \
|
||||
for video in backend.iter_search_results(pattern=q, nsfw=nsfw)]
|
||||
if videos:
|
||||
|
|
|
|||
5
weboob/frontends/videoob_web/public/style.css
Normal file
5
weboob/frontends/videoob_web/public/style.css
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.video-item
|
||||
{
|
||||
margin-bottom: 5ex;
|
||||
margin-left: 2em;
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ Videoob Web
|
|||
<head>
|
||||
<title>${self.title()}</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
${next.css()}
|
||||
</head>
|
||||
<body>
|
||||
${next.body()}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,19 @@
|
|||
|
||||
<%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 name="css()" filter="trim">
|
||||
<link rel="stylesheet" type="text/css" href="style.css"/>
|
||||
</%def>
|
||||
|
||||
<%def name="video_item(item)">
|
||||
<div class="video-item">
|
||||
<a href="${item['page_url']}">
|
||||
<img src="${item['thumbnail_url']}" alt="${item['title']}"/>
|
||||
<br/>
|
||||
${item['title']}
|
||||
</a>
|
||||
## (<a href="${item['url']}"><em>download</em></a>)
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%def name="body()">
|
||||
|
|
@ -18,19 +28,15 @@
|
|||
</div>
|
||||
<div id="results">
|
||||
% if merge:
|
||||
<ul>
|
||||
% for item in results:
|
||||
<li>${video_link(item)}</li>
|
||||
% endfor
|
||||
</ul>
|
||||
% for item in results:
|
||||
${video_item(item)}
|
||||
% endfor
|
||||
% else:
|
||||
% for backend, items in sorted(results.iteritems()):
|
||||
<h2>${backend}</h2>
|
||||
<ul>
|
||||
% for item in items:
|
||||
<li>${video_link(item)}</li>
|
||||
% endfor
|
||||
</ul>
|
||||
% for item in items:
|
||||
${video_item(item)}
|
||||
% endfor
|
||||
% endfor
|
||||
% endif
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue