diff --git a/audiobookdl/output/download.py b/audiobookdl/output/download.py index bb84042..d5a5f99 100644 --- a/audiobookdl/output/download.py +++ b/audiobookdl/output/download.py @@ -71,16 +71,16 @@ def add_metadata_to_file(audiobook: Audiobook, filepath: str, options): :param filepath: Filepath of output file :options: Cli options """ - # Chapters - if audiobook.chapters and not options.no_chapters: - logging.book_update("Adding chapters") - metadata.add_chapters(filepath, audiobook.chapters) # General metadata logging.book_update("Adding metadata") metadata.add_metadata(filepath, audiobook.metadata) if options.write_json_metadata: with open(f"{filepath}.json", "w") as f: f.write(audiobook.metadata.as_json()) + # Chapters + if audiobook.chapters and not options.no_chapters: + logging.book_update("Adding chapters") + metadata.add_chapters(filepath, audiobook.chapters) # Cover if audiobook.cover: logging.book_update("Embedding cover") diff --git a/audiobookdl/sources/nextory.py b/audiobookdl/sources/nextory.py index 18dfbc3..a1b1b4b 100644 --- a/audiobookdl/sources/nextory.py +++ b/audiobookdl/sources/nextory.py @@ -44,7 +44,7 @@ def _login(self, url: str, username: str, password: str): { # New version headers "X-Application-Id": self.APP_ID, - "X-App-Version": "5.0.0", + "X-App-Version": "5.4.1", "X-Locale": self.LOCALE, "X-Model": "Personal Computer", "X-Device-Id": device_id, @@ -59,6 +59,7 @@ def _login(self, url: str, username: str, password: str): }, ) session_response = session_response.json() + logging.debug(f"{session_response=}") login_token = session_response["login_token"] country = session_response["country"] self._session.headers.update( @@ -88,7 +89,7 @@ def _login(self, url: str, username: str, password: str): def download(self, url) -> Audiobook: - book_id = int(url.split("-")[-1].replace("/", "")) + book_id = int(url.split("/")[-1].split("-")[-1]) want_to_read_list = self.download_want_to_read_list() book_info = self.find_book_info(book_id, want_to_read_list) audio_data = self.download_audio_data(book_info) diff --git a/audiobookdl/sources/yourcloudlibrary.py b/audiobookdl/sources/yourcloudlibrary.py index 326083e..fd95e15 100644 --- a/audiobookdl/sources/yourcloudlibrary.py +++ b/audiobookdl/sources/yourcloudlibrary.py @@ -5,11 +5,12 @@ import requests.utils import base64 from typing import List +import re class YourCloudLibrarySource(Source): match = [ - # r"https?://ebook.yourcloudlibrary.com/library/[^/]+/AudioPlayer/.+" - r"https?://audio.yourcloudlibrary.com/listen/.+" + r"https?://audio.yourcloudlibrary.com/listen/.+", + r"https://ebook.yourcloudlibrary.com/library/[^/]+/detail/.+", ] names = [ "YourCloudLibrary" ] login_data = [ "username", "password", "library" ] @@ -17,9 +18,9 @@ class YourCloudLibrarySource(Source): "cookies", "login" ] - _library: str def download(self, url: str) -> Audiobook: + url = self.get_listening_url(url) account_id = self.extract_json_string(url, "accountId") logging.debug(f"{account_id=}") fulfillment_id = self.extract_json_string(url, "fulfillmentId") @@ -39,6 +40,19 @@ def download(self, url: str) -> Audiobook: ) + @staticmethod + def get_listening_url(url: str) -> str: + """ + Get url for listening page + + :param url: Url to information or listening page + :return: Url to listening page + """ + if re.match(YourCloudLibrarySource.match[0], url): + return url + book_id = url.split("/")[-1] + return f"https://audio.yourcloudlibrary.com/listen/{book_id}" + def extract_json_string(self, url: str, key: str) -> str: """ Extracts string from json in web page @@ -123,12 +137,13 @@ def download_playlist(self, fulfillment_id: str, license_id: str) -> dict: def _login(self, url: str, username: str, password: str, library: str): # type: ignore - self.library = library + self.get(f"https://ebook.yourcloudlibrary.com/library/{library}/featured") resp = self.post( - f"https://ebook.yourcloudlibrary.com/library/{library}/?_data=root", + "https://ebook.yourcloudlibrary.com/?_data=root", data = { "action": "login", "barcode": username, - "pin": password + "pin": password, + "library": library } )