knock/src/knock.py

49 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import subprocess, magic, shutil, click
from pathlib import Path
from getpass import getpass
from xdg import xdg_config_home
2021-09-12 17:46:15 -05:00
from handle_acsm import handle_acsm
from handle_aax import handle_aax
__version__ = "1.0.0-alpha"
@click.version_option()
@click.command()
@click.argument(
2021-09-12 17:46:15 -05:00
"path",
type=click.Path(
exists=True,
file_okay=True,
dir_okay=False,
readable=True,
resolve_path=True
)
)
2021-09-12 17:46:15 -05:00
def main(path):
path = Path(path)
# make the config dir if it doesn't exist
2021-09-12 17:46:15 -05:00
xdg_config_home().joinpath('knock').mkdir(parents=True, exist_ok=True)
2021-09-12 17:46:15 -05:00
path_type = path.suffix[1:].upper()
2021-09-12 17:46:15 -05:00
if path_type == 'ACSM':
click.echo('Received an ACSM (Adobe) file...')
2021-09-12 17:46:15 -05:00
handle_acsm(path)
elif path_type == 'AAX':
click.echo('Received an AAX (Audible) file...')
handle_aax(path)
else:
2021-09-12 17:46:15 -05:00
click.echo(f'Error: Files of type {path_type} are not supported.\n', err=True)
click.echo('Only the following file types are currently supported:', err=True)
click.echo(' * ACSM (Adobe)\n', err=True)
click.echo(' * AAX (Audible)\n', err=True)
click.echo('Please open a feature request at:', err=True)
2021-09-12 17:46:15 -05:00
click.echo(f' https://github.com/BentonEdmondson/knock/issues/new?title=Support%20{path_type}%20Files&labels=enhancement', err=True)
sys.exit(1)
if __name__ == "__main__":
main()