mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Cleanup stanza server code
This commit is contained in:
parent
6fea6a8fa7
commit
c8d2b4468f
@ -105,7 +105,7 @@ class LibraryServer(object):
|
|||||||
<entry xmlns:py="http://genshi.edgewall.org/">
|
<entry xmlns:py="http://genshi.edgewall.org/">
|
||||||
<title>${authors}</title>
|
<title>${authors}</title>
|
||||||
<id>urn:calibre:${record[FM['id']]}</id>
|
<id>urn:calibre:${record[FM['id']]}</id>
|
||||||
<updated>${timestamp}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?authorid=${record[FM['id']]}" />
|
<link type="application/atom+xml" href="/stanza/?authorid=${record[FM['id']]}" />
|
||||||
</entry>
|
</entry>
|
||||||
'''))
|
'''))
|
||||||
@ -114,7 +114,7 @@ class LibraryServer(object):
|
|||||||
<entry xmlns:py="http://genshi.edgewall.org/">
|
<entry xmlns:py="http://genshi.edgewall.org/">
|
||||||
<title>${tags}</title>
|
<title>${tags}</title>
|
||||||
<id>urn:calibre:${record[FM['id']]}</id>
|
<id>urn:calibre:${record[FM['id']]}</id>
|
||||||
<updated>${timestamp}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?tagid=${record[FM['id']]}" />
|
<link type="application/atom+xml" href="/stanza/?tagid=${record[FM['id']]}" />
|
||||||
</entry>
|
</entry>
|
||||||
'''))
|
'''))
|
||||||
@ -123,7 +123,7 @@ class LibraryServer(object):
|
|||||||
<entry xmlns:py="http://genshi.edgewall.org/">
|
<entry xmlns:py="http://genshi.edgewall.org/">
|
||||||
<title>${series}</title>
|
<title>${series}</title>
|
||||||
<id>urn:calibre:${record[FM['id']]}</id>
|
<id>urn:calibre:${record[FM['id']]}</id>
|
||||||
<updated>${timestamp}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?seriesid=${record[FM['id']]}" />
|
<link type="application/atom+xml" href="/stanza/?seriesid=${record[FM['id']]}" />
|
||||||
</entry>
|
</entry>
|
||||||
'''))
|
'''))
|
||||||
@ -167,30 +167,35 @@ class LibraryServer(object):
|
|||||||
<id>urn:uuid:fc000fa0-8c23-11de-a31d-0002a5d5c51b</id>
|
<id>urn:uuid:fc000fa0-8c23-11de-a31d-0002a5d5c51b</id>
|
||||||
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?sortby=byauthor" />
|
<link type="application/atom+xml" href="/stanza/?sortby=byauthor" />
|
||||||
|
<content type="text">Books sorted by Author</content>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<title>By Title</title>
|
<title>By Title</title>
|
||||||
<id>urn:uuid:1df4fe40-8c24-11de-b4c6-0002a5d5c51b</id>
|
<id>urn:uuid:1df4fe40-8c24-11de-b4c6-0002a5d5c51b</id>
|
||||||
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?sortby=bytitle" />
|
<link type="application/atom+xml" href="/stanza/?sortby=bytitle" />
|
||||||
|
<content type="text">Books sorted by Title</content>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<title>By Newest</title>
|
<title>By Newest</title>
|
||||||
<id>urn:uuid:3c6d4940-8c24-11de-a4d7-0002a5d5c51b</id>
|
<id>urn:uuid:3c6d4940-8c24-11de-a4d7-0002a5d5c51b</id>
|
||||||
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?sortby=bynewest" />
|
<link type="application/atom+xml" href="/stanza/?sortby=bynewest" />
|
||||||
|
<content type="text">Books sorted by Date</content>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<title>By Tag</title>
|
<title>By Tag</title>
|
||||||
<id>urn:uuid:824921e8-db8a-4e61-7d38-f1ce41502853</id>
|
<id>urn:uuid:824921e8-db8a-4e61-7d38-f1ce41502853</id>
|
||||||
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?sortby=bytag" />
|
<link type="application/atom+xml" href="/stanza/?sortby=bytag" />
|
||||||
|
<content type="text">Books sorted by Tags</content>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<title>By Series</title>
|
<title>By Series</title>
|
||||||
<id>urn:uuid:512a5e50-a88f-f6b8-82aa-8f129c719f61</id>
|
<id>urn:uuid:512a5e50-a88f-f6b8-82aa-8f129c719f61</id>
|
||||||
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
<updated>${updated.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</updated>
|
||||||
<link type="application/atom+xml" href="/stanza/?sortby=byseries" />
|
<link type="application/atom+xml" href="/stanza/?sortby=byseries" />
|
||||||
|
<content type="text">Books sorted by Series</content>
|
||||||
</entry>
|
</entry>
|
||||||
</feed>
|
</feed>
|
||||||
'''))
|
'''))
|
||||||
@ -375,9 +380,11 @@ class LibraryServer(object):
|
|||||||
updated = self.db.last_modified()
|
updated = self.db.last_modified()
|
||||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
||||||
cherrypy.response.headers['Content-Type'] = 'text/xml'
|
cherrypy.response.headers['Content-Type'] = 'text/xml'
|
||||||
|
# Main feed
|
||||||
if not sortby and not search and not authorid and not tagid and not seriesid:
|
if not sortby and not search and not authorid and not tagid and not seriesid:
|
||||||
return self.STANZA_MAIN.generate(subtitle='', data=books, FM=FIELD_MAP,
|
return self.STANZA_MAIN.generate(subtitle='', data=books, FM=FIELD_MAP,
|
||||||
updated=updated, id='urn:calibre:main').render('xml')
|
updated=updated, id='urn:calibre:main').render('xml')
|
||||||
|
# Sub-feed
|
||||||
if authorid:
|
if authorid:
|
||||||
authorid=int(authorid)
|
authorid=int(authorid)
|
||||||
au = self.db.authors(authorid, index_is_id=True)
|
au = self.db.authors(authorid, index_is_id=True)
|
||||||
@ -393,6 +400,8 @@ class LibraryServer(object):
|
|||||||
else:
|
else:
|
||||||
ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set()
|
ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set()
|
||||||
record_list = list(iter(self.db))
|
record_list = list(iter(self.db))
|
||||||
|
|
||||||
|
# Sort the record list
|
||||||
if sortby == "byauthor":
|
if sortby == "byauthor":
|
||||||
record_list.sort(lambda x, y: cmp(x[FIELD_MAP['author_sort']], y[FIELD_MAP['author_sort']]))
|
record_list.sort(lambda x, y: cmp(x[FIELD_MAP['author_sort']], y[FIELD_MAP['author_sort']]))
|
||||||
elif sortby == "bytag":
|
elif sortby == "bytag":
|
||||||
@ -406,6 +415,8 @@ class LibraryServer(object):
|
|||||||
record_list.sort(lambda x, y: cmp(x[FIELD_MAP['series_index']], y[FIELD_MAP['series_index']]))
|
record_list.sort(lambda x, y: cmp(x[FIELD_MAP['series_index']], y[FIELD_MAP['series_index']]))
|
||||||
else:
|
else:
|
||||||
record_list = reversed(record_list)
|
record_list = reversed(record_list)
|
||||||
|
|
||||||
|
|
||||||
author_list=[]
|
author_list=[]
|
||||||
tag_list=[]
|
tag_list=[]
|
||||||
series_list=[]
|
series_list=[]
|
||||||
@ -413,12 +424,16 @@ class LibraryServer(object):
|
|||||||
if record[0] not in ids: continue
|
if record[0] not in ids: continue
|
||||||
r = record[FIELD_MAP['formats']]
|
r = record[FIELD_MAP['formats']]
|
||||||
r = r.upper() if r else ''
|
r = r.upper() if r else ''
|
||||||
if 'EPUB' in r or 'PDB' in r:
|
if not ('EPUB' in r or 'PDB' in r):
|
||||||
|
continue
|
||||||
|
|
||||||
z = record[FIELD_MAP['authors']]
|
z = record[FIELD_MAP['authors']]
|
||||||
if not z:
|
if not z:
|
||||||
z = _('Unknown')
|
z = _('Unknown')
|
||||||
authors = ' & '.join([i.replace('|', ',') for i in
|
authors = ' & '.join([i.replace('|', ',') for i in
|
||||||
z.split(',')])
|
z.split(',')])
|
||||||
|
|
||||||
|
# Setup extra description
|
||||||
extra = []
|
extra = []
|
||||||
rating = record[FIELD_MAP['rating']]
|
rating = record[FIELD_MAP['rating']]
|
||||||
if rating > 0:
|
if rating > 0:
|
||||||
@ -433,54 +448,45 @@ class LibraryServer(object):
|
|||||||
extra.append('SERIES: %s [%s]<br />'%\
|
extra.append('SERIES: %s [%s]<br />'%\
|
||||||
(prepare_string_for_xml(series),
|
(prepare_string_for_xml(series),
|
||||||
fmt_sidx(float(record[FIELD_MAP['series_index']]))))
|
fmt_sidx(float(record[FIELD_MAP['series_index']]))))
|
||||||
|
|
||||||
fmt = 'epub' if 'EPUB' in r else 'pdb'
|
fmt = 'epub' if 'EPUB' in r else 'pdb'
|
||||||
mimetype = guess_type('dummy.'+fmt)[0]
|
mimetype = guess_type('dummy.'+fmt)[0]
|
||||||
|
|
||||||
|
# Create the sub-catalog, which is either a list of
|
||||||
|
# authors/tags/series or a list of books
|
||||||
|
data = dict(
|
||||||
|
record=record,
|
||||||
|
updated=updated,
|
||||||
|
authors=authors,
|
||||||
|
tags=tags,
|
||||||
|
series=series,
|
||||||
|
FM=FIELD_MAP
|
||||||
|
)
|
||||||
if sortby == "byauthor":
|
if sortby == "byauthor":
|
||||||
if authors and authors not in author_list:
|
if authors and authors not in author_list:
|
||||||
author_list.append(authors)
|
author_list.append(authors)
|
||||||
books.append(self.STANZA_AUTHOR_ENTRY.generate(
|
books.append(self.STANZA_AUTHOR_ENTRY.generate(**data)\
|
||||||
authors=authors,
|
.render('xml').decode('utf8'))
|
||||||
record=record, FM=FIELD_MAP,
|
|
||||||
port=self.opts.port,
|
|
||||||
extra=''.join(extra),
|
|
||||||
mimetype=mimetype,
|
|
||||||
fmt=fmt,
|
|
||||||
timestamp=strftime('%Y-%m-%dT%H:%M:%S+00:00', record[5]),
|
|
||||||
).render('xml').decode('utf8'))
|
|
||||||
elif sortby == "bytag":
|
elif sortby == "bytag":
|
||||||
if tags and tags not in tag_list:
|
if tags and tags not in tag_list:
|
||||||
tag_list.append(tags)
|
tag_list.append(tags)
|
||||||
books.append(self.STANZA_TAG_ENTRY.generate(
|
books.append(self.STANZA_TAG_ENTRY.generate(**data)\
|
||||||
tags=tags,
|
.render('xml').decode('utf8'))
|
||||||
record=record, FM=FIELD_MAP,
|
|
||||||
port=self.opts.port,
|
|
||||||
extra=''.join(extra),
|
|
||||||
mimetype=mimetype,
|
|
||||||
fmt=fmt,
|
|
||||||
timestamp=strftime('%Y-%m-%dT%H:%M:%S+00:00', record[5]),
|
|
||||||
).render('xml').decode('utf8'))
|
|
||||||
elif sortby == "byseries":
|
elif sortby == "byseries":
|
||||||
if series and series not in series_list:
|
if series and series not in series_list:
|
||||||
series_list.append(series)
|
series_list.append(series)
|
||||||
books.append(self.STANZA_SERIES_ENTRY.generate(
|
books.append(self.STANZA_SERIES_ENTRY.generate(**data)\
|
||||||
series=series,
|
.render('xml').decode('utf8'))
|
||||||
record=record, FM=FIELD_MAP,
|
|
||||||
port=self.opts.port,
|
else: # An actual book list
|
||||||
extra=''.join(extra),
|
data['extra'] = ''.join(extra)
|
||||||
mimetype=mimetype,
|
data['mimetype'] = mimetype
|
||||||
fmt=fmt,
|
data['fmt'] = fmt
|
||||||
timestamp=strftime('%Y-%m-%dT%H:%M:%S+00:00', record[5]),
|
data['timestamp'] = strftime('%Y-%m-%dT%H:%M:%S+00:00', record[5])
|
||||||
).render('xml').decode('utf8'))
|
books.append(self.STANZA_ENTRY.generate(**data)\
|
||||||
else:
|
.render('xml').decode('utf8'))
|
||||||
books.append(self.STANZA_ENTRY.generate(
|
|
||||||
authors=authors,
|
|
||||||
record=record, FM=FIELD_MAP,
|
|
||||||
port=self.opts.port,
|
|
||||||
extra=''.join(extra),
|
|
||||||
mimetype=mimetype,
|
|
||||||
fmt=fmt,
|
|
||||||
timestamp=strftime('%Y-%m-%dT%H:%M:%S+00:00', record[5]),
|
|
||||||
).render('xml').decode('utf8'))
|
|
||||||
|
|
||||||
return self.STANZA.generate(subtitle='', data=books, FM=FIELD_MAP,
|
return self.STANZA.generate(subtitle='', data=books, FM=FIELD_MAP,
|
||||||
updated=updated, id='urn:calibre:main').render('xml')
|
updated=updated, id='urn:calibre:main').render('xml')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user