From c25e4c9fd6b6451577297f4e65127948891500c4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 07:52:58 +0530 Subject: [PATCH 1/7] Fix regression in 0.8.41 that caused file:/// URLs to stop working in the news download system on windows. Fixes #955581 (Calibre now requires improper file url for local files) --- src/calibre/web/fetch/simple.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/web/fetch/simple.py b/src/calibre/web/fetch/simple.py index 9993d9a3db..03ce64a750 100644 --- a/src/calibre/web/fetch/simple.py +++ b/src/calibre/web/fetch/simple.py @@ -14,7 +14,7 @@ from PIL import Image from cStringIO import StringIO from calibre import browser, relpath, unicode_path -from calibre.constants import filesystem_encoding +from calibre.constants import filesystem_encoding, iswindows from calibre.utils.filenames import ascii_filename from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag from calibre.ebooks.chardet import xml_to_unicode @@ -213,6 +213,8 @@ class RecursiveFetcher(object): is_local = 5 if is_local > 0: url = url[is_local:] + if iswindows and url.startswith('/'): + url = url[1:] with open(url, 'rb') as f: data = response(f.read()) data.newurl = 'file:'+url # This is what mechanize does for From 7873048dbf36af7de0e7a51cae1d6541f082f72a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 07:56:04 +0530 Subject: [PATCH 2/7] Update Microwaves and RF --- recipes/microwave_and_rf.recipe | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/recipes/microwave_and_rf.recipe b/recipes/microwave_and_rf.recipe index e3eee9dab1..3cdf6e5acc 100644 --- a/recipes/microwave_and_rf.recipe +++ b/recipes/microwave_and_rf.recipe @@ -15,7 +15,7 @@ import re from calibre.web.feeds.news import BasicNewsRecipe from calibre.utils.magick import Image -class Microwave_and_RF(BasicNewsRecipe): +class Microwaves_and_RF(BasicNewsRecipe): Convert_Grayscale = False # Convert images to gray scale or not @@ -25,9 +25,9 @@ class Microwave_and_RF(BasicNewsRecipe): # Add sections that want to be included from the magazine include_sections = [] - title = u'Microwave and RF' - __author__ = 'kiavash' - description = u'Microwave and RF Montly Magazine' + title = u'Microwaves and RF' + __author__ = u'kiavash' + description = u'Microwaves and RF Montly Magazine' publisher = 'Penton Media, Inc.' publication_type = 'magazine' site = 'http://mwrf.com' @@ -96,9 +96,16 @@ class Microwave_and_RF(BasicNewsRecipe): def parse_index(self): - # Fetches the main page of Microwave and RF + # Fetches the main page of Microwaves and RF soup = self.index_to_soup(self.site) + # First page has the ad, Let's find the redirect address. + url = soup.find('span', attrs={'class':'commonCopy'}).find('a').get('href') + if url.startswith('/'): + url = self.site + url + + soup = self.index_to_soup(url) + # Searches the site for Issue ID link then returns the href address # pointing to the latest issue latest_issue = soup.find('a', attrs={'href':lambda x: x and 'IssueID' in x}).get('href') From 7cc30dada325bb8930bb4194e9d09b9742837ae5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 08:58:13 +0530 Subject: [PATCH 3/7] KF8 Input: Recognize OpenType embedded fonts as well. Fixes #954728 (Private bug) --- src/calibre/ebooks/mobi/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/mobi/utils.py b/src/calibre/ebooks/mobi/utils.py index feca894a66..108c79b5fd 100644 --- a/src/calibre/ebooks/mobi/utils.py +++ b/src/calibre/ebooks/mobi/utils.py @@ -477,8 +477,9 @@ def read_font_record(data, extent=1040): # {{{ return ans ans['font_data'] = font_data - ans['ext'] = ('ttf' if font_data[:4] in {b'\0\1\0\0', b'true', b'ttcf'} - else 'dat') + sig = font_data[:4] + ans['ext'] = ('ttf' if sig in {b'\0\1\0\0', b'true', b'ttcf'} + else 'otf' if sig == b'OTTO' else 'dat') return ans # }}} From 653826f58a657f6920a5dd037879ae79b199a3fa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 09:39:16 +0530 Subject: [PATCH 4/7] Fix #955688 (Android device not detected) --- src/calibre/devices/android/driver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/android/driver.py b/src/calibre/devices/android/driver.py index 0062137247..6ef1e528fe 100644 --- a/src/calibre/devices/android/driver.py +++ b/src/calibre/devices/android/driver.py @@ -81,7 +81,7 @@ class ANDROID(USBMS): 0x4e11 : [0x0100, 0x226, 0x227], 0x4e12 : [0x0100, 0x226, 0x227], 0x4e21 : [0x0100, 0x226, 0x227, 0x231], - 0x4e22 : [0x0100, 0x226, 0x227], + 0x4e22 : [0x0100, 0x226, 0x227, 0x231], 0xb058 : [0x0222, 0x226, 0x227], 0x0ff9 : [0x0226], 0xdddd : [0x216], @@ -194,7 +194,8 @@ class ANDROID(USBMS): '__UMS_COMPOSITE', 'SGH-I997_CARD', 'MB870', 'ALPANDIGITAL', 'ANDROID_MID', 'P990_SD_CARD', '.K080', 'LTE_CARD', 'MB853', 'A1-07___C0541A4F', 'XT912', 'MB855', 'XT910', 'BOOK_A10_CARD', - 'USB_2.0_DRIVER', 'I9100T', 'P999DW_SD_CARD', 'KTABLET_PC'] + 'USB_2.0_DRIVER', 'I9100T', 'P999DW_SD_CARD', 'KTABLET_PC', + 'FILE-CD_GADGET'] OSX_MAIN_MEM = 'Android Device Main Memory' From 56a540f5f4190a85bd04b13e11c3c40c2e20b843 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 10:01:55 +0530 Subject: [PATCH 5/7] ... --- src/calibre/ebooks/mobi/reader/headers.py | 3 ++ src/calibre/ebooks/mobi/reader/mobi6.py | 41 ++++++++++++----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/calibre/ebooks/mobi/reader/headers.py b/src/calibre/ebooks/mobi/reader/headers.py index 8cff1360de..f1cabffa8e 100644 --- a/src/calibre/ebooks/mobi/reader/headers.py +++ b/src/calibre/ebooks/mobi/reader/headers.py @@ -27,6 +27,7 @@ class EXTHHeader(object): # {{{ self.has_fake_cover = True self.start_offset = None left = self.num_items + self.kf8_header = None while left > 0: left -= 1 @@ -95,6 +96,8 @@ class EXTHHeader(object): # {{{ pass # ASIN or UUID elif id == 116: self.start_offset, = struct.unpack(b'>L', content) + elif id == 121: + self.kf8_header, = struct.unpack(b'>L', content) #else: # print 'unhandled metadata record', id, repr(content) # }}} diff --git a/src/calibre/ebooks/mobi/reader/mobi6.py b/src/calibre/ebooks/mobi/reader/mobi6.py index 896a9ebc2a..94675dc893 100644 --- a/src/calibre/ebooks/mobi/reader/mobi6.py +++ b/src/calibre/ebooks/mobi/reader/mobi6.py @@ -106,28 +106,29 @@ class MobiReader(object): self.name = self.name.decode(self.book_header.codec, 'replace') self.kf8_type = None is_kf8 = self.book_header.mobi_version == 8 + k8i = getattr(self.book_header.exth, 'kf8_header', None) + if is_kf8: self.kf8_type = 'standalone' - else: # Check for joint mobi 6 and kf 8 file - KF8_BOUNDARY = b'BOUNDARY' - for i, x in enumerate(self.sections[:-1]): - sec = x[0] - if (len(sec) == len(KF8_BOUNDARY) and sec == - KF8_BOUNDARY): - try: - self.book_header = BookHeader(self.sections[i+1][0], - self.ident, user_encoding, self.log) - # The following are only correct in the Mobi 6 - # header not the Mobi 8 header - for x in ('first_image_index',): - setattr(self.book_header, x, getattr(bh, x)) - if hasattr(self.book_header, 'huff_offset'): - self.book_header.huff_offset += i + 1 - self.kf8_type = 'joint' - self.kf8_boundary = i - except: - self.book_header = bh - break + elif k8i is not None: # Check for joint mobi 6 and kf 8 file + try: + raw = self.sections[k8i-1][0] + except: + raw = None + if raw == b'BOUNDARY': + try: + self.book_header = BookHeader(self.sections[k8i][0], + self.ident, user_encoding, self.log) + # The following are only correct in the Mobi 6 + # header not the Mobi 8 header + for x in ('first_image_index',): + setattr(self.book_header, x, getattr(bh, x)) + if hasattr(self.book_header, 'huff_offset'): + self.book_header.huff_offset += k8i + self.kf8_type = 'joint' + self.kf8_boundary = k8i-1 + except: + self.book_header = bh def check_for_drm(self): if self.book_header.encryption_type != 0: From d4f7ba445644d460f02fd34848656e4c807ae5a6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 11:02:47 +0530 Subject: [PATCH 6/7] ... --- src/calibre/ebooks/mobi/reader/mobi6.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/calibre/ebooks/mobi/reader/mobi6.py b/src/calibre/ebooks/mobi/reader/mobi6.py index 94675dc893..962c38a0ba 100644 --- a/src/calibre/ebooks/mobi/reader/mobi6.py +++ b/src/calibre/ebooks/mobi/reader/mobi6.py @@ -105,10 +105,9 @@ class MobiReader(object): user_encoding, self.log, try_extra_data_fix=try_extra_data_fix) self.name = self.name.decode(self.book_header.codec, 'replace') self.kf8_type = None - is_kf8 = self.book_header.mobi_version == 8 k8i = getattr(self.book_header.exth, 'kf8_header', None) - if is_kf8: + if self.book_header.mobi_version == 8: self.kf8_type = 'standalone' elif k8i is not None: # Check for joint mobi 6 and kf 8 file try: From b781ff54d09ed018507ad70172c15e377353a90d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2012 11:03:16 +0530 Subject: [PATCH 7/7] Fix #940680 (Error sending books to iTunes) --- src/calibre/ebooks/metadata/book/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 1b43b97b73..754bcbfa66 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -543,6 +543,7 @@ class Metadata(object): # Happens if x is not a text, is_multiple field # on self lstags = [] + self_tags = [] ot, st = map(frozenset, (lotags, lstags)) for t in st.intersection(ot): sidx = lstags.index(t)