Skip to content

Commit

Permalink
FIX-IMAGE make it work with api v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gudata committed Sep 27, 2021
1 parent 10b400a commit 2260ffc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Books/
cookies.json
*.log
*.txt
*.code-workspace
15 changes: 12 additions & 3 deletions safaribooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 2260ffc

Please sign in to comment.