diff --git a/scripts/videoob-web-server b/scripts/videoob-web-server new file mode 100755 index 00000000..5f01b5c8 --- /dev/null +++ b/scripts/videoob-web-server @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai + +""" +Copyright(C) 2010 Christophe Benz + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +""" + +from weboob.frontends.videoob_web import VideoobWeb + +if __name__ == '__main__': + VideoobWeb.run() diff --git a/weboob/frontends/videoob_web/__init__.py b/weboob/frontends/videoob_web/__init__.py new file mode 100644 index 00000000..7497ab6c --- /dev/null +++ b/weboob/frontends/videoob_web/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +""" +Copyright(C) 2010 Christophe Benz + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +""" + +from .application import VideoobWeb diff --git a/weboob/frontends/videoob_web/application.py b/weboob/frontends/videoob_web/application.py new file mode 100644 index 00000000..7c64c8ea --- /dev/null +++ b/weboob/frontends/videoob_web/application.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- + +""" +Copyright(C) 2010 Christophe Benz + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +""" + +import os + +from mako.lookup import TemplateLookup +from mako.runtime import Context +from routes import Mapper +from StringIO import StringIO +from webob.dec import wsgify +from webob import exc +from webob import Response +from wsgiref.simple_server import make_server + +from weboob.capabilities.video import ICapVideoProvider +from weboob.tools.application import BaseApplication + + +__all__ = ['VideoobWeb'] + + +template_lookup = TemplateLookup(directories=['%s/templates' % os.path.dirname(__file__)], + output_encoding='utf-8', encoding_errors='replace') + + +class VideoobWeb(BaseApplication): + APPNAME = 'videoob-web' + CONFIG = dict(host='localhost', port=8080) + + @wsgify + def make_app(self, req): + map = Mapper() + 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) + + def main(self, argv): + self.load_config() + self.weboob.load_modules(ICapVideoProvider) + print 'Web server created. Listening on http://%s:%s' % ( + self.config.get('host'), int(self.config.get('port'))) + srv = make_server(self.config.get('host'), int(self.config.get('port')), self.make_app) + srv.serve_forever() + + def index(self, req): + c = {} + nsfw = req.params.get('nsfw') + nsfw = False if not nsfw or nsfw == '0' else True + q = req.params.get('q', u'') + c['form_data'] = dict(q=q) + c['results'] = {} + if q: + for backend in self.weboob.iter_backends(): + items = [(video.id, video.title, video.formatted_duration) for video in + backend.iter_search_results(pattern=q, nsfw=nsfw)] + if items: + c['results'][backend.name] = items + template = template_lookup.get_template('index.mako') + buf = StringIO() + ctx = Context(buf, **c) + template.render_context(ctx) + return buf.getvalue().strip() diff --git a/weboob/frontends/videoob_web/templates/base.mako b/weboob/frontends/videoob_web/templates/base.mako new file mode 100644 index 00000000..30e759e7 --- /dev/null +++ b/weboob/frontends/videoob_web/templates/base.mako @@ -0,0 +1,16 @@ +## -*- coding: utf-8 -*- + +<%def name="title()" filter="trim"> +Videoob Web + + + + + + ${self.title()} + + + + ${next.body()} + + diff --git a/weboob/frontends/videoob_web/templates/index.mako b/weboob/frontends/videoob_web/templates/index.mako new file mode 100644 index 00000000..b228070c --- /dev/null +++ b/weboob/frontends/videoob_web/templates/index.mako @@ -0,0 +1,20 @@ +## -*- coding: utf-8 -*- + +<%inherit file="base.mako"/> + +<%def name="body()"> +

Videoob Web

+ +
+ % for backend, items in results.iteritems(): +

${backend}

+ ${items} + % endfor +
+