diff --git a/.gitignore b/.gitignore index 539ad1a..a21a47d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Books/ cookies.json *.log *.txt +*.code-workspace diff --git a/safaribooks.py b/safaribooks.py index 9ef990f..81a14a9 100755 --- a/safaribooks.py +++ b/safaribooks.py @@ -812,10 +812,19 @@ def get(self): self.chapter_title = next_chapter["title"] self.filename = next_chapter["filename"] - # Images + asset_base_url = next_chapter['asset_base_url'] + api_v2_detected = False + if 'v2' in next_chapter['content']: + asset_base_url = SAFARI_BASE_URL + "/api/v2/epubs/urn:orm:book:{}/files".format(self.book_id) + api_v2_detected = True + if "images" in next_chapter and len(next_chapter["images"]): - self.images.extend(urljoin(next_chapter['content'], img_url) - for img_url in next_chapter['images']) + for img_url in next_chapter['images']: + if api_v2_detected: + self.images.extend([asset_base_url + '/' + img_url]) + else: + self.images.extend(urljoin(next_chapter['asset_base_url'], img_url) + # Stylesheets self.chapter_stylesheets = []