foley.sources.music_library.verify#
Checking a downloaded file is audio: an audio stream and a duration, read by foley’s probes.
probe_verify() is the default verify seam of
acquire() (bytes -> seconds). It writes the
bytes to a temporary file, checks it has an audio stream with
foley.sources.video.has_audio_stream() (ffprobe, else soundfile), and
reads its length with foley.sources.video.default_probe() (ffprobe, bounded
by a timeout, else mixing’s probe): the probes foley uses for media, rather than a
second ffprobe wrapper. An empty file, one with no audio stream (a video-only mp4, a
gif), one whose audio stream cannot be confirmed (fail closed), and one with no
readable duration (an error page saved as .mp3) are refused. require_probe()
stops a batch before its first download when the checks cannot run.
Module Attributes
how a file is checked to be a track (raises when it is not). |
Functions
Whether |
|
|
The duration of the audio |
Raise |
Exceptions
A tool every title needs is missing: the batch stops before it starts. |
- exception foley.sources.music_library.verify.MusicToolMissing[source]#
Bases:
RuntimeErrorA tool every title needs is missing: the batch stops before it starts.
- foley.sources.music_library.verify.Verify#
how a file is checked to be a track (raises when it is not).
- Type:
bytes -> seconds
- foley.sources.music_library.verify.probe_available()[source]#
Whether
probe_verify()’s probes can run here:ffprobeonPATH, or both mixing’s video probe with anffmpeg(the length) andsoundfile(the audio stream).- Return type:
- foley.sources.music_library.verify.probe_verify(data, *, probe=None, has_audio=None, suffix='.mp3')[source]#
The duration of the audio
data, in seconds.The bytes are written to a temporary file named with
suffix(from a pipe, ffprobe reports no duration).has_audio(path) -> True | False | Nonemust sayTrue(defaulthas_audio_stream();None, “cannot tell”, is a refusal), thenprobe(path) -> seconds | Nonereads the length (defaultdefault_probe()).>>> probe_verify(b"ID3...", probe=lambda path: 61.5, has_audio=lambda path: True) 61.5 >>> probe_verify(b"<html>403</html>", probe=lambda path: 3.0, ... has_audio=lambda path: False) Traceback (most recent call last): ... foley.sources.music_library.libraries.MusicLibraryError: the file has no audio stream >>> probe_verify(b"ID3...", probe=lambda path: None, has_audio=lambda path: True) Traceback (most recent call last): ... foley.sources.music_library.libraries.MusicLibraryError: the file has no readable duration (not audio)
- Raises:
MusicLibraryError – When the file is empty, has no audio stream (or one cannot be confirmed), or has no readable duration.
- Return type:
- foley.sources.music_library.verify.require_probe()[source]#
Raise
MusicToolMissingunlessprobe_available().- Return type: