Skip to content

Commit

Permalink
add get_duration utility
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldoramos committed Nov 23, 2022
1 parent 7097660 commit 8eb9240
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion maestro_worker_python/data/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions maestro_worker_python/get_duration.py
Original file line number Diff line number Diff line change
@@ -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}")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8eb9240

Please sign in to comment.