Loading conf/sopds.conf +1 −1 Original line number Diff line number Diff line Loading @@ -151,7 +151,7 @@ scan_interval = 360 # scan_on_start определяет необходимость запуска сканирования при старте sopdsd.py # если scan_on_start = yes , то при запуске sopdsd.py сразу же запустится сканирование # по умолчанию scan_on_start = yes scan_on_start = yes scan_on_start = no # Параметр logfile задает имя файла, куда будут складываться логи от SCAND-демона (путь задавать не нужно - логи будут находится в папке logs) # По умолчанию logfile = sopds-scand.log Loading py/__pycache__/sopdscfg.cpython-33.pyc (7.5 KiB) File changed.No diff preview for this file type. View original file View changed file py/sopdscli.py +16 −111 Original line number Diff line number Diff line Loading @@ -146,32 +146,21 @@ class opdsClient(): self.user=user def add_response_body(self, string='', encoding='utf8'): # self.response_body+=[string.encode(encoding)] self.opdsWrapper.add_response_body(string,encoding) def add_response_binary(self, data): # self.response_body+=[data] self.opdsWrapper.add_response_binary(data) def add_response_header(self,list): # self.response_headers+=list self.opdsWrapper.add_response_header(list) def set_response_status(self,status): # self.response_status=status self.opdsWrapper.set_response_status(status) def write_response_headers(self, encoding='utf8'): # sys.stdout.buffer.write(b'Status: '+self.response_status.encode(encoding)+ b'\n') # for header in self.response_headers: # (a,b)=header # sys.stdout.buffer.write(a.encode(encoding)+b': '+b.encode(encoding) + b'\n') # sys.stdout.buffer.write(b'\n') self.opdsWrapper.write_response_headers(encoding) def write_response(self): # for element in self.response_body: # sys.stdout.buffer.write(element + b'\n') self.opdsWrapper.write_response() def get_response_status(self): Loading @@ -187,127 +176,43 @@ class opdsClient(): if h_id==None: h_id=self.cfg.SITE_ID if h_title==None: h_title=self.cfg.SITE_TITLE if h_subtitle==None: h_subtitle='Simple OPDS Catalog by www.sopds.ru. Version '+sopdscfg.VERSION # self.add_response_header([('Content-Type','text/xml; charset='+charset)]) # self.add_response_body('<?xml version="1.0" encoding="'+charset+'"?>') # self.add_response_body('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/terms/" xmlns:os="http://a9.com/-/spec/opensearch/1.1/" xmlns:opds="http://opds-spec.org/2010/catalog">') # self.add_response_body('<id>%s</id>'%h_id) # self.add_response_body('<title>%s</title>'%h_title) # self.add_response_body('<subtitle>%s</subtitle>'%h_subtitle) # self.add_response_body('<updated>'+time.strftime("%Y-%m-%dT%H:%M:%SZ")+'</updated>') # self.add_response_body('<icon>'+self.cfg.SITE_ICON+'</icon>') # self.add_response_body('<author><name>'+self.cfg.SITE_AUTOR+'</name><uri>'+self.cfg.SITE_URL+'</uri><email>'+self.cfg.SITE_EMAIL+'</email></author>') # self.add_response_body('<link type="application/atom+xml" rel="start" href="'+self.modulePath+'?id=00"/>') self.opdsWrapper.header(h_id,h_title,h_subtitle,time.strftime("%Y-%m-%dT%H:%M:%SZ")) def footer(self): # self.add_response_body('</feed>') self.opdsWrapper.footer() def main_menu(self): # if self.cfg.ALPHA: am='30' # else: am='' dbinfo=self.opdsdb.getdbinfo(self.cfg.DUBLICATES_SHOW,self.cfg.BOOK_SHELF,self.user) # self.add_response_body('<link href="'+self.modulePath+'?id=09" rel="search" type="application/opensearchdescription+xml" />') # self.add_response_body('<link href="'+self.modulePath+'?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />') # self.add_response_body('<entry>') # self.add_response_body('<title>По каталогам</title>') # self.add_response_body('<content type="text">Каталогов: %s, книг: %s.</content>'%(dbinfo[2][1],dbinfo[0][1])) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=01"/>') # self.add_response_body('<id>id:01</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По авторам</title>') # self.add_response_body('<content type="text">Авторов: %s.</content>'%dbinfo[1][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'02"/>') # self.add_response_body('<id>id:02</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По наименованию</title>') # self.add_response_body('<content type="text">Книг: %s.</content>'%dbinfo[0][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'03"/>') # self.add_response_body('<id>id:03</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По Жанрам</title>') # self.add_response_body('<content type="text">Жанров: %s.</content>'%dbinfo[3][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=04"/>') # self.add_response_body('<id>id:04</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По Сериям</title>') # self.add_response_body('<content type="text">Серий: %s.</content>'%dbinfo[4][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'06"/>') # self.add_response_body('<id>id:06</id></entry>') # if self.cfg.NEW_PERIOD!=0: # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки за %s суток</title>'%self.cfg.NEW_PERIOD) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=05"/>') # self.add_response_body('<id>id:05</id></entry>') # if self.cfg.BOOK_SHELF and self.user!=None: # self.add_response_body('<entry>') # self.add_response_body('<title>Книжная полка для %s</title>'%self.user) # self.add_response_body('<content type="text">Книг: %s.</content>'%dbinfo[5][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=08"/>') # self.add_response_body('<id>id:08</id></entry>') self.opdsWrapper.main_menu(self.user,dbinfo) def new_menu(self): # if self.cfg.ALPHA: am='30' # else: am='' newinfo=self.opdsdb.getnewinfo(self.cfg.DUBLICATES_SHOW,self.cfg.NEW_PERIOD) # self.add_response_body('<entry>') # self.add_response_body('<title>Все новинки за %s суток</title>'%self.cfg.NEW_PERIOD) # self.add_response_body('<content type="text">Новых книг: %s.</content>'%newinfo[0][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'03&news=1"/>') # self.add_response_body('<id>id:03:news</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки по авторам</title>') # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'02&news=1"/>') # self.add_response_body('<id>id:02:news</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки по Жанрам</title>') # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=04&news=1"/>') # self.add_response_body('<id>id:04:news</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки по Сериям</title>') # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'06&news=1"/>') # self.add_response_body('<id>id:06:news</id></entry>') self.opdsWrapper.new_menu(newinfo) def authors_submenu(self,author_id): self.add_response_body('<entry>') self.add_response_body('<title>Книги по сериям</title>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=31'+str(author_id)+'"/>') self.add_response_body('<id>id:31:authors</id></entry>') self.add_response_body('<entry>') self.add_response_body('<title>Книги вне серий</title>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=34'+str(author_id)+'"/>') self.add_response_body('<id>id:32:authors</id></entry>') self.add_response_body('<entry>') self.add_response_body('<title>Книги по алфавиту</title>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=33'+str(author_id)+'"/>') self.add_response_body('<id>id:33:authors</id></entry>') self.opdsWrapper.authors_submenu(author_id) def entry_start(self): self.add_response_body('<entry>') self.opdsWrapper.entry_start() def entry_head(self,e_title,e_date,e_id): self.add_response_body('<title>'+websym(e_title)+'</title>') if e_date!=None: self.add_response_body('<updated>'+e_date.strftime("%Y-%m-%dT%H:%M:%S")+'</updated>') self.add_response_body('<id>id:'+e_id+'</id>') self.opdsWrapper.entry_head(e_title,e_date,e_id) def entry_link_subsection(self,link_id): self.add_response_body('<link type="application/atom+xml" rel="alternate" href="'+self.modulePath+'?id='+link_id+self.nl+'"/>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="'+self.modulePath+'?id='+link_id+self.nl+'"/>') self.opdsWrapper.entry_link_subsection(link_id,self.nl) def entry_link_book(self,link_id,format): str_id=str(link_id) self.add_response_body('<link type="application/'+format+'" rel="alternate" href="'+self.modulePath+'?id=91'+str_id+'"/>') if format.lower()=='fb2' and self.cfg.FB2TOEPUB: self.add_response_body('<link type="application/epub" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/epub+zip" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') if format.lower()=='fb2' and self.cfg.FB2TOMOBI: self.add_response_body('<link type="application/mobi" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/mobi+zip" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/'+format+'" href="'+self.modulePath+'?id=91'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/'+format+'+zip" href="'+self.modulePath+'?id=92'+str_id+'" rel="http://opds-spec.org/acquisition" />') # str_id=str(link_id) # self.add_response_body('<link type="application/'+format+'" rel="alternate" href="'+self.modulePath+'?id=91'+str_id+'"/>') # if format.lower()=='fb2' and self.cfg.FB2TOEPUB: # self.add_response_body('<link type="application/epub" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/epub+zip" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') # if format.lower()=='fb2' and self.cfg.FB2TOMOBI: # self.add_response_body('<link type="application/mobi" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/mobi+zip" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/'+format+'" href="'+self.modulePath+'?id=91'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/'+format+'+zip" href="'+self.modulePath+'?id=92'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.opdsWrapper.entry_link_book(link_id,format) def entry_authors(self,book_id,link_show=False): authors="" Loading Loading @@ -381,7 +286,7 @@ class opdsClient(): self.add_response_body('</content>') def entry_finish(self): self.add_response_body('</entry>') self.opdsWrapper.entry_finish() def page_control(self, page, link_id): if page>0: Loading py/sopdswrap.py +83 −34 Original line number Diff line number Diff line import sopdscfg import datetime class opdsTemplate(): def __init__(self, modulepath, charset='utf-8'): Loading @@ -13,9 +14,11 @@ class opdsTemplate(): <updated>%%(updated)s</updated> <icon>%%(site_icon)s</icon> <author><name>%%(site_author)s</name><uri>%%(site_url)s</uri><email>%%(site_email)s</email></author> <link type="application/atom+xml" rel="start" href="%(modulepath)s?id=00"/>'''%{'charset':self.charset,'modulepath':self.modulepath} <link type="application/atom+xml" rel="start" href="%(modulepath)s?id=00"/> '''%{'charset':self.charset,'modulepath':self.modulepath} self.document_footer='''</feed>''' self.document_mainmenu_std='''<link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" /> self.document_mainmenu_std=''' <link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" /> <link href="%(modulepath)s?searchTerm={searchTerms}" rel="search" type="application/atom+xml" /> <entry> <title>По каталогам</title> Loading @@ -41,17 +44,23 @@ class opdsTemplate(): <title>По Сериям</title> <content type="text">Серий: %%(series_num)s.</content> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s06"/> <id>id:06</id></entry>'''%{'modulepath':self.modulepath} self.document_mainmenu_new='''<entry> <id>id:06</id></entry> '''%{'modulepath':self.modulepath} self.document_mainmenu_new=''' <entry> <title>Новинки за %%(new_period)s суток</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=05"/> <id>id:05</id></entry>'''%{'modulepath':self.modulepath} self.document_mainmenu_shelf='''<entry> <id>id:05</id></entry> '''%{'modulepath':self.modulepath} self.document_mainmenu_shelf=''' <entry> <title>Книжная полка для %%(user)s</title> <content type="text">Книг: %%(book_num)s.</content> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=08"/> <id>id:08</id></entry>'''%{'modulepath':self.modulepath} self.document_newmenu='''<entry> <id>id:08</id></entry> '''%{'modulepath':self.modulepath} self.document_newmenu=''' <entry> <title>Все новинки за %%(new_period)s суток</title> <content type="text">Новых книг: %%(newbook_num)s.</content> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s03&news=1"/> Loading @@ -67,7 +76,39 @@ class opdsTemplate(): <entry> <title>Новинки по Сериям</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s06&news=1"/> <id>id:06:news</id></entry>'''%{'modulepath':self.modulepath} <id>id:06:news</id></entry> '''%{'modulepath':self.modulepath} self.document_authors_submenu=''' <entry> <title>Книги по сериям</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=31%%(author_id)s"/> <id>id:31:authors</id></entry> <entry> <title>Книги вне серий</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=34%%(author_id)s"/> <id>id:32:authors</id></entry> <entry> <title>Книги по алфавиту</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=33%%(author_id)s"/> <id>id:33:authors</id></entry> '''%{'modulepath':self.modulepath} self.document_entry_start='''<entry>''' self.document_entry_finish='''</entry>''' self.document_entry_head=''' <title>%(e_title)s</title> <updated>%(e_date)s</updated> <id>id:%(e_id)s</id> ''' self.document_entry_link_subsection=''' <link type="application/atom+xml" rel="alternate" href="%(modulepath)s?id=%%(link_id)s%%(nl)s"/> <link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="%(modulepath)s?id=%%(link_id)s%%(nl)s"/> '''%{'modulepath':self.modulepath} self.document_entry_link_book_alternate=''' <link type="application/%%(format)s" rel="alternate" href="%(modulepath)s?id=91%%(link_id)s"/> '''%{'modulepath':self.modulepath} self.document_entry_link_book=''' <link type="application/%%(format)s" href="%(modulepath)s?id=%%(id)s%%(link_id)s" rel="http://opds-spec.org/acquisition" /> '''%{'modulepath':self.modulepath} Loading Loading @@ -134,19 +175,27 @@ class baseWrapper(): self.add_response_body(self.template.document_newmenu%{'new_period':self.cfg.NEW_PERIOD,'newbook_num':NEWINFO[0][1],'alphabet_id':am}) def authors_submenu(self,author_id): pass self.add_response_body(self.template.document_authors_submenu%{'author_id':author_id}) def entry_start(self): pass self.add_response_body(self.template.document_entry_start) def entry_head(self,e_title,e_date,e_id): pass def entry_link_subsection(self,link_id,modulePath): pass def entry_link_book(self,link_id,format,modulePath): pass if e_date==None: e_date=datetime.datetime(2001,9,9,0,0,0) self.add_response_body(self.template.document_entry_head%{'e_title':e_title,'e_date':e_date.strftime("%Y-%m-%dT%H:%M:%S"),'e_id':e_id}) def entry_link_subsection(self,link_id,nl): self.add_response_body(self.template.document_entry_link_subsection%{'link_id':link_id,'nl':nl}) def entry_link_book(self,link_id,format): self.add_response_body(self.template.document_entry_link_book_alternate%{'format':format,'link_id':link_id}) if format.lower()=='fb2' and self.cfg.FB2TOEPUB: self.add_response_body(self.template.document_entry_link_book%{'id':93,'format':'epub','link_id':link_id}) if format.lower()=='fb2' and self.cfg.FB2TOMOBI: self.add_response_body(self.template.document_entry_link_book%{'id':94,'format':'mobi','link_id':link_id}) self.add_response_body(self.template.document_entry_link_book%{'id':91,'format':format,'link_id':link_id}) self.add_response_body(self.template.document_entry_link_book%{'id':92,'format':format+'.zip','link_id':link_id}) def entry_authors(self,book_id,tupleAITHORS,link_show=False): authors='' Loading @@ -173,7 +222,7 @@ class baseWrapper(): pass def entry_finish(self): pass self.add_response_body(self.template.document_entry_finish) def page_control(self, page, link_id, modulePath): pass Loading Loading
conf/sopds.conf +1 −1 Original line number Diff line number Diff line Loading @@ -151,7 +151,7 @@ scan_interval = 360 # scan_on_start определяет необходимость запуска сканирования при старте sopdsd.py # если scan_on_start = yes , то при запуске sopdsd.py сразу же запустится сканирование # по умолчанию scan_on_start = yes scan_on_start = yes scan_on_start = no # Параметр logfile задает имя файла, куда будут складываться логи от SCAND-демона (путь задавать не нужно - логи будут находится в папке logs) # По умолчанию logfile = sopds-scand.log Loading
py/__pycache__/sopdscfg.cpython-33.pyc (7.5 KiB) File changed.No diff preview for this file type. View original file View changed file
py/sopdscli.py +16 −111 Original line number Diff line number Diff line Loading @@ -146,32 +146,21 @@ class opdsClient(): self.user=user def add_response_body(self, string='', encoding='utf8'): # self.response_body+=[string.encode(encoding)] self.opdsWrapper.add_response_body(string,encoding) def add_response_binary(self, data): # self.response_body+=[data] self.opdsWrapper.add_response_binary(data) def add_response_header(self,list): # self.response_headers+=list self.opdsWrapper.add_response_header(list) def set_response_status(self,status): # self.response_status=status self.opdsWrapper.set_response_status(status) def write_response_headers(self, encoding='utf8'): # sys.stdout.buffer.write(b'Status: '+self.response_status.encode(encoding)+ b'\n') # for header in self.response_headers: # (a,b)=header # sys.stdout.buffer.write(a.encode(encoding)+b': '+b.encode(encoding) + b'\n') # sys.stdout.buffer.write(b'\n') self.opdsWrapper.write_response_headers(encoding) def write_response(self): # for element in self.response_body: # sys.stdout.buffer.write(element + b'\n') self.opdsWrapper.write_response() def get_response_status(self): Loading @@ -187,127 +176,43 @@ class opdsClient(): if h_id==None: h_id=self.cfg.SITE_ID if h_title==None: h_title=self.cfg.SITE_TITLE if h_subtitle==None: h_subtitle='Simple OPDS Catalog by www.sopds.ru. Version '+sopdscfg.VERSION # self.add_response_header([('Content-Type','text/xml; charset='+charset)]) # self.add_response_body('<?xml version="1.0" encoding="'+charset+'"?>') # self.add_response_body('<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/terms/" xmlns:os="http://a9.com/-/spec/opensearch/1.1/" xmlns:opds="http://opds-spec.org/2010/catalog">') # self.add_response_body('<id>%s</id>'%h_id) # self.add_response_body('<title>%s</title>'%h_title) # self.add_response_body('<subtitle>%s</subtitle>'%h_subtitle) # self.add_response_body('<updated>'+time.strftime("%Y-%m-%dT%H:%M:%SZ")+'</updated>') # self.add_response_body('<icon>'+self.cfg.SITE_ICON+'</icon>') # self.add_response_body('<author><name>'+self.cfg.SITE_AUTOR+'</name><uri>'+self.cfg.SITE_URL+'</uri><email>'+self.cfg.SITE_EMAIL+'</email></author>') # self.add_response_body('<link type="application/atom+xml" rel="start" href="'+self.modulePath+'?id=00"/>') self.opdsWrapper.header(h_id,h_title,h_subtitle,time.strftime("%Y-%m-%dT%H:%M:%SZ")) def footer(self): # self.add_response_body('</feed>') self.opdsWrapper.footer() def main_menu(self): # if self.cfg.ALPHA: am='30' # else: am='' dbinfo=self.opdsdb.getdbinfo(self.cfg.DUBLICATES_SHOW,self.cfg.BOOK_SHELF,self.user) # self.add_response_body('<link href="'+self.modulePath+'?id=09" rel="search" type="application/opensearchdescription+xml" />') # self.add_response_body('<link href="'+self.modulePath+'?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />') # self.add_response_body('<entry>') # self.add_response_body('<title>По каталогам</title>') # self.add_response_body('<content type="text">Каталогов: %s, книг: %s.</content>'%(dbinfo[2][1],dbinfo[0][1])) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=01"/>') # self.add_response_body('<id>id:01</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По авторам</title>') # self.add_response_body('<content type="text">Авторов: %s.</content>'%dbinfo[1][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'02"/>') # self.add_response_body('<id>id:02</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По наименованию</title>') # self.add_response_body('<content type="text">Книг: %s.</content>'%dbinfo[0][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'03"/>') # self.add_response_body('<id>id:03</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По Жанрам</title>') # self.add_response_body('<content type="text">Жанров: %s.</content>'%dbinfo[3][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=04"/>') # self.add_response_body('<id>id:04</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>По Сериям</title>') # self.add_response_body('<content type="text">Серий: %s.</content>'%dbinfo[4][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'06"/>') # self.add_response_body('<id>id:06</id></entry>') # if self.cfg.NEW_PERIOD!=0: # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки за %s суток</title>'%self.cfg.NEW_PERIOD) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=05"/>') # self.add_response_body('<id>id:05</id></entry>') # if self.cfg.BOOK_SHELF and self.user!=None: # self.add_response_body('<entry>') # self.add_response_body('<title>Книжная полка для %s</title>'%self.user) # self.add_response_body('<content type="text">Книг: %s.</content>'%dbinfo[5][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=08"/>') # self.add_response_body('<id>id:08</id></entry>') self.opdsWrapper.main_menu(self.user,dbinfo) def new_menu(self): # if self.cfg.ALPHA: am='30' # else: am='' newinfo=self.opdsdb.getnewinfo(self.cfg.DUBLICATES_SHOW,self.cfg.NEW_PERIOD) # self.add_response_body('<entry>') # self.add_response_body('<title>Все новинки за %s суток</title>'%self.cfg.NEW_PERIOD) # self.add_response_body('<content type="text">Новых книг: %s.</content>'%newinfo[0][1]) # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'03&news=1"/>') # self.add_response_body('<id>id:03:news</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки по авторам</title>') # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'02&news=1"/>') # self.add_response_body('<id>id:02:news</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки по Жанрам</title>') # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=04&news=1"/>') # self.add_response_body('<id>id:04:news</id></entry>') # self.add_response_body('<entry>') # self.add_response_body('<title>Новинки по Сериям</title>') # self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id='+am+'06&news=1"/>') # self.add_response_body('<id>id:06:news</id></entry>') self.opdsWrapper.new_menu(newinfo) def authors_submenu(self,author_id): self.add_response_body('<entry>') self.add_response_body('<title>Книги по сериям</title>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=31'+str(author_id)+'"/>') self.add_response_body('<id>id:31:authors</id></entry>') self.add_response_body('<entry>') self.add_response_body('<title>Книги вне серий</title>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=34'+str(author_id)+'"/>') self.add_response_body('<id>id:32:authors</id></entry>') self.add_response_body('<entry>') self.add_response_body('<title>Книги по алфавиту</title>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="'+self.modulePath+'?id=33'+str(author_id)+'"/>') self.add_response_body('<id>id:33:authors</id></entry>') self.opdsWrapper.authors_submenu(author_id) def entry_start(self): self.add_response_body('<entry>') self.opdsWrapper.entry_start() def entry_head(self,e_title,e_date,e_id): self.add_response_body('<title>'+websym(e_title)+'</title>') if e_date!=None: self.add_response_body('<updated>'+e_date.strftime("%Y-%m-%dT%H:%M:%S")+'</updated>') self.add_response_body('<id>id:'+e_id+'</id>') self.opdsWrapper.entry_head(e_title,e_date,e_id) def entry_link_subsection(self,link_id): self.add_response_body('<link type="application/atom+xml" rel="alternate" href="'+self.modulePath+'?id='+link_id+self.nl+'"/>') self.add_response_body('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="'+self.modulePath+'?id='+link_id+self.nl+'"/>') self.opdsWrapper.entry_link_subsection(link_id,self.nl) def entry_link_book(self,link_id,format): str_id=str(link_id) self.add_response_body('<link type="application/'+format+'" rel="alternate" href="'+self.modulePath+'?id=91'+str_id+'"/>') if format.lower()=='fb2' and self.cfg.FB2TOEPUB: self.add_response_body('<link type="application/epub" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/epub+zip" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') if format.lower()=='fb2' and self.cfg.FB2TOMOBI: self.add_response_body('<link type="application/mobi" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/mobi+zip" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/'+format+'" href="'+self.modulePath+'?id=91'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.add_response_body('<link type="application/'+format+'+zip" href="'+self.modulePath+'?id=92'+str_id+'" rel="http://opds-spec.org/acquisition" />') # str_id=str(link_id) # self.add_response_body('<link type="application/'+format+'" rel="alternate" href="'+self.modulePath+'?id=91'+str_id+'"/>') # if format.lower()=='fb2' and self.cfg.FB2TOEPUB: # self.add_response_body('<link type="application/epub" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/epub+zip" href="'+self.modulePath+'?id=93'+str_id+'" rel="http://opds-spec.org/acquisition" />') # if format.lower()=='fb2' and self.cfg.FB2TOMOBI: # self.add_response_body('<link type="application/mobi" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/mobi+zip" href="'+self.modulePath+'?id=94'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/'+format+'" href="'+self.modulePath+'?id=91'+str_id+'" rel="http://opds-spec.org/acquisition" />') # self.add_response_body('<link type="application/'+format+'+zip" href="'+self.modulePath+'?id=92'+str_id+'" rel="http://opds-spec.org/acquisition" />') self.opdsWrapper.entry_link_book(link_id,format) def entry_authors(self,book_id,link_show=False): authors="" Loading Loading @@ -381,7 +286,7 @@ class opdsClient(): self.add_response_body('</content>') def entry_finish(self): self.add_response_body('</entry>') self.opdsWrapper.entry_finish() def page_control(self, page, link_id): if page>0: Loading
py/sopdswrap.py +83 −34 Original line number Diff line number Diff line import sopdscfg import datetime class opdsTemplate(): def __init__(self, modulepath, charset='utf-8'): Loading @@ -13,9 +14,11 @@ class opdsTemplate(): <updated>%%(updated)s</updated> <icon>%%(site_icon)s</icon> <author><name>%%(site_author)s</name><uri>%%(site_url)s</uri><email>%%(site_email)s</email></author> <link type="application/atom+xml" rel="start" href="%(modulepath)s?id=00"/>'''%{'charset':self.charset,'modulepath':self.modulepath} <link type="application/atom+xml" rel="start" href="%(modulepath)s?id=00"/> '''%{'charset':self.charset,'modulepath':self.modulepath} self.document_footer='''</feed>''' self.document_mainmenu_std='''<link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" /> self.document_mainmenu_std=''' <link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" /> <link href="%(modulepath)s?searchTerm={searchTerms}" rel="search" type="application/atom+xml" /> <entry> <title>По каталогам</title> Loading @@ -41,17 +44,23 @@ class opdsTemplate(): <title>По Сериям</title> <content type="text">Серий: %%(series_num)s.</content> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s06"/> <id>id:06</id></entry>'''%{'modulepath':self.modulepath} self.document_mainmenu_new='''<entry> <id>id:06</id></entry> '''%{'modulepath':self.modulepath} self.document_mainmenu_new=''' <entry> <title>Новинки за %%(new_period)s суток</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=05"/> <id>id:05</id></entry>'''%{'modulepath':self.modulepath} self.document_mainmenu_shelf='''<entry> <id>id:05</id></entry> '''%{'modulepath':self.modulepath} self.document_mainmenu_shelf=''' <entry> <title>Книжная полка для %%(user)s</title> <content type="text">Книг: %%(book_num)s.</content> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=08"/> <id>id:08</id></entry>'''%{'modulepath':self.modulepath} self.document_newmenu='''<entry> <id>id:08</id></entry> '''%{'modulepath':self.modulepath} self.document_newmenu=''' <entry> <title>Все новинки за %%(new_period)s суток</title> <content type="text">Новых книг: %%(newbook_num)s.</content> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s03&news=1"/> Loading @@ -67,7 +76,39 @@ class opdsTemplate(): <entry> <title>Новинки по Сериям</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s06&news=1"/> <id>id:06:news</id></entry>'''%{'modulepath':self.modulepath} <id>id:06:news</id></entry> '''%{'modulepath':self.modulepath} self.document_authors_submenu=''' <entry> <title>Книги по сериям</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=31%%(author_id)s"/> <id>id:31:authors</id></entry> <entry> <title>Книги вне серий</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=34%%(author_id)s"/> <id>id:32:authors</id></entry> <entry> <title>Книги по алфавиту</title> <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=33%%(author_id)s"/> <id>id:33:authors</id></entry> '''%{'modulepath':self.modulepath} self.document_entry_start='''<entry>''' self.document_entry_finish='''</entry>''' self.document_entry_head=''' <title>%(e_title)s</title> <updated>%(e_date)s</updated> <id>id:%(e_id)s</id> ''' self.document_entry_link_subsection=''' <link type="application/atom+xml" rel="alternate" href="%(modulepath)s?id=%%(link_id)s%%(nl)s"/> <link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="subsection" href="%(modulepath)s?id=%%(link_id)s%%(nl)s"/> '''%{'modulepath':self.modulepath} self.document_entry_link_book_alternate=''' <link type="application/%%(format)s" rel="alternate" href="%(modulepath)s?id=91%%(link_id)s"/> '''%{'modulepath':self.modulepath} self.document_entry_link_book=''' <link type="application/%%(format)s" href="%(modulepath)s?id=%%(id)s%%(link_id)s" rel="http://opds-spec.org/acquisition" /> '''%{'modulepath':self.modulepath} Loading Loading @@ -134,19 +175,27 @@ class baseWrapper(): self.add_response_body(self.template.document_newmenu%{'new_period':self.cfg.NEW_PERIOD,'newbook_num':NEWINFO[0][1],'alphabet_id':am}) def authors_submenu(self,author_id): pass self.add_response_body(self.template.document_authors_submenu%{'author_id':author_id}) def entry_start(self): pass self.add_response_body(self.template.document_entry_start) def entry_head(self,e_title,e_date,e_id): pass def entry_link_subsection(self,link_id,modulePath): pass def entry_link_book(self,link_id,format,modulePath): pass if e_date==None: e_date=datetime.datetime(2001,9,9,0,0,0) self.add_response_body(self.template.document_entry_head%{'e_title':e_title,'e_date':e_date.strftime("%Y-%m-%dT%H:%M:%S"),'e_id':e_id}) def entry_link_subsection(self,link_id,nl): self.add_response_body(self.template.document_entry_link_subsection%{'link_id':link_id,'nl':nl}) def entry_link_book(self,link_id,format): self.add_response_body(self.template.document_entry_link_book_alternate%{'format':format,'link_id':link_id}) if format.lower()=='fb2' and self.cfg.FB2TOEPUB: self.add_response_body(self.template.document_entry_link_book%{'id':93,'format':'epub','link_id':link_id}) if format.lower()=='fb2' and self.cfg.FB2TOMOBI: self.add_response_body(self.template.document_entry_link_book%{'id':94,'format':'mobi','link_id':link_id}) self.add_response_body(self.template.document_entry_link_book%{'id':91,'format':format,'link_id':link_id}) self.add_response_body(self.template.document_entry_link_book%{'id':92,'format':format+'.zip','link_id':link_id}) def entry_authors(self,book_id,tupleAITHORS,link_show=False): authors='' Loading @@ -173,7 +222,7 @@ class baseWrapper(): pass def entry_finish(self): pass self.add_response_body(self.template.document_entry_finish) def page_control(self, page, link_id, modulePath): pass Loading