mirror of
https://github.com/mkb79/audible-cli.git
synced 2025-06-27 17:00:34 -04:00
# Added - add the `api` command to make requests to the AudibleAPI - a counter of downloaded items for the download command - the `--verbosity/-v` option; default is INFO - the `--bunch-size` option to the download, library export and library list subcommand; this is only needed on slow internet connections - `wishlist` subcommand - the `--resolve-podcasts` flag to download subcommand; all episodes of a podcast will be fetched at startup, so a single episode can be searched via his title or asin - the `--ignore-podcasts` flag to download subcommand; if a podcast contains multiple episodes, the podcast will be ignored - the`models.Library.resolve_podcasts` method to append all podcast episodes to given library. - the `models.LibraryItem.get_child_items` method to get all episodes of a podcast item or parts for a MultiPartBook. - the`models.BaseItem` now holds a list of `response_groups` in the `_response_groups` attribute. - the`--format` option to `library export` subcommand - the `models.Catalog` class - the `models.Library.from_api_full_sync` method to fetch the full library # Changed - the `--aaxc` flag of the download command now try to check if a voucher file exists before a `licenserequest` is make (issue #60) - the `--aaxc` flag of the download command now downloads mp3/m4a files if the `aaxc` format is not available and the `licenserequest` offers this formats - the `download` subcommand now download podcasts - *Remove sync code where async code are available. All plugins should take care about this!!!* - Bump `audible` to v0.7.0 - rebuild `models.LibraryItem.get_aax_url` to build the aax download url in another way - `models.BaseItem.full_title` now contains publication name for podcast episodes - `models.LibraryItem` now checks the customer rights when calling `LibraryItem._is_downloadable` - `models.BaseItem` and `models.BaseList` now holds the `api_client` instead the `locale` and `auth` - rename `models.Wishlist.get_from_api` to `models.Wishlist.from_api` - rename `models.Library.get_from_api` to `models.Library.from_api`; this method does not fetch the full library for now # Misc - bump click to v8 # Bugfix - removing an error using the `--output` option of the `library export` command - fixing some other bugs
83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
"""Converts the credentials.json file from OpenAudible >= v2.4 beta to an
|
|
audible-cli auth file. The credentials.json file from OpenAudible leaves
|
|
unchanged, so you can use one device registration for OpenAudible and
|
|
audible-cli."""
|
|
|
|
|
|
import json
|
|
import pathlib
|
|
|
|
import audible
|
|
import click
|
|
from audible_cli.config import pass_session
|
|
|
|
|
|
def extract_data_from_file(credentials):
|
|
origins = {}
|
|
for k, v in credentials.items():
|
|
if k == "active_device":
|
|
continue
|
|
origin = v["details"]["response"]["success"]
|
|
origin["additionnel"] = {
|
|
"expires": v["expires"],
|
|
"region": v["region"].lower()
|
|
}
|
|
origins.update({k: origin})
|
|
return origins
|
|
|
|
|
|
def make_auth_file(fn, origin):
|
|
tokens = origin["tokens"]
|
|
adp_token = tokens["mac_dms"]["adp_token"]
|
|
device_private_key = tokens["mac_dms"]["device_private_key"]
|
|
store_authentication_cookie = tokens["store_authentication_cookie"]
|
|
access_token = tokens["bearer"]["access_token"]
|
|
refresh_token = tokens["bearer"]["refresh_token"]
|
|
expires = origin["additionnel"]["expires"]
|
|
|
|
extensions = origin["extensions"]
|
|
device_info = extensions["device_info"]
|
|
customer_info = extensions["customer_info"]
|
|
|
|
website_cookies = dict()
|
|
for cookie in tokens["website_cookies"]:
|
|
website_cookies[cookie["Name"]] = cookie["Value"].replace(r'"', r'')
|
|
|
|
data = {
|
|
"adp_token": adp_token,
|
|
"device_private_key": device_private_key,
|
|
"access_token": access_token,
|
|
"refresh_token": refresh_token,
|
|
"expires": expires,
|
|
"website_cookies": website_cookies,
|
|
"store_authentication_cookie": store_authentication_cookie,
|
|
"device_info": device_info,
|
|
"customer_info": customer_info,
|
|
"locale": origin["additionnel"]["region"]
|
|
}
|
|
auth = audible.Authenticator()
|
|
auth._update_attrs(**data)
|
|
return auth
|
|
|
|
|
|
@click.command("convert-oa-file")
|
|
@click.option(
|
|
"--input", "-i",
|
|
type=click.Path(exists=True, file_okay=True),
|
|
multiple=True,
|
|
help="OpenAudible credentials.json file")
|
|
@pass_session
|
|
def cli(session, input):
|
|
"""Converts a OpenAudible credential file to a audible-cli auth file
|
|
|
|
Stores the auth files in app dir"""
|
|
fdata = pathlib.Path(input).read_text("utf-8")
|
|
fdata = json.loads(fdata)
|
|
|
|
x = extract_data_from_file(fdata)
|
|
for k, v in x.items():
|
|
app_dir = pathlib.Path(session.get_app_dir())
|
|
fn = app_dir / pathlib.Path(k).with_suffix(".json")
|
|
auth = make_auth_file(fn, v)
|
|
auth.to_file(fn)
|
|
|