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']
|
__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')
|
output_encoding='utf-8', encoding_errors='replace')
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -50,13 +50,28 @@ class VideoobWeb(BaseApplication):
|
||||||
map.connect('index', '/', method='index')
|
map.connect('index', '/', method='index')
|
||||||
|
|
||||||
results = map.routematch(environ=req.environ)
|
results = map.routematch(environ=req.environ)
|
||||||
if not results:
|
if results:
|
||||||
return exc.HTTPNotFound()
|
match, route = results
|
||||||
match, route = results
|
req.urlvars = ((), match)
|
||||||
req.urlvars = ((), match)
|
kwargs = match.copy()
|
||||||
kwargs = match.copy()
|
method = kwargs.pop('method')
|
||||||
method = kwargs.pop('method')
|
return getattr(self, method)(req, **kwargs)
|
||||||
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):
|
def main(self, argv):
|
||||||
self.load_config()
|
self.load_config()
|
||||||
|
|
@ -79,8 +94,9 @@ class VideoobWeb(BaseApplication):
|
||||||
if q:
|
if q:
|
||||||
for backend in self.weboob.iter_backends():
|
for backend in self.weboob.iter_backends():
|
||||||
videos = [dict(title=video.title,
|
videos = [dict(title=video.title,
|
||||||
page_url=video.page_url,
|
page_url=video.page_url,
|
||||||
url=video.url if video.url else '/download?id=%s' % video.id
|
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)]
|
for video in backend.iter_search_results(pattern=q, nsfw=nsfw)]
|
||||||
if videos:
|
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>
|
<head>
|
||||||
<title>${self.title()}</title>
|
<title>${self.title()}</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
${next.css()}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
${next.body()}
|
${next.body()}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,19 @@
|
||||||
|
|
||||||
<%inherit file="base.mako"/>
|
<%inherit file="base.mako"/>
|
||||||
|
|
||||||
<%def name="video_link(item)">
|
<%def name="css()" filter="trim">
|
||||||
<a href="${item['page_url']}">${item['title']}</a>
|
<link rel="stylesheet" type="text/css" href="style.css"/>
|
||||||
## (<a href="${item['url']}"><em>download</em></a>)
|
</%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>
|
||||||
|
|
||||||
<%def name="body()">
|
<%def name="body()">
|
||||||
|
|
@ -18,19 +28,15 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="results">
|
<div id="results">
|
||||||
% if merge:
|
% if merge:
|
||||||
<ul>
|
% for item in results:
|
||||||
% for item in results:
|
${video_item(item)}
|
||||||
<li>${video_link(item)}</li>
|
% endfor
|
||||||
% endfor
|
|
||||||
</ul>
|
|
||||||
% else:
|
% else:
|
||||||
% for backend, items in sorted(results.iteritems()):
|
% for backend, items in sorted(results.iteritems()):
|
||||||
<h2>${backend}</h2>
|
<h2>${backend}</h2>
|
||||||
<ul>
|
% for item in items:
|
||||||
% for item in items:
|
${video_item(item)}
|
||||||
<li>${video_link(item)}</li>
|
% endfor
|
||||||
% endfor
|
|
||||||
</ul>
|
|
||||||
% endfor
|
% endfor
|
||||||
% endif
|
% endif
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue