Merge pull request #288 from gudata/master
fix images url and remove trailing spaces
This commit is contained in:
commit
e016ad340b
2 changed files with 27 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -11,3 +11,4 @@ Books/
|
||||||
cookies.json
|
cookies.json
|
||||||
*.log
|
*.log
|
||||||
*.txt
|
*.txt
|
||||||
|
*.code-workspace
|
||||||
|
|
|
||||||
|
|
@ -138,20 +138,20 @@ class Display:
|
||||||
|
|
||||||
def intro(self):
|
def intro(self):
|
||||||
output = self.SH_YELLOW + ("""
|
output = self.SH_YELLOW + ("""
|
||||||
____ ___ _
|
____ ___ _
|
||||||
/ __/__ _/ _/__ _____(_)
|
/ __/__ _/ _/__ _____(_)
|
||||||
_\ \/ _ `/ _/ _ `/ __/ /
|
_\ \/ _ `/ _/ _ `/ __/ /
|
||||||
/___/\_,_/_/ \_,_/_/ /_/
|
/___/\_,_/_/ \_,_/_/ /_/
|
||||||
/ _ )___ ___ / /__ ___
|
/ _ )___ ___ / /__ ___
|
||||||
/ _ / _ \/ _ \/ '_/(_-<
|
/ _ / _ \/ _ \/ '_/(_-<
|
||||||
/____/\___/\___/_/\_\/___/
|
/____/\___/\___/_/\_\/___/
|
||||||
""" if random() > 0.5 else """
|
""" if random() > 0.5 else """
|
||||||
██████╗ ██████╗ ██╗ ██╗ ██╗██████╗
|
██████╗ ██████╗ ██╗ ██╗ ██╗██████╗
|
||||||
██╔═══██╗ ██╔══██╗██║ ╚██╗ ██╔╝╚════██╗
|
██╔═══██╗ ██╔══██╗██║ ╚██╗ ██╔╝╚════██╗
|
||||||
██║ ██║ ██████╔╝██║ ╚████╔╝ ▄███╔╝
|
██║ ██║ ██████╔╝██║ ╚████╔╝ ▄███╔╝
|
||||||
██║ ██║ ██╔══██╗██║ ╚██╔╝ ▀▀══╝
|
██║ ██║ ██╔══██╗██║ ╚██╔╝ ▀▀══╝
|
||||||
╚██████╔╝ ██║ ██║███████╗██║ ██╗
|
╚██████╔╝ ██║ ██║███████╗██║ ██╗
|
||||||
╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
||||||
""") + self.SH_DEFAULT
|
""") + self.SH_DEFAULT
|
||||||
output += "\n" + "~" * (self.columns // 2)
|
output += "\n" + "~" * (self.columns // 2)
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ class Display:
|
||||||
def parse_description(self, desc):
|
def parse_description(self, desc):
|
||||||
if not desc:
|
if not desc:
|
||||||
return "n/d"
|
return "n/d"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return html.fromstring(desc).text_content()
|
return html.fromstring(desc).text_content()
|
||||||
|
|
||||||
|
|
@ -540,7 +540,7 @@ class SafariBooks:
|
||||||
|
|
||||||
if "last_chapter_read" in response:
|
if "last_chapter_read" in response:
|
||||||
del response["last_chapter_read"]
|
del response["last_chapter_read"]
|
||||||
|
|
||||||
for key, value in response.items():
|
for key, value in response.items():
|
||||||
if value is None:
|
if value is None:
|
||||||
response[key] = 'n/a'
|
response[key] = 'n/a'
|
||||||
|
|
@ -812,10 +812,19 @@ class SafariBooks:
|
||||||
self.chapter_title = next_chapter["title"]
|
self.chapter_title = next_chapter["title"]
|
||||||
self.filename = next_chapter["filename"]
|
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"]):
|
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
|
# Stylesheets
|
||||||
self.chapter_stylesheets = []
|
self.chapter_stylesheets = []
|
||||||
|
|
@ -863,6 +872,7 @@ class SafariBooks:
|
||||||
self.css_done_queue.put(1)
|
self.css_done_queue.put(1)
|
||||||
self.display.state(len(self.css), self.css_done_queue.qsize())
|
self.display.state(len(self.css), self.css_done_queue.qsize())
|
||||||
|
|
||||||
|
|
||||||
def _thread_download_images(self, url):
|
def _thread_download_images(self, url):
|
||||||
image_name = url.split("/")[-1]
|
image_name = url.split("/")[-1]
|
||||||
image_path = os.path.join(self.images_path, image_name)
|
image_path = os.path.join(self.images_path, image_name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue