Example #1
0
	def __init__(self, book, bytes_range = None):
		status = 200 if bytes_range is None else 206 # 'OK' or 'Partial Content'
		DummyResponse.__init__(self, status, self._HEADERS)
		self.book = book
		self.length = book.file_size

		if bytes_range is None:
			self.range_begin = 0
			self.range_end = self.length - 1
			self.range_length = self.length
			self.headers['Content-Length'] = self.length
		else:
			self.range_begin = bytes_range[0]
			self.range_end = bytes_range[1]
			self.range_length = bytes_range[2]
			self.headers['Content-Range'] = 'bytes=%d-%d/%d' % ( self.range_begin, self.range_end, self.length )
			self.headers['Content-Length'] = self.range_length

		self.headers['Content-Disposition'] = 'attachment; filename="%s"' % os.path.basename(book.file_path)
		self.headers['Content-Type'] = book.content_type

		if book.cde_content_type == 'EBOK':
			# Kindles do not support annotations for PDOCs
			if annotations.has(book.asin):
				self.headers['Hint-Sidecar-Download'] = 1
			if annotations.apnx_path(book):
				self.headers['Hint-APNX-Available'] = 1
Example #2
0
	def __init__(self, book, bytes_range = None):
		status = 200 if bytes_range is None else 206 # 'OK' or 'Partial Content'
		DummyResponse.__init__(self, status, _HEADERS)
		self.book = book
		self.length = book.file_size

		if bytes_range is None:
			self.range_begin = 0
			self.range_end = self.length - 1
			self.range_length = self.length
			self.headers['Content-Length'] = self.length
		else:
			self.range_begin = bytes_range[0]
			self.range_end = bytes_range[1]
			self.range_length = bytes_range[2]
			self.headers['Content-Range'] = 'bytes=%d-%d/%d' % ( self.range_begin, self.range_end, self.length )
			self.headers['Content-Length'] = self.range_length

		self.headers['Content-Disposition'] = 'attachment; filename="%s"' % os.path.basename(book.file_path)
		self.headers['Content-Type'] = book.content_type

		if book.cde_content_type == 'EBOK':
			# annotations are only supported for MOBI books
			if annotations.has(book.asin):
				self.headers['Hint-Sidecar-Download'] = 1
			if annotations.apnx_path(book):
				self.headers['Hint-APNX-Available'] = 1
Example #3
0
 def call(self, request, device):
     q = request.get_query_params()
     asin = q.get('key')
     if q.get('type') == 'EBOK' and is_uuid(asin, 'EBOK'):
         book = calibre.book(asin)
         apnx_path = annotations.apnx_path(book)
         # logging.debug("looking for apnx of %s, found %s", book, apnx_path)
         if apnx_path:
             # APNX files are usually small (a few Ks at most),
             # so there's no need to do stream copying
             apnx_data = None
             with open(apnx_path, 'rb') as apnx:
                 apnx_data = apnx.read()
             if apnx_data:
                 return DummyResponse(headers=_HEADERS, data=apnx_data)