Skip to content

Commit

Permalink
Add CLI for detect audio function
Browse files Browse the repository at this point in the history
Rewrite function to only return each file once,
even if there are multiple audio streams.
Rename other CLI related functions.
Remove name-main part.
  • Loading branch information
153957 committed Dec 29, 2024
1 parent a62d104 commit fd99b47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Homepage = 'https://arne.delaat.net/timelapse.html'
Repository = 'https://github.com/153957/time-lapse'

[project.scripts]
timelapse = 'time_lapse.cli:main'
timelapse = 'time_lapse.cli:timelapse'
detect_audio = 'time_lapse.cli:detect_audio'

[tool.mypy]
ignore_missing_imports = true
Expand Down
26 changes: 23 additions & 3 deletions time_lapse/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse

from time_lapse import output, source
from time_lapse.detect_audio import files_with_audio


def make_movie(
Expand All @@ -17,7 +18,7 @@ def make_movie(
output.create_outputs(source_input, name, watermark=watermark, verbose=verbose, dryrun=dryrun)


def main() -> None:
def get_parser_timelapse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description='Combine frames into a movie.')
parser.add_argument(
'--name',
Expand Down Expand Up @@ -60,10 +61,29 @@ def main() -> None:
help='Add watermark, provide two value, one main text and the subtext.',
nargs=2,
)
return parser


def timelapse() -> None:
parser = get_parser_timelapse()
kwargs = vars(parser.parse_args())

make_movie(**kwargs)


if __name__ == '__main__':
main()
def get_parser_detect_audio() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description='Find movie files with audio streams.')
parser.add_argument(
'--pattern',
help='Glob pattern with which to find the movies to check.',
default='*.mp4',
)
return parser


def detect_audio() -> None:
parser = get_parser_detect_audio()
kwargs = vars(parser.parse_args())

for filename in files_with_audio(**kwargs):
print(filename)
8 changes: 5 additions & 3 deletions time_lapse/detect_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

def files_with_audio(pattern: str = '*.mp4') -> Iterator[str]:
for filename in Path().glob(pattern):
for stream in ffmpeg.probe(filename)['streams']:
if stream['codec_type'] == 'audio':
yield str(filename)
if any(
stream['codec_type'] == 'audio'
for stream in ffmpeg.probe(filename)['streams']
):
yield str(filename)

0 comments on commit fd99b47

Please sign in to comment.