diff --git a/CloudStorage.py b/CloudStorage.py index 375b48e..3033dde 100644 --- a/CloudStorage.py +++ b/CloudStorage.py @@ -301,6 +301,11 @@ class EbookMetaData (object): # test filename return urllib.parse.urljoin ( protocol + str(cherrypy.config['file_host']) , 'test.pdf') - return urllib.parse.urljoin ( - protocol + cherrypy.config['file_host'], - 'ebooks/%d.%s' % (self.id, self.filetype)) + if self.filetype == 'pdf': + return urllib.parse.urljoin ( + protocol + cherrypy.config['file_host'], + 'files/%d/%d-pdf.pdf' % (self.id, self.id)) + else: + return urllib.parse.urljoin ( + protocol + cherrypy.config['file_host'], + 'ebooks/%d.%s' % (self.id, self.filetype)) diff --git a/HTMLFormatter.py b/HTMLFormatter.py index 53889cb..cbb8ab4 100644 --- a/HTMLFormatter.py +++ b/HTMLFormatter.py @@ -18,6 +18,7 @@ import operator import cherrypy import genshi.output +import re import six from six.moves import urllib @@ -37,6 +38,7 @@ HANDOVER_TYPES = (mt.epub, mt.plucker, mt.mobi, mt.pdf, mt.qioo) # self-contained files we can send to dropbox CLOUD_TYPES = (mt.epub, mt.mobi, mt.pdf) +STD_PDF_MATCH = re.compile (r'files/\d+/\d+-pdf.pdf$') class XMLishFormatter (BaseFormatter.BaseFormatter): """ Produce XMLish output. """ @@ -47,6 +49,10 @@ class XMLishFormatter (BaseFormatter.BaseFormatter): def fix_dc (self, dc, os): """ Tweak dc. """ + def has_std_path (file_obj): + if file_obj.filetype == 'pdf': + return STD_PDF_MATCH.search (file_obj.url) + return True super (XMLishFormatter, self).fix_dc (dc, os) @@ -58,7 +64,7 @@ class XMLishFormatter (BaseFormatter.BaseFormatter): for file_ in dc.files + dc.generated_files: type_ = six.text_type (file_.mediatypes[0]) m = type_.partition (';')[0] - if m in CLOUD_TYPES: + if m in CLOUD_TYPES and has_std_path (file_): file_.dropbox_url = os.url ( 'dropbox_send', id = dc.project_gutenberg_id, filetype = file_.filetype) file_.gdrive_url = os.url (