Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Simple OPDS
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Simple OPDS
Commits
c4666f55
Commit
c4666f55
authored
Mar 3, 2017
by
Dmitry Shelepnev
Browse files
Options
Downloads
Patches
Plain Diff
Fix book mimetypes for opdsFedds and downloads
parent
dd689d0f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
book_tools/format/__init__.py
+19
-11
19 additions, 11 deletions
book_tools/format/__init__.py
opds_catalog/dl.py
+6
-14
6 additions, 14 deletions
opds_catalog/dl.py
opds_catalog/feeds.py
+30
-24
30 additions, 24 deletions
opds_catalog/feeds.py
with
55 additions
and
49 deletions
book_tools/format/__init__.py
+
19
−
11
View file @
c4666f55
...
@@ -17,33 +17,41 @@ from constance import config
...
@@ -17,33 +17,41 @@ from constance import config
class
__detector
:
class
__detector
:
@staticmethod
@staticmethod
def
file
(
filename
):
def
format
(
fmt
):
(
n
,
e
)
=
os
.
path
.
splitext
(
filename
)
if
fmt
.
lower
()
==
'
xml
'
:
if
e
.
lower
()
==
'
.xml
'
:
return
Mimetype
.
XML
return
Mimetype
.
XML
if
e
.
lower
()
==
'
.
fb2
'
:
el
if
fmt
.
lower
()
==
'
fb2
'
:
return
Mimetype
.
FB2
return
Mimetype
.
FB2
elif
e
.
lower
()
==
'
.epub
'
or
e
.
lower
()
==
'
.zip
'
:
elif
fmt
.
lower
()
==
'
epub
'
:
return
Mimetype
.
EPUB
elif
fmt
.
lower
()
==
'
mobi
'
:
return
Mimetype
.
MOBI
elif
fmt
.
lower
()
==
'
zip
'
:
return
Mimetype
.
ZIP
return
Mimetype
.
ZIP
elif
e
.
lower
()
==
'
.
pdf
'
:
elif
fmt
.
lower
()
==
'
pdf
'
:
return
Mimetype
.
PDF
return
Mimetype
.
PDF
elif
e
.
lower
()
==
'
.
doc
'
or
e
.
lower
()
==
'
.
docx
'
:
elif
fmt
.
lower
()
==
'
doc
'
or
fmt
.
lower
()
==
'
docx
'
:
return
Mimetype
.
MSWORD
return
Mimetype
.
MSWORD
elif
e
.
lower
()
==
'
.
djvu
'
:
elif
fmt
.
lower
()
==
'
djvu
'
:
return
Mimetype
.
DJVU
return
Mimetype
.
DJVU
elif
e
.
lower
()
==
'
.
txt
'
:
elif
fmt
.
lower
()
==
'
txt
'
:
return
Mimetype
.
TEXT
return
Mimetype
.
TEXT
elif
e
.
lower
()
==
'
.
rtf
'
:
elif
fmt
.
lower
()
==
'
rtf
'
:
return
Mimetype
.
RTF
return
Mimetype
.
RTF
else
:
else
:
return
Mimetype
.
OCTET_STREAM
return
Mimetype
.
OCTET_STREAM
@staticmethod
def
file
(
filename
):
(
n
,
e
)
=
os
.
path
.
splitext
(
filename
)
return
format
(
e
[
1
:])
def
detect_mime
(
file
,
original_filename
):
def
detect_mime
(
file
,
original_filename
):
FB2_ROOT
=
'
FictionBook
'
FB2_ROOT
=
'
FictionBook
'
mime
=
__detector
.
file
(
original_filename
)
mime
=
__detector
.
file
(
original_filename
)
try
:
try
:
if
mime
==
Mimetype
.
XML
or
mime
==
Mimetype
.
FB2
:
if
mime
==
Mimetype
.
XML
:
if
FB2_ROOT
==
__xml_root_tag
(
file
):
if
FB2_ROOT
==
__xml_root_tag
(
file
):
return
Mimetype
.
FB2
return
Mimetype
.
FB2
elif
mime
==
Mimetype
.
ZIP
:
elif
mime
==
Mimetype
.
ZIP
:
...
...
This diff is collapsed.
Click to expand it.
opds_catalog/dl.py
+
6
−
14
View file @
c4666f55
...
@@ -11,7 +11,9 @@ from django.http import HttpResponse, Http404
...
@@ -11,7 +11,9 @@ from django.http import HttpResponse, Http404
from
opds_catalog.models
import
Book
,
bookshelf
from
opds_catalog.models
import
Book
,
bookshelf
from
opds_catalog
import
settings
,
utils
,
opdsdb
,
fb2parse
from
opds_catalog
import
settings
,
utils
,
opdsdb
,
fb2parse
import
opds_catalog.zipf
as
zipfile
import
opds_catalog.zipf
as
zipfile
from
book_tools.format
import
create_bookfile
from
book_tools.format
import
create_bookfile
,
__detector
from
book_tools.format.mimetype
import
Mimetype
from
constance
import
config
from
constance
import
config
from
PIL
import
Image
from
PIL
import
Image
...
@@ -40,17 +42,10 @@ def Download(request, book_id, zip_flag):
...
@@ -40,17 +42,10 @@ def Download(request, book_id, zip_flag):
if
zip_flag
==
'
1
'
:
if
zip_flag
==
'
1
'
:
dlfilename
=
transname
+
'
.zip
'
dlfilename
=
transname
+
'
.zip
'
content_type
=
'
application/zip
'
content_type
=
Mimetype
.
FB2_ZIP
if
book
.
format
==
'
fb2
'
else
Mimetype
.
ZIP
else
:
else
:
dlfilename
=
transname
dlfilename
=
transname
if
book
.
format
==
"
fb2
"
:
content_type
=
__detector
.
format
(
book
.
format
)
content_type
=
'
text/xml
'
elif
book
.
format
==
"
epub
"
:
content_type
=
'
application/epub+zip
'
elif
book
.
format
==
"
mobi
"
:
content_type
=
'
application/x-mobipocket-ebook
'
else
:
content_type
=
'
application/octet-stream
'
response
=
HttpResponse
()
response
=
HttpResponse
()
response
[
"
Content-Type
"
]
=
'
%s; name=
"
%s
"'
%
(
content_type
,
dlfilename
)
response
[
"
Content-Type
"
]
=
'
%s; name=
"
%s
"'
%
(
content_type
,
dlfilename
)
...
@@ -243,12 +238,9 @@ def ConvertFB2(request, book_id, convert_type):
...
@@ -243,12 +238,9 @@ def ConvertFB2(request, book_id, convert_type):
if
convert_type
==
'
epub
'
:
if
convert_type
==
'
epub
'
:
converter_path
=
config
.
SOPDS_FB2TOEPUB
converter_path
=
config
.
SOPDS_FB2TOEPUB
content_type
=
'
application/epub+zip
'
elif
convert_type
==
'
mobi
'
:
elif
convert_type
==
'
mobi
'
:
converter_path
=
config
.
SOPDS_FB2TOMOBI
converter_path
=
config
.
SOPDS_FB2TOMOBI
content_type
=
'
application/x-mobipocket-ebook
'
content_type
=
__detector
.
format
(
convert_type
)
else
:
content_type
=
'
application/octet-stream
'
if
book
.
cat_type
==
opdsdb
.
CAT_NORMAL
:
if
book
.
cat_type
==
opdsdb
.
CAT_NORMAL
:
tmp_fb2_path
=
None
tmp_fb2_path
=
None
...
...
This diff is collapsed.
Click to expand it.
opds_catalog/feeds.py
+
30
−
24
View file @
c4666f55
import
urllib
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.utils.feedgenerator
import
Atom1Feed
,
Enclosure
,
rfc3339_date
from
django.utils.feedgenerator
import
Atom1Feed
,
Enclosure
,
rfc3339_date
from
django.contrib.syndication.views
import
Feed
from
django.contrib.syndication.views
import
Feed
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.core.paginator
import
Paginator
,
EmptyPage
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.db.models
import
Count
,
Min
from
django.db.models
import
Count
,
Min
...
@@ -15,8 +12,12 @@ from opds_catalog import settings
...
@@ -15,8 +12,12 @@ from opds_catalog import settings
from
opds_catalog.middleware
import
BasicAuthMiddleware
from
opds_catalog.middleware
import
BasicAuthMiddleware
from
opds_catalog.opds_paginator
import
Paginator
as
OPDS_Paginator
from
opds_catalog.opds_paginator
import
Paginator
as
OPDS_Paginator
from
book_tools.format
import
__detector
as
detector
from
book_tools.format.mimetype
import
Mimetype
from
constance
import
config
from
constance
import
config
class
AuthFeed
(
Feed
):
class
AuthFeed
(
Feed
):
request
=
None
request
=
None
def
__call__
(
self
,
request
,
*
args
,
**
kwargs
):
def
__call__
(
self
,
request
,
*
args
,
**
kwargs
):
...
@@ -293,17 +294,18 @@ class CatalogsFeed(AuthFeed):
...
@@ -293,17 +294,18 @@ class CatalogsFeed(AuthFeed):
if
item
[
'
is_catalog
'
]:
if
item
[
'
is_catalog
'
]:
return
(
opdsEnclosure
(
reverse
(
"
opds_catalog:cat_tree
"
,
kwargs
=
{
"
cat_id
"
:
item
[
'
id
'
]}),
"
application/atom+xml;profile=opds-catalog;kind=navigation
"
,
"
subsection
"
),)
return
(
opdsEnclosure
(
reverse
(
"
opds_catalog:cat_tree
"
,
kwargs
=
{
"
cat_id
"
:
item
[
'
id
'
]}),
"
application/atom+xml;profile=opds-catalog;kind=navigation
"
,
"
subsection
"
),)
else
:
else
:
enclosure
=
[
mime
=
detector
.
format
(
item
[
'
format
'
])
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
0
}),
"
application/%s
"
%
item
[
'
format
'
]
,
"
http://opds-spec.org/acquisition/open-access
"
),
enclosure
=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
0
}),
mime
,
"
http://opds-spec.org/acquisition/open-access
"
),]
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
1
}),
"
application/%s+zip
"
%
item
[
'
format
'
],
"
http://opds-spec.org/acquisition/open-access
"
),
if
not
item
[
'
format
'
]
in
settings
.
NOZIP_FORMATS
:
opdsEnclosure
(
reverse
(
"
opds_catalog:cover
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/image
"
),
mimezip
=
Mimetype
.
FB2_ZIP
if
mime
==
Mimetype
.
FB2
else
"
%s+zip
"
%
mime
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
1
}),
mimezip
,
"
http://opds-spec.org/acquisition/open-access
"
)]
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:cover
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/image
"
),
opdsEnclosure
(
reverse
(
"
opds_catalog:thumb
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/thumbnail
"
),
opdsEnclosure
(
reverse
(
"
opds_catalog:thumb
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/thumbnail
"
),
]
]
if
(
config
.
SOPDS_FB2TOEPUB
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
if
(
config
.
SOPDS_FB2TOEPUB
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
epub
"
}),
"
application/epub+zip
"
,
"
http://opds-spec.org/acquisition/open-access
"
)]
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
epub
"
}),
Mimetype
.
EPUB
,
"
http://opds-spec.org/acquisition/open-access
"
)]
if
(
config
.
SOPDS_FB2TOMOBI
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
if
(
config
.
SOPDS_FB2TOMOBI
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
mobi
"
}),
"
application/mobi
"
,
"
http://opds-spec.org/acquisition/open-access
"
)]
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
mobi
"
}),
Mimetype
.
MOBI
,
"
http://opds-spec.org/acquisition/open-access
"
)]
return
enclosure
return
enclosure
...
@@ -539,17 +541,21 @@ class SearchBooksFeed(AuthFeed):
...
@@ -539,17 +541,21 @@ class SearchBooksFeed(AuthFeed):
return
item
[
'
registerdate
'
]
return
item
[
'
registerdate
'
]
def
item_enclosures
(
self
,
item
):
def
item_enclosures
(
self
,
item
):
mime
=
detector
.
format
(
item
[
'
format
'
])
enclosure
=
[
enclosure
=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
0
}),
"
application/%s
"
%
item
[
'
format
'
]
,
"
http://opds-spec.org/acquisition/open-access
"
),
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
0
}),
mime
,
"
http://opds-spec.org/acquisition/open-access
"
),
]
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
1
}),
"
application/%s+zip
"
%
item
[
'
format
'
],
"
http://opds-spec.org/acquisition/open-access
"
),
if
not
item
[
'
format
'
]
in
settings
.
NOZIP_FORMATS
:
opdsEnclosure
(
reverse
(
"
opds_catalog:cover
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/image
"
),
mimezip
=
Mimetype
.
FB2_ZIP
if
mime
==
Mimetype
.
FB2
else
"
%s+zip
"
%
mime
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:download
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
zip_flag
"
:
1
}),
mimezip
,
"
http://opds-spec.org/acquisition/open-access
"
)]
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:cover
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/image
"
),
opdsEnclosure
(
reverse
(
"
opds_catalog:thumb
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/thumbnail
"
),
opdsEnclosure
(
reverse
(
"
opds_catalog:thumb
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
]}),
"
image/jpeg
"
,
"
http://opds-spec.org/thumbnail
"
),
]
]
if
(
config
.
SOPDS_FB2TOEPUB
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
if
(
config
.
SOPDS_FB2TOEPUB
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
epub
"
}),
"
application/epub+zip
"
,
"
http://opds-spec.org/acquisition/open-access
"
)]
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
epub
"
}),
Mimetype
.
EPUB
,
"
http://opds-spec.org/acquisition/open-access
"
)]
if
(
config
.
SOPDS_FB2TOMOBI
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
if
(
config
.
SOPDS_FB2TOMOBI
!=
""
)
and
(
item
[
'
format
'
]
==
'
fb2
'
):
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
mobi
"
}),
"
application/mobi
"
,
"
http://opds-spec.org/acquisition/open-access
"
)]
enclosure
+=
[
opdsEnclosure
(
reverse
(
"
opds_catalog:convert
"
,
kwargs
=
{
"
book_id
"
:
item
[
'
id
'
],
"
convert_type
"
:
"
mobi
"
}),
Mimetype
.
MOBI
,
"
http://opds-spec.org/acquisition/open-access
"
)]
return
enclosure
return
enclosure
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment