-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (42 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import Sequence
import click
from aok.audio_merge import AudioMerge
from aok.audio_split import AudioSplit
from aok.exporter import Exporter
supported_formats = ['mp3', 'wav', 'aif', 'ogg']
@click.group()
@click.version_option()
def aok() -> None:
"""A utility to split and/or join audio files.
"""
@aok.command()
@click.option('-f', '--format', required=False,
type=click.Choice(supported_formats),
help='The format of both input and output audio')
@click.option('-o', '--output', type=click.Path(), nargs=1,
help='Output file with absolute or relative path', required=False)
@click.argument('input', type=click.File('rb'), nargs=-1, required=True)
def join(format: str, output: click.Path, input: Sequence[click.File]) -> None:
"""Merge two or more audio files.
"""
Exporter.export(output,
AudioMerge.merge_all(input, format=format),
format=format)
@aok.command()
@click.option('-f', '--format', required=False,
type=click.Choice(supported_formats),
help='The format of both input and output audio')
@click.option('-s', '--seconds', type=int,
help='The number of seconds to split the song for', required=True)
@click.option('-o', '--output', type=click.Path(), nargs=1,
help='Output file with absolute or relative path', required=False)
@click.argument('input', type=click.File('rb'), nargs=1, required=True)
def split(format: str, seconds: int, output: click.Path, input: click.File) -> None:
"""Split a song for given number of seconds.
The seconds are counted from the beginning of the input song.
In case the number of seconds exceeds the input song's length,
input song will be exported as it is.
"""
Exporter.export(output,
AudioSplit.split_song(input, format=format, seconds=seconds),
format=format)