diff --git a/README.md b/README.md index 98627b0..c549671 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pip install git+https://github.com/moises-ai/maestro-worker-python.git To install a version (recommended): ``` -pip install git+https://github.com/moises-ai/maestro-worker-python.git@1.0.23 +pip install git+https://github.com/moises-ai/maestro-worker-python.git@1.0.24 ``` ## Maestro init @@ -83,6 +83,12 @@ files_to_convert.append(FileToConvert(input_file_path="input.mp3", output_file_p convert_files(files_to_convert) ``` +### Get file duration in seconds +```python +from maestro_worker_python.get_duration import get_duration +get_duration('./myfile.mp3') +``` + ## Using Docker Compose ### Build image diff --git a/maestro_worker_python/data/requirements.txt b/maestro_worker_python/data/requirements.txt index a8c3f21..f0b12d4 100644 --- a/maestro_worker_python/data/requirements.txt +++ b/maestro_worker_python/data/requirements.txt @@ -1 +1 @@ -git+https://github.com/moises-ai/maestro-worker-python.git@1.0.23 +git+https://github.com/moises-ai/maestro-worker-python.git@1.0.24 diff --git a/maestro_worker_python/get_duration.py b/maestro_worker_python/get_duration.py new file mode 100644 index 0000000..c0f94ff --- /dev/null +++ b/maestro_worker_python/get_duration.py @@ -0,0 +1,16 @@ + +import logging +from subprocess import check_output +logging.basicConfig(level=logging.INFO) + + +def get_duration(local_file_path: str) -> int: + logging.info(f"Getting file duration for {local_file_path}") + try: + output = check_output(["ffprobe", "-v", "error", "-show_entries", + "format=duration", "-of", + "default=noprint_wrappers=1:nokey=1", + local_file_path]) + return int(float(output)) + except Exception as e: + logging.error(f"Error getting duration for {local_file_path}: {e}") diff --git a/setup.py b/setup.py index 1ef5706..b07d904 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ name="maestro_worker_python", py_modules=["maestro_worker_python", "maestro_worker_python.worker_example"], - version="1.0.23", + version="1.0.24", description="Utility to run workers on Moises/Maestro", readme="README.md", python_requires=">=3.7",