Skip to content

Commit

Permalink
Merge pull request lorenzodifuccia#288 from gudata/master
Browse files Browse the repository at this point in the history
fix images url and remove trailing spaces
  • Loading branch information
lorenzodifuccia committed Oct 25, 2021
2 parents af02912 + 9445253 commit e016ad3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 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
42 changes: 26 additions & 16 deletions safaribooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ def save_last_request(self):

def intro(self):
output = self.SH_YELLOW + ("""
____ ___ _
/ __/__ _/ _/__ _____(_)
_\ \/ _ `/ _/ _ `/ __/ /
/___/\_,_/_/ \_,_/_/ /_/
/ _ )___ ___ / /__ ___
/ _ / _ \/ _ \/ '_/(_-<
/____/\___/\___/_/\_\/___/
____ ___ _
/ __/__ _/ _/__ _____(_)
_\ \/ _ `/ _/ _ `/ __/ /
/___/\_,_/_/ \_,_/_/ /_/
/ _ )___ ___ / /__ ___
/ _ / _ \/ _ \/ '_/(_-<
/____/\___/\___/_/\_\/___/
""" if random() > 0.5 else """
██████╗ ██████╗ ██╗ ██╗ ██╗██████╗
██████╗ ██████╗ ██╗ ██╗ ██╗██████╗
██╔═══██╗ ██╔══██╗██║ ╚██╗ ██╔╝╚════██╗
██║ ██║ ██████╔╝██║ ╚████╔╝ ▄███╔╝
██║ ██║ ██╔══██╗██║ ╚██╔╝ ▀▀══╝
╚██████╔╝ ██║ ██║███████╗██║ ██╗
╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
██║ ██║ ██╔══██╗██║ ╚██╔╝ ▀▀══╝
╚██████╔╝ ██║ ██║███████╗██║ ██╗
╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
""") + self.SH_DEFAULT
output += "\n" + "~" * (self.columns // 2)

Expand All @@ -160,7 +160,7 @@ def intro(self):
def parse_description(self, desc):
if not desc:
return "n/d"

try:
return html.fromstring(desc).text_content()

Expand Down Expand Up @@ -540,7 +540,7 @@ def get_book_info(self):

if "last_chapter_read" in response:
del response["last_chapter_read"]

for key, value in response.items():
if value is None:
response[key] = 'n/a'
Expand Down 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['asset_base_url'], img_url)
for img_url in next_chapter['images'])
for img_url in next_chapter['images']:
if api_v2_detected:
self.images.append(asset_base_url + '/' + img_url)
else:
self.images.append(urljoin(next_chapter['asset_base_url'], img_url))


# Stylesheets
self.chapter_stylesheets = []
Expand Down Expand Up @@ -863,6 +872,7 @@ def _thread_download_css(self, url):
self.css_done_queue.put(1)
self.display.state(len(self.css), self.css_done_queue.qsize())


def _thread_download_images(self, url):
image_name = url.split("/")[-1]
image_path = os.path.join(self.images_path, image_name)
Expand Down

0 comments on commit e016ad3

Please sign in to comment.