Code cosmetics

Bugfix download opds
added changable title to opds feed
removed unused search.xml file
This commit is contained in:
OzzieIsaacs 2017-01-29 21:06:08 +01:00
parent e9d0bff559
commit 935b6e3143
10 changed files with 39 additions and 45 deletions

3
cps.py
View File

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os import os
import sys import sys
import time import time

View File

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging import logging
import uploader import uploader
import os import os

View File

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import zipfile import zipfile
from lxml import etree from lxml import etree
import os import os

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from lxml import etree from lxml import etree
import os import os

View File

@ -29,9 +29,9 @@
<link rel="search" <link rel="search"
href="{{url_for('feed_osd')}}" href="{{url_for('feed_osd')}}"
type="application/opensearchdescription+xml"/> type="application/opensearchdescription+xml"/>
<title>Calibre Web</title> <title>{{instance}}</title>
<author> <author>
<name>Calibre Web</name> <name>{{instance}}</name>
<uri>https://github.com/janeczku/calibre-web</uri> <uri>https://github.com/janeczku/calibre-web</uri>
</author> </author>

View File

@ -6,9 +6,9 @@
type="application/atom+xml;profile=opds-catalog;kind=navigation"/> type="application/atom+xml;profile=opds-catalog;kind=navigation"/>
<link rel="search" title="{{_('Search')}}" href="{{url_for('feed_osd')}}" <link rel="search" title="{{_('Search')}}" href="{{url_for('feed_osd')}}"
type="application/opensearchdescription+xml"/> type="application/opensearchdescription+xml"/>
<title>Calibre Web</title> <title>{{instance}}</title>
<author> <author>
<name>Calibre Web</name> <name>{{instance}}</name>
<uri>https://github.com/janeczku/calibre-web</uri> <uri>https://github.com/janeczku/calibre-web</uri>
</author> </author>
<entry> <entry>

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<LongName>Calibre Web</LongName> <LongName>{{instance}}</LongName>
<ShortName>Calibre Web</ShortName> <ShortName>{{instance}}</ShortName>
<Description>Calibre Web ebook catalog</Description> <Description>{{_('instanceCalibre Web ebook catalog')}}</Description>
<Developer>janeczku</Developer> <Developer>Janeczku</Developer>
<Contact>https://github.com/janeczku/calibre-web</Contact> <Contact>https://github.com/janeczku/calibre-web</Contact>
<Url type="text/html" <Url type="text/html"
template="{{url_for('search')}}?query={searchTerms}"/> template="{{url_for('search')}}?query={searchTerms}"/>
<Url type="application/atom+xml" <Url type="application/atom+xml"
template="{{url_for('feed_normal_search')}}?query={searchTerms}"/> template="{{url_for('feed_normal_search')}}?query={searchTerms}"/>
<SyndicationRight>open</SyndicationRight> <SyndicationRight>open</SyndicationRight>
<Language>de-DE</Language> <Language>{{lang}}</Language>
<OutputEncoding>UTF-8</OutputEncoding> <OutputEncoding>UTF-8</OutputEncoding>
<InputEncoding>UTF-8</InputEncoding> <InputEncoding>UTF-8</InputEncoding>
</OpenSearchDescription> </OpenSearchDescription>

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<LongName>Calibre Web</LongName>
<ShortName>Calibre Web</ShortName>
<Description>Calibre Web ebook catalog</Description>
<Developer>janeczku</Developer>
<Contact>https://github.com/janeczku/calibre-web</Contact>
<Url type="text/html"
template="{{url_for('search')}}?query={searchTerms}"/>
<Url type="application/atom+xml"
template="{{url_for('feed_search')}}?query={searchTerms}"/>
<SyndicationRight>open</SyndicationRight>
<Language>de-DE</Language>
<OutputEncoding>UTF-8</OutputEncoding>
<InputEncoding>UTF-8</InputEncoding>
</OpenSearchDescription>

View File

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os import os
from tempfile import gettempdir from tempfile import gettempdir
import hashlib import hashlib

View File

