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 sys
import time

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,16 +1,16 @@
<?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>
<LongName>{{instance}}</LongName>
<ShortName>{{instance}}</ShortName>
<Description>{{_('instanceCalibre 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_normal_search')}}?query={searchTerms}"/>
<SyndicationRight>open</SyndicationRight>
<Language>de-DE</Language>
<Language>{{lang}}</Language>
<OutputEncoding>UTF-8</OutputEncoding>
<InputEncoding>UTF-8</InputEncoding>
</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
from tempfile import gettempdir
import hashlib

View File

@ -106,7 +106,7 @@ mimetypes.add_type('image/vnd.djvu', '.djvu')
app = (Flask(__name__))
app.wsgi_app = ReverseProxied(app.wsgi_app)
'''formatter = logging.Formatter(
formatter = logging.Formatter(
"[%(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.setFormatter(formatter)
@ -115,7 +115,7 @@ app.logger.setLevel(config.config_log_level)
app.logger.info('Starting Calibre Web...')
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)
@ -434,7 +434,7 @@ def feed_index():
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
xml = render_template('index.xml')
xml = render_title_template('index.xml')
response = make_response(xml)
response.headers["Content-Type"] = "application/xml"
return response
@ -443,7 +443,7 @@ def feed_index():
@app.route("/opds/osd")
@requires_basic_auth_if_no_ano
def feed_osd():
xml = render_template('osd.xml')
xml = render_title_template('osd.xml',lang='de-DE')
response = make_response(xml)
response.headers["Content-Type"] = "application/xml"
return response
@ -472,9 +472,9 @@ def feed_search(term):
db.Books.title.like("%" + term + "%"))).filter(filter).all()
entriescount = len(entries) if len(entries) > 0 else 1
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:
xml = render_template('feed.xml', searchterm="")
xml = render_title_template('feed.xml', searchterm="")
response = make_response(xml)
response.headers["Content-Type"] = "application/xml"
return response
@ -494,7 +494,7 @@ def feed_new():
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()))
xml = render_template('feed.xml', entries=entries, pagination=pagination)
xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml)
response.headers["Content-Type"] = "application/xml"
return response
@ -512,7 +512,7 @@ def feed_discover():
# off = 0
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))
xml = render_template('feed.xml', entries=entries, pagination=pagination)
xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml)
response.headers["Content-Type"] = "application/xml"
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,
len(db.session.query(db.Books).filter(filter).filter(
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.headers["Content-Type"] = "application/xml"
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)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
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.headers["Content-Type"] = "application/xml"
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,
len(db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id == id)).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.headers["Content-Type"] = "application/xml"
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)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
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.headers["Content-Type"] = "application/xml"
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,
len(db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.id == id)).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.headers["Content-Type"] = "application/xml"
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)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
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.headers["Content-Type"] = "application/xml"
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,
len(db.session.query(db.Books).filter(db.Books.series.any(db.Series.id == id)).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.headers["Content-Type"] = "application/xml"
return response
@ -670,7 +670,7 @@ def get_opds_download_link(book_id, format):
if len(author) > 0:
file_name = author + '-' + 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)
return response