예제 #1
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)
예제 #2
0
        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")


if __name__ == "__main__":
    # authenticate with login
    # don't stores any credentials on your system
    auth = audible.LoginAuthenticator("USERNAME",
                                      "PASSWORD",
                                      locale="us",
                                      register=False)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(auth))

    # store credentials to file
    auth.to_file(filename="FILENAME", encryption="json", password="******")

    # register device
    auth.register_device()

    # save again
    auth.to_file()

    # load credentials from file
    auth = audible.FileAuthenticator(filename="FILENAME", password="******")
예제 #3
0
        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")


if __name__ == "__main__":
    # authenticate with login and deregister after job
    # don't stores any credentials on your system
    # don't use `with`-statement if you want to store credentials
    with audible.LoginAuthenticator(
        "USERNAME", "PASSWORD", locale="us"
    ) as auth:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(main(auth))

    # authenticate with login
    # store credentials to file
    auth = audible.LoginAuthenticator(
        "USERNAME", "PASSWORD", locale="us"
    )
    auth.to_file(
        filename="FILENAME",
        encryption="json",
        password="******"
    )
예제 #4
0
async def main():
    #Name of the encrypted file with Amazon credentials
    Auth_file = "Credentials"

    #If it doesn't exists, it will be created
    if (not os.path.exists(Auth_file)):
        auth = audible.LoginAuthenticator(
            input("Username: "******"Password: "******"Enter one of the following country" +
                "\ncode 'de', 'us', 'ca', 'uk', 'au', 'fr', 'jp', 'it', 'in' \nEnter: "
            ),
            register=True)

        print("This information will be stored in an encrypted" +
              "\nfile so you don't have to insert them anymore.")
        config.credentials_pass = input(
            "Enter a password for the encryption: ")
        auth.to_file(filename=Auth_file,
                     password=config.credentials_pass,
                     encryption="bytes")
    else:
        auth = audible.FileAuthenticator(filename=Auth_file,
                                         password=config.credentials_pass)

    async with audible.AsyncClient(auth=auth) as client:

        activation_bytes = auth.get_activation_bytes()

        #Checking download folder
        if (not os.path.exists(config.download_folder)):
            os.mkdir(config.download_folder)

        #Retrieving audiobooks
        library = await client.get("library", num_results=1000)
        books = {book["title"]: book["asin"] for book in library["items"]}
        titles = [title for title in books.keys()]

        #Printing list of audiobooks
        for index, title in enumerate(titles):
            print(str(index + 1) + ") " + title)

        #Input of the book(s) that will be downloaded
        print("\nEnter the number of the book you want to download" +
              "\nIf you want to download multiple book enter the" +
              "\nnumber of the first and the last book separated" +
              "\nby a dash and without spaces between (i.e. 0-10)\n")
        book_range = input("Enter: ")
        book_range = book_range.split("-")

        if (len(book_range) == 2):
            first_book, last_book = book_range
            first_book = int(first_book) - 1
            last_book = int(last_book)
        elif (len(book_range) == 1):
            first_book = int(book_range[0]) - 1
            last_book = first_book + 1
        else:
            raise Exception("Invalid input!")

        #Downloading and converting books
        for index in range(first_book, last_book):
            asin = books[titles[index]]
            dl_link = await _get_download_link(auth, asin)

            if dl_link:
                print(f"Downloading now: {titles[index]}")
                status = await download_file(dl_link)
                print(f"Downloaded file: {status}")

                print("Now converting")
                status = await ConvertToMp3(
                    status, activation_bytes,
                    os.path.join(config.download_folder,
                                 titles[index].replace(" ", "")))
                print(f"Converted file: {status}")
예제 #5
0
# So this is a somewhat manual but not nearly as manual as it could be process.
# First, follow the instructions here: https://www.themodernnomad.com/audible-statistics-extractor/
# Depending on how many pages, copy and paste the results into Excel
# (it will auto format, though you will need to remove the header)

import audible

# example for US accounts
auth = audible.LoginAuthenticator("EMAIL", "PASSWORD", locale="us")

# to specify another API version
library, _ = client.get(path="library/books",
                        api_version="0.0",
                        params={
                            "purchaseAfterDate": "01/01/1970",
                            "sortInAscendingOrder": "true"
                        })

# Before running
# Install the required libraries: pandas and isbntools
# Modify the read_excel argument to point at your file.
# Then point the to_csv argument to wherever you want to export to.

# Go to https://www.goodreads.com/review/import, add the CSV file, and sit back and enjoy

import pandas as pd
from isbntools.app import *

df = pd.read_excel(r'/path/to/the/saved/excel.xlsx')

# Fetch ISBN from title and author using isbn tools
예제 #6
0
import audible

# needs at least audible v0.4.0

# if you have a valid auth file already
password = input("Password for file: ")
auth = audible.FileAuthenticator(filename="FILENAME", password=password)

# or use LoginAuthenticator (without register)
auth = audible.LoginAuthenticator(username="******",
                                  password="******",
                                  locale="YOUR_COUNTRY_CODE",
                                  register=False)

ab = auth.get_activation_bytes()
print(ab)