示例#1
0
 def _restore_from_session_file(self):
     # Try to restore session from file if possible
     try:
         auth = audible.FileAuthenticator(filename=self._session_file,
                                          locale=self._locale)
         self._client = audible.AudibleAPI(auth)
     except Exception as msg:
         msg = f"Can't log into Audible using session file ({self._session_file}): {msg}"
         raise Exception(msg)
示例#2
0
    def _create_with_credentials(self):
        if self._email and self._password:
            try:
                logging.info("Creating session using login/password credentials")
                auth = audible.LoginAuthenticator(
                    self._email, self._password, locale=self._locale
                )
            except Exception as msg:
                print(f"Can't log into Audible using credentials: {msg}", file=sys.stderr)
                raise
        else:
            raise Exception("Both email and password must be specified")

        # save session after initializing
        auth.to_file(self._session_file, encryption=False)
        self._client = audible.AudibleAPI(auth)
示例#3
0
async def main(auth):
    async with audible.AudibleAPI(auth, is_async=True) as client:
        print(repr(client))

        library, _ = await client.get(path="library",
                                      params={"num_results": 999})
        asins = [book["asin"] for book in library["items"]]

        # books = await asyncio.gather(*(dl_book(asin) for asin in asins))
        tasks = []
        for asin in asins:
            tasks.append(asyncio.ensure_future(get_book_infos(client, asin)))
        books = await asyncio.gather(*tasks)

        for book in books:
            if book is not None:
                print(book["item"])
                print("\n", 40 * "-", "\n")
示例#4
0
def download_file(url, filename):
    r = requests.get(url, stream=True)
    with open(filename, 'wb') as f:
        shutil.copyfileobj(r.raw, f)
    return filename


if __name__ == "__main__":
    password = input("Password for file: ")

    auth = audible.FileAuthenticator(
        filename="FILENAME",
        encryption="json",
        password=password
    )
    client = audible.AudibleAPI(auth)

    books, _ = client.get(
        path="library/books",
        api_version="0.0",
        params={
            "purchaseAfterDate": "01/01/1970"
        }
    )["books"]["book"]

    for book in books:
        asin = book['asin']
        title = book['title'] + f" ({asin})" + ".aaxc"
        dl_link = _get_download_link(asin, quality="Extreme")
        if dl_link:
            filename = pathlib.Path.cwd() / "audiobooks" / title