Commit 6d5565d8 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Add thumbnail to opds feeds

parent 35088409
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -11,7 +11,9 @@ from django.http import HttpResponse, Http404
from opds_catalog.models import Book, bookshelf
from opds_catalog import settings, utils, opdsdb, fb2parse
import opds_catalog.zipf as zipfile

from constance import config
from PIL import Image

def Download(request, book_id, zip_flag):
    """ Загрузка файла книги """
@@ -94,7 +96,7 @@ def Download(request, book_id, zip_flag):

    return response

def Cover(request, book_id):
def Cover(request, book_id, thumbnail = False):
    """ Загрузка обложки """
    book = Book.objects.get(id=book_id)
    response = HttpResponse()
@@ -127,6 +129,11 @@ def Cover(request, book_id):
                s=fb2.cover_image.cover_data
                dstr=base64.b64decode(s)
                response["Content-Type"]=fb2.cover_image.getattr('content-type')
                if thumbnail:
                    #thumb = Image.open(io.StringIO(dstr))
                    thumb = Image.fromstring(dstr)
                    thumb.thumbnail((settings.THUMB_SIZE, settings.THUMB_SIZE), Image.ANTIALIAS)
                    thumb = Image.tostring(dstr)
                response.write(dstr)
                c0=1
            except:
@@ -143,6 +150,10 @@ def Cover(request, book_id):

    return response

def Thumbnail(request, book_id):
    return Cover(request, book_id, True)


def ConvertFB2(request, book_id, convert_type):
    """ Выдача файла книги после конвертации в EPUB или mobi """
    book = Book.objects.get(id=book_id)
+3 −0
Original line number Diff line number Diff line
@@ -297,6 +297,7 @@ class CatalogsFeed(AuthFeed):
                opdsEnclosure(reverse("opds_catalog:download", kwargs={"book_id":item['id'],"zip_flag":0}),"application/fb2" ,"http://opds-spec.org/acquisition/open-access"),
                opdsEnclosure(reverse("opds_catalog:download", kwargs={"book_id":item['id'],"zip_flag":1}),"application/fb2+zip", "http://opds-spec.org/acquisition/open-access"),
                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"),
            )
    
    def item_description(self, item):
@@ -535,6 +536,8 @@ class SearchBooksFeed(AuthFeed):
            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":1}),"application/%s+zip"%item['format'], "http://opds-spec.org/acquisition/open-access"),
            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"),

        ]
        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")] 
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ VERSION = "0.41"
TITLE = getattr(settings, "SOPDS_TITLE", "SimpleOPDS")
SUBTITLE = getattr(settings, "SOPDS_SUBTITLE", "SimpleOPDS Catalog by www.sopds.ru. Version %s."%VERSION)
ICON = getattr(settings, "SOPDS_ICON", "/static/images/favicon.ico")
THUMB_SIZE = 50

loglevel = getattr(settings, "SOPDS_LOGLEVEL", "info")
if loglevel.lower() in loglevels:
+2 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ urlpatterns = [
    url(r'^convert/(?P<book_id>[0-9]+)/(?P<convert_type>.+)/$',dl.ConvertFB2, name='convert'),    
    url(r'^download/(?P<book_id>[0-9]+)/(?P<zip_flag>[0-1])/$',dl.Download, name='download'),
    url(r'^cover/(?P<book_id>[0-9]+)/$',dl.Cover, name='cover'),
    url(r'^thumb/(?P<book_id>[0-9]+)/$',dl.Thumbnail, name='thumb'),
    url(r'^cover/$',dl.Cover, name='covertmpl'),  
        
    url(r'^',feeds.MainFeed(), name='main'),