Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
90729de8
Commit
90729de8
authored
Oct 06, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Plain Diff
Fix #354
Fix #355 Fix #353 Fix #352 Fix #351
parents
56c71dd4
6855dece
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
42 deletions
+50
-42
feed.xml
cps/templates/feed.xml
+1
-2
index.xml
cps/templates/index.xml
+11
-18
ub.py
cps/ub.py
+6
-1
web.py
cps/web.py
+32
-21
No files found.
cps/templates/feed.xml
View file @
90729de8
...
...
@@ -64,8 +64,7 @@
<entry>
<title>
{{entry.name}}
</title>
<id>
{{ url_for(folder, book_id=entry.id) }}
</id>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for(folder, book_id=entry.id)}}"
/>
<link
type=
"application/atom+xml"
href=
"{{url_for(folder, book_id=entry.id)}}"
rel=
"subsection"
/>
<link
rel=
"subsection"
type=
"application/atom+xml;profile=opds-catalog"
href=
"{{url_for(folder, book_id=entry.id)}}"
/>
</entry>
{% endfor %}
</feed>
cps/templates/index.xml
View file @
90729de8
...
...
@@ -12,64 +12,57 @@
</author>
<entry>
<title>
{{_('Hot Books')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_hot')}}"
/>
<link
type=
"application/atom+xml"
href=
"{{url_for('feed_hot')}}"
rel=
"http://opds-spec.org/sort/popular"
/>
<link
rel=
"http://opds-spec.org/sort/popular"
href=
"{{url_for('feed_hot')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_hot')}}
</id>
<content
type=
"text"
>
{{_('Popular publications from this catalog based on Downloads.')}}
</content>
</entry>
<entry>
<title>
{{_('Best rated Books')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_best_rated')}}"
/>
<link
type=
"application/atom+xml"
href=
"{{url_for('feed_best_rated')}}"
rel=
"http://opds-spec.org/recommended"
/>
<link
rel=
"http://opds-spec.org/recommended"
href=
"{{url_for('feed_best_rated')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_best_rated')}}
</id>
<content
type=
"text"
>
{{_('Popular publications from this catalog based on Rating.')}}
</content>
</entry>
<entry>
<title>
{{_('New Books')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_new')}}"
/>
<link
rel=
"http://opds-spec.org/sort/new"
href=
"{{url_for('feed_new')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
/>
<link
rel=
"http://opds-spec.org/sort/new"
href=
"{{url_for('feed_new')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_new')}}
</id>
<content
type=
"text"
>
{{_('The latest Books')}}
</content>
</entry>
<entry>
<title>
{{_('Random Books')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_discover')}}"
/>
<link
rel=
"http://opds-spec.org/featured"
href=
"{{url_for('feed_discover')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
/>
<link
rel=
"http://opds-spec.org/featured"
href=
"{{url_for('feed_discover')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_discover')}}
</id>
<content
type=
"text"
>
{{_('Show Random Books')}}
</content>
</entry>
{% if not current_user.is_anonymous() %}
<entry>
<title>
{{_('Read Books')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_read_books')}}"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_read_books')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_read_books')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_read_books')}}
</id>
<content
type=
"text"
>
{{_('Read Books')}}
</content>
</entry>
<entry>
<title>
{{_('Unread Books')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_unread_books')}}"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_unread_books')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_unread_books')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_unread_books')}}
</id>
<content
type=
"text"
>
{{_('Unread Books')}}
</content>
</entry>
{% endif %}
<entry>
<title>
{{_('Authors')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_authorindex')}}"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_authorindex')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_authorindex')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_authorindex')}}
</id>
<content
type=
"text"
>
{{_('Books ordered by Author')}}
</content>
</entry>
<entry>
<title>
{{_('Category list')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_categoryindex')}}"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_categoryindex')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_categoryindex')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_categoryindex')}}
</id>
<content
type=
"text"
>
{{_('Books ordered by category')}}
</content>
</entry>
<entry>
<title>
{{_('Series list')}}
</title>
<link
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition"
href=
"{{url_for('feed_seriesindex')}}"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_seriesindex')}}"
type=
"application/atom+xml;profile=opds-catalog;type=feed;kind=navigation"
/>
<link
rel=
"subsection"
href=
"{{url_for('feed_seriesindex')}}"
type=
"application/atom+xml;profile=opds-catalog"
/>
<id>
{{url_for('feed_seriesindex')}}
</id>
<content
type=
"text"
>
{{_('Books ordered by series')}}
</content>
</entry>
...
...
cps/ub.py
View file @
90729de8
...
...
@@ -6,6 +6,7 @@ from sqlalchemy import exc
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm
import
*
from
flask_login
import
AnonymousUserMixin
import
sys
import
os
import
logging
from
werkzeug.security
import
generate_password_hash
...
...
@@ -387,7 +388,11 @@ class Config:
(
self
.
config_default_role
&
ROLE_DELETE_BOOKS
==
ROLE_DELETE_BOOKS
))
def
mature_content_tags
(
self
):
return
list
(
map
(
unicode
.
lstrip
,
self
.
config_mature_content_tags
.
split
(
","
)))
if
(
sys
.
version_info
>
(
3
,
0
)):
#Python3 str, Python2 unicode
lstrip
=
str
.
lstrip
else
:
lstrip
=
unicode
.
lstrip
return
list
(
map
(
lstrip
,
self
.
config_mature_content_tags
.
split
(
","
)))
def
get_Log_Level
(
self
):
ret_value
=
""
...
...
cps/web.py
View file @
90729de8
...
...
@@ -203,6 +203,7 @@ class ReverseProxied(object):
mimetypes
.
init
()
mimetypes
.
add_type
(
'application/xhtml+xml'
,
'.xhtml'
)
mimetypes
.
add_type
(
'application/epub+zip'
,
'.epub'
)
mimetypes
.
add_type
(
'application/fb2+zip'
,
'.fb2'
)
mimetypes
.
add_type
(
'application/x-mobipocket-ebook'
,
'.mobi'
)
mimetypes
.
add_type
(
'application/x-mobipocket-ebook'
,
'.prc'
)
mimetypes
.
add_type
(
'application/vnd.amazon.ebook'
,
'.azw'
)
...
...
@@ -631,7 +632,7 @@ def before_request():
def
feed_index
():
xml
=
render_title_template
(
'index.xml'
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -640,7 +641,7 @@ def feed_index():
def
feed_osd
():
xml
=
render_title_template
(
'osd.xml'
,
lang
=
'de-DE'
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/xml"
response
.
headers
[
"Content-Type"
]
=
"application/xml
; charset=utf-8
"
return
response
...
...
@@ -670,7 +671,7 @@ def feed_search(term):
else
:
xml
=
render_title_template
(
'feed.xml'
,
searchterm
=
""
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -684,7 +685,7 @@ def feed_new():
db
.
Books
,
True
,
db
.
Books
.
timestamp
.
desc
())
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -696,7 +697,7 @@ def feed_discover():
pagination
=
Pagination
(
1
,
config
.
config_books_per_page
,
int
(
config
.
config_books_per_page
))
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -710,7 +711,7 @@ def feed_best_rated():
db
.
Books
,
db
.
Books
.
ratings
.
any
(
db
.
Ratings
.
rating
>
9
),
db
.
Books
.
timestamp
.
desc
())
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -738,7 +739,7 @@ def feed_hot():
pagination
=
Pagination
((
int
(
off
)
/
(
int
(
config
.
config_books_per_page
))
+
1
),
config
.
config_books_per_page
,
numBooks
)
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -754,7 +755,7 @@ def feed_authorindex():
len
(
db
.
session
.
query
(
db
.
Authors
)
.
all
()))
xml
=
render_title_template
(
'feed.xml'
,
listelements
=
entries
,
folder
=
'feed_author'
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -768,7 +769,7 @@ def feed_author(book_id):
db
.
Books
,
db
.
Books
.
authors
.
any
(
db
.
Authors
.
id
==
book_id
),
db
.
Books
.
timestamp
.
desc
())
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -784,7 +785,7 @@ def feed_categoryindex():
len
(
db
.
session
.
query
(
db
.
Tags
)
.
all
()))
xml
=
render_title_template
(
'feed.xml'
,
listelements
=
entries
,
folder
=
'feed_category'
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -798,7 +799,7 @@ def feed_category(book_id):
db
.
Books
,
db
.
Books
.
tags
.
any
(
db
.
Tags
.
id
==
book_id
),
db
.
Books
.
timestamp
.
desc
())
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -814,7 +815,7 @@ def feed_seriesindex():
len
(
db
.
session
.
query
(
db
.
Series
)
.
all
()))
xml
=
render_title_template
(
'feed.xml'
,
listelements
=
entries
,
folder
=
'feed_series'
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -828,7 +829,7 @@ def feed_series(book_id):
db
.
Books
,
db
.
Books
.
series
.
any
(
db
.
Series
.
id
==
book_id
),
db
.
Books
.
series_index
)
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
response
.
headers
[
"Content-Type"
]
=
"application/
xml
"
response
.
headers
[
"Content-Type"
]
=
"application/
atom+xml; charset=utf-8
"
return
response
...
...
@@ -873,7 +874,11 @@ def get_opds_download_link(book_id, book_format):
file_name
=
helper
.
get_valid_filename
(
file_name
)
headers
=
Headers
()
headers
[
"Content-Disposition"
]
=
"attachment; filename*=UTF-8''
%
s.
%
s"
%
(
quote
(
file_name
.
encode
(
'utf8'
)),
book_format
)
app
.
logger
.
info
(
time
.
time
()
-
startTime
)
try
:
headers
[
"Content-Type"
]
=
mimetypes
.
types_map
[
'.'
+
book_format
]
except
KeyError
:
headers
[
"Content-Type"
]
=
"application/octet-stream"
app
.
logger
.
info
(
time
.
time
()
-
startTime
)
startTime
=
time
.
time
()
if
config
.
config_use_google_drive
:
app
.
logger
.
info
(
time
.
time
()
-
startTime
)
...
...
@@ -1712,15 +1717,21 @@ def feed_get_cover(book_id):
def
render_read_books
(
page
,
are_read
,
as_xml
=
False
):
readBooks
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
))
.
filter
(
ub
.
ReadBook
.
is_read
==
True
)
.
all
()
readBookIds
=
[
x
.
book_id
for
x
in
readBooks
]
if
are_read
:
db_filter
=
db
.
Books
.
id
.
in_
(
readBookIds
)
if
not
current_user
.
is_anonymous
():
readBooks
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
))
.
filter
(
ub
.
ReadBook
.
is_read
==
True
)
.
all
()
readBookIds
=
[
x
.
book_id
for
x
in
readBooks
]
if
are_read
:
db_filter
=
db
.
Books
.
id
.
in_
(
readBookIds
)
else
:
db_filter
=
~
db
.
Books
.
id
.
in_
(
readBookIds
)
entries
,
random
,
pagination
=
fill_indexpage
(
page
,
db
.
Books
,
db_filter
,
db
.
Books
.
timestamp
.
desc
())
else
:
db_filter
=
~
db
.
Books
.
id
.
in_
(
readBookIds
)
entries
=
[]
random
=
False
pagination
=
Pagination
(
page
,
1
,
0
)
entries
,
random
,
pagination
=
fill_indexpage
(
page
,
db
.
Books
,
db_filter
,
db
.
Books
.
timestamp
.
desc
())
if
as_xml
:
xml
=
render_title_template
(
'feed.xml'
,
entries
=
entries
,
pagination
=
pagination
)
response
=
make_response
(
xml
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment