-
-
Notifications
You must be signed in to change notification settings - Fork 6
Usage from Python
- FFCueSplitter Useful for obtaining information and ready-to-use recipes.
- FileSystemOperations For automating splitting processes.
- filename: (str) absolute or relative CUE sheet file pathname.
-
outputdir: (str) absolute or relative pathname to output files, default is
"."
, the same as file pathname. -
collection: (str) adds audio collection sub-dirctories, one of
"artist+album", "artist", "album"
, default is""
. -
outputformat: (str) output format, one of
"wav", "flac", "mp3", "ogg", "opus", "copy"
, default is"flac"
. -
overwrite: (str) overwriting options, one of
"ask", "never", "always"
, default is"ask"
. -
ffmpeg_cmd: (str) an absolute path command of ffmpeg, default is
"ffmpeg"
-
ffmpeg_add_params: (str) additionals parameters of FFmpeg (require to be quoted in single quotes), default is
''
. -
ffmpeg_loglevel: (str) one of
"error", "warning", "info", "verbose", "debug"
, default is"info"
. -
ffprobe_cmd: (str) an absolute path command of ffprobe, default is
"ffprobe"
. -
progress_meter: (str) one of
"tqdm", "standard"
, default is"standard"
. Note thattqdm
argument adds-progress pipe:1 -nostats -nostdin
parameter to the FFmpeg recipes. Keep this in mind if you intend to use these recipes in your program. -
dry: (bool) with
True
, perform the dry run with no changes done to filesystem. -
prg_loglevel: (str) program logging level of tracking events to console. One of
"error", "warning", "info", "debug"
, default is"info"
.
In the following examples we will use the sample file Three Samples_ASCII.cue inside the sources directory. To get the same results when trying the following examples yourself, be sure to open the Python console inside the source directory.
The FFCueSplitter class was designed for retrieving essential data related to audio track splitting. The data obtained can be used by other applications.
Possible constructors (see Arguments):
FFCueSplitter(filename='filename')
FFCueSplitter(**kwargs)
FFCueSplitter(filename='filename', outputdir='.', collection='',
outputformat='flac', overwrite='ask', ffmpeg_cmd='ffmpeg',
ffmpeg_loglevel='info', ffprobe_cmd='ffprobe', ffmpeg_add_params='',
progress_meter='standard', dry=False, prg_loglevel='info')
Examples:
>>> from ffcuesplitter.cuesplitter import FFCueSplitter
For more details, type help(FFCueSplitter)
>>> getdata = FFCueSplitter(filename="tests/Three Samples_ASCII.cue", dry=True)
>>> tracks = getdata.audiotracks
>>> tracks
Output:
[{'FILE': 'Three Samples.flac', 'ALBUM': 'Sox - Three samples', 'PERFORMER': 'Sox the genius', 'DATE': '2021',
'GENRE': 'Noise', 'COMMENT': 'Just a little bit of noise generated with sox', 'TITLE': '300 Hz', 'TRACK_NUM': '1',
'INDEX 01': '00:00:00', 'START': 0, 'END': 88200, 'DURATION': 2.0}, {'FILE': 'Three Samples.flac', 'ALBUM': 'Sox - Three samples',
'PERFORMER': 'Sox the genius', 'DATE': '2021', 'GENRE': 'Noise', 'COMMENT': 'Just a little bit of noise generated with sox',
'TITLE': '400 Hz', 'TRACK_NUM': '2', 'INDEX 01': '00:02:00', 'START': 88200, 'END': 176400, 'DURATION': 2.0},
{'FILE': 'Three Samples.flac', 'ALBUM': 'Sox - Three samples', 'PERFORMER': 'Sox the genius', 'DATE': '2021', 'GENRE': 'Noise',
'COMMENT': 'Just a little bit of noise generated with sox', 'TITLE': '500 Hz', 'TRACK_NUM': '3', 'INDEX 01': '00:04:00',
'START': 176400, 'DURATION': 2.0}]
>>> getdata.commandargs(tracks)
Output:
{'recipes': [('"ffmpeg" -loglevel info -i "tests/Three Samples.flac" -ss 0.0 -to 2.0 -metadata ARTIST="Sox the genius"
-metadata ALBUM="Sox - Three samples" -metadata TITLE="300 Hz" -metadata TRACK="1/3" -metadata DISCNUMBER="" -metadata GENRE="Noise"
-metadata DATE="2021" -metadata COMMENT="Just a little bit of noise generated with sox" -metadata DISCID="" -c:a flac -ar 44100 -y
"./01 - 300 Hz.flac"', {'duration': 2.0, 'titletrack': '01 - 300 Hz.flac'}), ('"ffmpeg" -loglevel info -i "tests/Three Samples.flac"
-ss 2.0 -to 4.0 -metadata ARTIST="Sox the genius" -metadata ALBUM="Sox - Three samples" -metadata TITLE="400 Hz" -metadata TRACK="2/3"
-metadata DISCNUMBER="" -metadata GENRE="Noise" -metadata DATE="2021" -metadata COMMENT="Just a little bit of noise generated with sox"
-metadata DISCID="" -c:a flac -ar 44100 -y "./02 - 400 Hz.flac"', {'duration': 2.0, 'titletrack': '02 - 400 Hz.flac'}),
('"ffmpeg" -loglevel info -i "tests/Three Samples.flac" -ss 4.0 -metadata ARTIST="Sox the genius" -metadata ALBUM="Sox - Three samples"
-metadata TITLE="500 Hz" -metadata TRACK="3/3" -metadata DISCNUMBER="" -metadata GENRE="Noise" -metadata DATE="2021"
-metadata COMMENT="Just a little bit of noise generated with sox" -metadata DISCID="" -c:a flac -ar 44100 -y "./03 - 500 Hz.flac"',
{'duration': 2.0, 'titletrack': '03 - 500 Hz.flac'})]}
>>> getdata.cue.meta.data # get CD info
Output:
{'ALBUM': 'Sox - Three samples', 'PERFORMER': 'Sox the genius', 'DATE': '2021', 'GENRE': 'Noise', 'COMMENT': 'Just a little bit of noise generated with sox'}
>>> getdata.probedata
Output:
[{'streams': [{'index': 0, 'codec_name': 'flac', 'codec_long_name': 'FLAC (Free Lossless Audio Codec)', 'codec_type': 'audio', 'codec_time_base': '1/44100', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'sample_fmt': 's16', 'sample_rate': '44100', 'channels': 1, 'channel_layout': 'mono', 'bits_per_sample': 0, 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/44100', 'start_pts': 0, 'start_time': '0.000000', 'duration_ts': 264600, 'duration': '6.000000', 'bits_per_raw_sample': '16', 'disposition': {'default': 0, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}}], 'format': {'filename': 'Three Samples.flac', 'nb_streams': 1, 'nb_programs': 0, 'format_name': 'flac', 'format_long_name': 'raw FLAC', 'start_time': '0.000000', 'duration': '6.000000', 'size': '94480', 'bit_rate': '125973', 'probe_score': 100, 'tags': {'encoder': 'Lavf58.45.100'}}}]
This class represents a control interface designed for splitting audio tracks. It can be used to extend control functions on the Python console or via Python scripts that implement the command line, but it is NOT suitable for graphical interfaces at all. It implements a convenient interface for file system operations, such as overwrite checking functionality for file destinations, writing files in a temporary context, move files from temporary directory to output directory. There is also a specific method for dry mode.
Possible constructors (see Arguments):
FileSystemOperations(filename='filename')
FileSystemOperations(**kwargs)
FileSystemOperations(filename='filename', outputdir='.', collection='',
outputformat='flac', overwrite='ask', ffmpeg_cmd='ffmpeg',
ffmpeg_loglevel='info', ffprobe_cmd='ffprobe', ffmpeg_add_params='',
progress_meter='standard', dry=False, prg_loglevel='info')
Examples:
>>> from ffcuesplitter.user_service import FileSystemOperations
For more details, type help(FileSystemOperations)
>>> split = FileSystemOperations(filename="tests/Three Samples_ASCII.cue")
>>> if split.kwargs['dry']:
>>> split.dry_run_mode()
>>> else:
>>> overwr = split.check_for_overwriting()
>>> if not overwr:
>>> split.work_on_temporary_directory()