Commit 31330c7c authored by mitshel's avatar mitshel
Browse files

Додалан функционал показа обложек книг fb2

Теперь только тестировать!!!
parent 611bf6ed
Loading
Loading
Loading
Loading
+27 −15
Original line number Diff line number Diff line
@@ -59,21 +59,33 @@ books_in_archives = 0
#
# Вспомогательные функции
#
def create_cover(book_id,fb2):
def create_cover(book_id,fb2,opdsdb):
    ictype=fb2.cover_image.getattr('content-type')
    f_ext=''
    if ictype!=None:
       if ictype.lower()=='image/jpeg':
          f_ext='.jpg'
       if ictype.lower()=='image/png':
          f_ext='.png'
    fn=os.path.join(sopdscfg.COVER_PATH,str(book_id)+f_ext)
    coverid=fb2.cover_image.getattr('id')
    fn=''
    if ictype==None:
       ictype=''
    else:
       ictype=ictype.lower()
       if ictype=='image/jpeg':
          fn=str(book_id)+'.jpg'
       if ictype=='image/png':
          fn=str(book_id)+'.png'
       if ictype=='application/octet-stream':
          if coverid!=None:
             (f,e)=os.path.splitext(coverid)
          else: 
             e='.img'
          fn=str(book_id)+e
         
       fp=os.path.join(sopdscfg.COVER_PATH,fn)
       if len(fb2.cover_image.cover_data)>0:
       img=open(fn,'wb')
          img=open(fp,'wb')
          s=fb2.cover_image.cover_data
          dstr=base64.b64decode(s)
          img.write(dstr)
          img.close()
    opdsdb.addcover(book_id,fn,ictype)

def processfile(db,fb2,name,full_path,file,archive=0):
    global books_added
@@ -118,7 +130,7 @@ def processfile(db,fb2,name,full_path,file,archive=0):
          books_added+=1
          
          if e.lower()=='.fb2' and cfg.FB2PARSE and cfg.COVER_ENABLE:
             create_cover(book_id,fb2)
             create_cover(book_id,fb2,opdsdb)
          
          if archive==1:
             books_in_archives+=1
+13 −4
Original line number Diff line number Diff line
@@ -72,6 +72,13 @@ def main_menu():
   enc_print('<id>sopds.cgi?id=4</id></entry>')
   opdsdb.closeDB()

def covers(cover,cover_type):
   if cover!=None and cover!='':
      enc_print( '<link href="../covers/%s" rel="http://opds-spec.org/image" type="%s" />'%(cover,cover_type) )
      enc_print( '<link href="../covers/%s" rel="x-stanza-cover-image" type="%s" />'%(cover,cover_type) )
      enc_print( '<link href="../covers/%s" rel="http://opds-spec.org/thumbnail" type="%s" />'%(cover,cover_type) )
      enc_print( '<link href="../covers/%s" rel="x-stanza-cover-image-thumbnail" type="%s" />'%(cover,cover_type) )

###########################################################################
# Основной код программы
#
@@ -263,12 +270,13 @@ if type_value==6:
   opdsdb=sopdsdb.opdsDatabase(cfg.DB_NAME,cfg.DB_USER,cfg.DB_PASS,cfg.DB_HOST,cfg.ROOT_LIB)
   opdsdb.openDB()
   header()
   for (book_id,book_name,book_path,reg_date,book_title,book_genre) in opdsdb.getbooksforautor(slice_value,cfg.MAXITEMS,page_value):
   for (book_id,book_name,book_path,reg_date,book_title,book_genre,cover,cover_type) in opdsdb.getbooksforautor(slice_value,cfg.MAXITEMS,page_value):
       id='07'+str(book_id)
       enc_print('<entry>')
       enc_print('<title>'+book_title+'</title>')
       enc_print('<updated>'+reg_date.strftime("%Y-%m-%dT%H:%M:%SZ")+'</updated>')
       enc_print('<id>sopds.cgi?id='+id+'</id>')
       covers(cover,cover_type)
       enc_print('<link type="application/atom+xml" rel="alternate" href="sopds.cgi?id='+id+'"/>')
       enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="sopds.cgi?id='+id+'"/>')
       authors=""