@ -106,7 +106,7 @@ mimetypes.add_type('image/vnd.djvu', '.djvu')
app = (Flask(__name__)) app = (Flask(__name__))
app.wsgi_app = ReverseProxied(app.wsgi_app) app.wsgi_app = ReverseProxied(app.wsgi_app)
'''formatter = logging.Formatter( formatter = logging.Formatter(
"[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
file_handler = RotatingFileHandler(os.path.join(config.get_main_dir, "calibre-web.log"), maxBytes=50000, backupCount=1) file_handler = RotatingFileHandler(os.path.join(config.get_main_dir, "calibre-web.log"), maxBytes=50000, backupCount=1)
file_handler.setFormatter(formatter) file_handler.setFormatter(formatter)
@ -115,7 +115,7 @@ app.logger.setLevel(config.config_log_level)
app.logger.info('Starting Calibre Web...') app.logger.info('Starting Calibre Web...')
logging.getLogger("book_formats").addHandler(file_handler) logging.getLogger("book_formats").addHandler(file_handler)
logging.getLogger("book_formats").setLevel(config.config_log_level)''' logging.getLogger("book_formats").setLevel(config.config_log_level)
Principal(app) Principal(app)
@ -434,7 +434,7 @@ def feed_index():
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else: else:
filter = True filter = True
xml = render_template('index.xml') xml = render_title_template('index.xml')
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -443,7 +443,7 @@ def feed_index():
@app.route("/opds/osd") @app.route("/opds/osd")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_osd(): def feed_osd():
xml = render_template('osd.xml') xml = render_title_template('osd.xml',lang='de-DE')
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -472,9 +472,9 @@ def feed_search(term):
db.Books.title.like("%" + term + "%"))).filter(filter).all() db.Books.title.like("%" + term + "%"))).filter(filter).all()
entriescount = len(entries) if len(entries) > 0 else 1 entriescount = len(entries) if len(entries) > 0 else 1
pagination = Pagination(1, entriescount, entriescount) pagination = Pagination(1, entriescount, entriescount)
xml = render_template('feed.xml', searchterm=term, entries=entries, pagination=pagination) xml = render_title_template('feed.xml', searchterm=term, entries=entries, pagination=pagination)
else: else:
xml = render_template('feed.xml', searchterm="") xml = render_title_template('feed.xml', searchterm="")
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -494,7 +494,7 @@ def feed_new():
config.config_books_per_page) config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(filter).all())) len(db.session.query(db.Books).filter(filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -512,7 +512,7 @@ def feed_discover():
# off = 0 # off = 0
entries = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.config_books_per_page) entries = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.config_books_per_page)
pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page)) pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page))
xml = render_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -533,7 +533,7 @@ def feed_hot():
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(filter).filter( len(db.session.query(db.Books).filter(filter).filter(
db.Books.ratings.any(db.Ratings.rating > 9)).all())) db.Books.ratings.any(db.Ratings.rating > 9)).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -553,7 +553,7 @@ def feed_authorindex():
authors = db.session.query(db.Authors).order_by(db.Authors.sort).offset(off).limit(config.config_books_per_page) authors = db.session.query(db.Authors).order_by(db.Authors.sort).offset(off).limit(config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Authors).all())) len(db.session.query(db.Authors).all()))
xml = render_template('feed.xml', authors=authors, pagination=pagination) xml = render_title_template('feed.xml', authors=authors, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -574,7 +574,7 @@ def feed_author(id):
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id == id)).filter( len(db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id == id)).filter(
filter).all())) filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -589,7 +589,7 @@ def feed_categoryindex():
entries = db.session.query(db.Tags).order_by(db.Tags.name).offset(off).limit(config.config_books_per_page) entries = db.session.query(db.Tags).order_by(db.Tags.name).offset(off).limit(config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Tags).all())) len(db.session.query(db.Tags).all()))
xml = render_template('feed.xml', categorys=entries, pagination=pagination) xml = render_title_template('feed.xml', categorys=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -610,7 +610,7 @@ def feed_category(id):
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.id == id)).filter( len(db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.id == id)).filter(
filter).all())) filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -629,7 +629,7 @@ def feed_seriesindex():
entries = db.session.query(db.Series).order_by(db.Series.name).offset(off).limit(config.config_books_per_page) entries = db.session.query(db.Series).order_by(db.Series.name).offset(off).limit(config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Series).all())) len(db.session.query(db.Series).all()))
xml = render_template('feed.xml', series=entries, pagination=pagination) xml = render_title_template('feed.xml', series=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -650,7 +650,7 @@ def feed_series(id):
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(db.Books.series.any(db.Series.id == id)).filter( len(db.session.query(db.Books).filter(db.Books.series.any(db.Series.id == id)).filter(
filter).all())) filter).all()))
xml = render_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -670,7 +670,7 @@ def get_opds_download_link(book_id, format):
if len(author) > 0: if len(author) > 0:
file_name = author + '-' + file_name file_name = author + '-' + file_name
file_name = helper.get_valid_filename(file_name) file_name = helper.get_valid_filename(file_name)
response = make_response(send_from_directory(os.path.join(config.DB_ROOT, book.path), data.name + "." + format)) response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (data.name, format) response.headers["Content-Disposition"] = "attachment; filename=\"%s.%s\"" % (data.name, format)
return response return response