@@ -300,11 +308,12 @@ elif type_value==7:
   header()
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" rel="start" href="sopds.cgi?id=0" title="'+cfg.SITE_MAINTITLE+'"/>')
   enc_print('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="self" href="sopds.cgi?id='+id+'"/>')
   (book_name,book_path,reg_date,format,title,cat_type)=opdsdb.getbook(slice_value)
   (book_name,book_path,reg_date,format,title,cat_type,cover,cover_type)=opdsdb.getbook(slice_value)
   id='08'+str(slice_value)
   idzip='09'+str(slice_value)
   enc_print('<entry>')
   enc_print('<title>Файл: '+book_name+'</title>')
   covers(cover,cover_type)
   enc_print('<link type="application/'+format+'" rel="alternate" href="sopds.cgi?id='+id+'"/>')
   enc_print('<link type="application/'+format+'" href="sopds.cgi?id='+id+'" rel="http://opds-spec.org/acquisition" />')
   enc_print('<link type="application/'+format+'+zip" href="sopds.cgi?id='+idzip+'" rel="http://opds-spec.org/acquisition" />')
@@ -328,7 +337,7 @@ elif type_value==7:
elif type_value==8:
   opdsdb=sopdsdb.opdsDatabase(cfg.DB_NAME,cfg.DB_USER,cfg.DB_PASS,cfg.DB_HOST,cfg.ROOT_LIB)
   opdsdb.openDB()
   (book_name,book_path,reg_date,format,title,cat_type)=opdsdb.getbook(slice_value)
   (book_name,book_path,reg_date,format,title,cat_type,cover,cover_type)=opdsdb.getbook(slice_value)
   full_path=os.path.join(cfg.ROOT_LIB,book_path)
   transname=translit(book_name)
   # HTTP Header
@@ -364,7 +373,7 @@ elif type_value==8:
elif type_value==9:
   opdsdb=sopdsdb.opdsDatabase(cfg.DB_NAME,cfg.DB_USER,cfg.DB_PASS,cfg.DB_HOST,cfg.ROOT_LIB)
   opdsdb.openDB()
   (book_name,book_path,reg_date,format,title,cat_type)=opdsdb.getbook(slice_value)
   (book_name,book_path,reg_date,format,title,cat_type,cover,cover_type)=opdsdb.getbook(slice_value)
   full_path=os.path.join(cfg.ROOT_LIB,book_path)
   transname=translit(book_name)
   # HTTP Header
+10 −2
Original line number Diff line number Diff line
@@ -128,6 +128,14 @@ class opdsDatabase:
    cursor.close()
    return book_id

  def addcover(self,book_id,fn,cover_type):
    sql=("update "+TBL_BOOKS+" set cover=%s, cover_type=%s where book_id=%s")
    data=(fn,cover_type,book_id)
    cursor=self.cnx.cursor()
    cursor.execute(sql,data)
    self.cnx.commit()
    cursor.close()
    
  def addtag(self, tag, tag_type=0):
    tag_id=self.findtag(tag)
    if tag_id!=0:
@@ -272,7 +280,7 @@ class opdsDatabase:
    return rows

  def getbook(self,book_id):
    sql_getbook=("select filename, path, registerdate, format, title, cat_type from "+TBL_BOOKS+" where book_id="+str(book_id))
    sql_getbook=("select filename, path, registerdate, format, title, cat_type, cover, cover_type from "+TBL_BOOKS+" where book_id="+str(book_id))
    cursor=self.cnx.cursor()
    cursor.execute(sql_getbook)
    row=cursor.fetchone()
@@ -328,7 +336,7 @@ class opdsDatabase:
       limitstr=""
    else:
       limitstr="limit "+str(limit*page)+","+str(limit)
    sql="select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.genre from "+TBL_BOOKS+" a, "+TBL_BAUTHORS+" b where a.book_id=b.book_id and b.author_id="+str(author_id)+" order by a.title "+limitstr
    sql="select SQL_CALC_FOUND_ROWS a.book_id,a.filename,a.path,a.registerdate,a.title,a.genre,a.cover,a.cover_type from "+TBL_BOOKS+" a, "+TBL_BAUTHORS+" b where a.book_id=b.book_id and b.author_id="+str(author_id)+" order by a.title "+limitstr
    cursor=self.cnx.cursor()
    cursor.execute(sql)
    rows=cursor.fetchall()