TonieToolbox 0.1.0__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tonietoolbox-0.1.0/TonieToolbox.egg-info → tonietoolbox-0.1.3}/PKG-INFO +3 -1
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/README.md +2 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/__init__.py +1 -1
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/__main__.py +6 -6
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/audio_conversion.py +8 -7
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/constants.py +1 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/dependency_manager.py +19 -7
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/tonie_file.py +6 -5
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3/TonieToolbox.egg-info}/PKG-INFO +3 -1
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/LICENSE.md +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/MANIFEST.in +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/filename_generator.py +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/logger.py +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/ogg_page.py +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/opus_packet.py +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/tonie_analysis.py +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/tonie_header.proto +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox/tonie_header_pb2.py +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox.egg-info/SOURCES.txt +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox.egg-info/dependency_links.txt +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox.egg-info/entry_points.txt +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox.egg-info/requires.txt +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/TonieToolbox.egg-info/top_level.txt +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/pyproject.toml +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/setup.cfg +0 -0
- {tonietoolbox-0.1.0 → tonietoolbox-0.1.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: TonieToolbox
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: Convert audio files to Tonie box compatible format
|
5
5
|
Home-page: https://github.com/Quentendo64/TonieToolbox
|
6
6
|
Author: Quentendo64
|
@@ -31,6 +31,8 @@ Happy Testing :-P
|
|
31
31
|
|
32
32
|
A Python tool for converting audio files to Tonie box compatible format (TAF - Tonie Audio Format).
|
33
33
|
|
34
|
+
# Beginners Guide
|
35
|
+
- [HOWTO](HOWTO.md)
|
34
36
|
|
35
37
|
## Table of Contents
|
36
38
|
|
@@ -71,17 +71,17 @@ def main():
|
|
71
71
|
|
72
72
|
ffmpeg_binary = args.ffmpeg
|
73
73
|
if ffmpeg_binary is None:
|
74
|
-
ffmpeg_binary = get_ffmpeg_binary()
|
74
|
+
ffmpeg_binary = get_ffmpeg_binary(args.auto_download)
|
75
75
|
if ffmpeg_binary is None:
|
76
|
-
logger.error("Could not find FFmpeg. Please install FFmpeg or specify its location using --ffmpeg")
|
76
|
+
logger.error("Could not find FFmpeg. Please install FFmpeg or specify its location using --ffmpeg or use --auto-download")
|
77
77
|
sys.exit(1)
|
78
78
|
logger.debug("Using FFmpeg binary: %s", ffmpeg_binary)
|
79
79
|
|
80
80
|
opus_binary = args.opusenc
|
81
81
|
if opus_binary is None:
|
82
|
-
opus_binary = get_opus_binary()
|
82
|
+
opus_binary = get_opus_binary(args.auto_download)
|
83
83
|
if opus_binary is None:
|
84
|
-
logger.error("Could not find opusenc. Please install opus-tools or specify its location using --opusenc")
|
84
|
+
logger.error("Could not find opusenc. Please install opus-tools or specify its location using --opusenc or use --auto-download")
|
85
85
|
sys.exit(1)
|
86
86
|
logger.debug("Using opusenc binary: %s", opus_binary)
|
87
87
|
|
@@ -123,7 +123,7 @@ def main():
|
|
123
123
|
logger.debug("Using default output location: %s", out_filename)
|
124
124
|
|
125
125
|
if args.append_tonie_tag:
|
126
|
-
|
126
|
+
logger.debug("Appending Tonie tag to output filename")
|
127
127
|
hex_tag = args.append_tonie_tag
|
128
128
|
logger.debug("Validating tag: %s", hex_tag)
|
129
129
|
if not all(c in '0123456789abcdefABCDEF' for c in hex_tag) or len(hex_tag) != 8:
|
@@ -137,7 +137,7 @@ def main():
|
|
137
137
|
|
138
138
|
logger.info("Creating Tonie file: %s with %d input file(s)", out_filename, len(files))
|
139
139
|
create_tonie_file(out_filename, files, args.no_tonie_header, args.user_timestamp,
|
140
|
-
args.bitrate, not args.cbr, ffmpeg_binary, opus_binary, args.keep_temp)
|
140
|
+
args.bitrate, not args.cbr, ffmpeg_binary, opus_binary, args.keep_temp, args.auto_download)
|
141
141
|
logger.info("Successfully created Tonie file: %s", out_filename)
|
142
142
|
|
143
143
|
|
@@ -12,7 +12,7 @@ from .logger import get_logger
|
|
12
12
|
logger = get_logger('audio_conversion')
|
13
13
|
|
14
14
|
|
15
|
-
def get_opus_tempfile(ffmpeg_binary=None, opus_binary=None, filename=None, bitrate=48, vbr=True, keep_temp=False):
|
15
|
+
def get_opus_tempfile(ffmpeg_binary=None, opus_binary=None, filename=None, bitrate=48, vbr=True, keep_temp=False, auto_download=False):
|
16
16
|
"""
|
17
17
|
Convert an audio file to Opus format and return a temporary file handle.
|
18
18
|
|
@@ -23,6 +23,7 @@ def get_opus_tempfile(ffmpeg_binary=None, opus_binary=None, filename=None, bitra
|
|
23
23
|
bitrate: Bitrate for the Opus encoding in kbps
|
24
24
|
vbr: Whether to use variable bitrate encoding
|
25
25
|
keep_temp: Whether to keep the temporary files for testing
|
26
|
+
auto_download: Whether to automatically download dependencies if not found
|
26
27
|
|
27
28
|
Returns:
|
28
29
|
tuple: (file handle, temp_file_path) or (file handle, None) if keep_temp is False
|
@@ -31,18 +32,18 @@ def get_opus_tempfile(ffmpeg_binary=None, opus_binary=None, filename=None, bitra
|
|
31
32
|
|
32
33
|
if ffmpeg_binary is None:
|
33
34
|
logger.debug("FFmpeg not specified, attempting to auto-detect")
|
34
|
-
ffmpeg_binary = get_ffmpeg_binary()
|
35
|
+
ffmpeg_binary = get_ffmpeg_binary(auto_download)
|
35
36
|
if ffmpeg_binary is None:
|
36
|
-
logger.error("Could not find
|
37
|
-
raise RuntimeError("Could not find
|
37
|
+
logger.error("Could not find FFmpeg binary. Use --auto-download to enable automatic installation")
|
38
|
+
raise RuntimeError("Could not find FFmpeg binary. Use --auto-download to enable automatic installation")
|
38
39
|
logger.debug("Found FFmpeg at: %s", ffmpeg_binary)
|
39
40
|
|
40
41
|
if opus_binary is None:
|
41
42
|
logger.debug("Opusenc not specified, attempting to auto-detect")
|
42
|
-
opus_binary = get_opus_binary()
|
43
|
+
opus_binary = get_opus_binary(auto_download)
|
43
44
|
if opus_binary is None:
|
44
|
-
logger.error("Could not find
|
45
|
-
raise RuntimeError("Could not find
|
45
|
+
logger.error("Could not find Opus binary. Use --auto-download to enable automatic installation")
|
46
|
+
raise RuntimeError("Could not find Opus binary. Use --auto-download to enable automatic installation")
|
46
47
|
logger.debug("Found opusenc at: %s", opus_binary)
|
47
48
|
|
48
49
|
vbr_parameter = "--vbr" if vbr else "--hard-cbr"
|
@@ -6,6 +6,7 @@ ONLY_CONVERT_FRAMEPACKING = -1
|
|
6
6
|
OTHER_PACKET_NEEDED = -2
|
7
7
|
DO_NOTHING = -3
|
8
8
|
TOO_MANY_SEGMENTS = -4
|
9
|
+
TIMESTAMP_DEDUCT = 0x50000000
|
9
10
|
OPUS_TAGS = [
|
10
11
|
bytearray(
|
11
12
|
b"\x4F\x70\x75\x73\x54\x61\x67\x73\x0D\x00\x00\x00\x4C\x61\x76\x66\x35\x38\x2E\x32\x30\x2E\x31\x30\x30\x03\x00\x00\x00\x26\x00\x00\x00\x65\x6E\x63\x6F\x64\x65\x72\x3D\x6F\x70\x75\x73\x65\x6E\x63\x20\x66\x72\x6F\x6D\x20\x6F\x70\x75\x73\x2D\x74\x6F\x6F\x6C\x73\x20\x30\x2E\x31\x2E\x31\x30\x2A\x00\x00\x00\x65\x6E\x63\x6F\x64\x65\x72\x5F\x6F\x70\x74\x69\x6F\x6E\x73\x3D\x2D\x2D\x71\x75\x69\x65\x74\x20\x2D\x2D\x62\x69\x74\x72\x61\x74\x65\x20\x39\x36\x20\x2D\x2D\x76\x62\x72\x3B\x01\x00\x00\x70\x61\x64\x3D\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30"),
|
@@ -21,12 +21,12 @@ logger = get_logger('dependency_manager')
|
|
21
21
|
DEPENDENCIES = {
|
22
22
|
'ffmpeg': {
|
23
23
|
'windows': {
|
24
|
-
'url': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl
|
24
|
+
'url': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip',
|
25
25
|
'bin_path': 'bin/ffmpeg.exe',
|
26
26
|
'extract_dir': 'ffmpeg'
|
27
27
|
},
|
28
28
|
'linux': {
|
29
|
-
'url': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl
|
29
|
+
'url': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz',
|
30
30
|
'bin_path': 'ffmpeg',
|
31
31
|
'extract_dir': 'ffmpeg'
|
32
32
|
},
|
@@ -280,12 +280,13 @@ def install_package(package_name):
|
|
280
280
|
logger.error("Failed to install %s: %s", package_name, e)
|
281
281
|
return False
|
282
282
|
|
283
|
-
def ensure_dependency(dependency_name):
|
283
|
+
def ensure_dependency(dependency_name, auto_download=False):
|
284
284
|
"""
|
285
285
|
Ensure that a dependency is available, downloading it if necessary.
|
286
286
|
|
287
287
|
Args:
|
288
288
|
dependency_name (str): Name of the dependency ('ffmpeg' or 'opusenc')
|
289
|
+
auto_download (bool): Whether to automatically download or install the dependency if not found
|
289
290
|
|
290
291
|
Returns:
|
291
292
|
str: Path to the binary if available, None otherwise
|
@@ -308,6 +309,11 @@ def ensure_dependency(dependency_name):
|
|
308
309
|
logger.info("Found %s in PATH: %s", dependency_name, path_binary)
|
309
310
|
return path_binary
|
310
311
|
|
312
|
+
# If auto_download is not enabled, don't try to install or download
|
313
|
+
if not auto_download:
|
314
|
+
logger.warning("%s not found in PATH and auto-download is disabled. Use --auto-download to enable automatic installation.", dependency_name)
|
315
|
+
return None
|
316
|
+
|
311
317
|
# If not in PATH, check if we should install via package manager
|
312
318
|
if 'package' in DEPENDENCIES[dependency_name].get(system, {}):
|
313
319
|
package_name = DEPENDENCIES[dependency_name][system]['package']
|
@@ -359,20 +365,26 @@ def ensure_dependency(dependency_name):
|
|
359
365
|
logger.error("Failed to set up %s", dependency_name)
|
360
366
|
return None
|
361
367
|
|
362
|
-
def get_ffmpeg_binary():
|
368
|
+
def get_ffmpeg_binary(auto_download=False):
|
363
369
|
"""
|
364
370
|
Get the path to the FFmpeg binary, downloading it if necessary.
|
365
371
|
|
372
|
+
Args:
|
373
|
+
auto_download (bool): Whether to automatically download or install if not found
|
374
|
+
|
366
375
|
Returns:
|
367
376
|
str: Path to the FFmpeg binary if available, None otherwise
|
368
377
|
"""
|
369
|
-
return ensure_dependency('ffmpeg')
|
378
|
+
return ensure_dependency('ffmpeg', auto_download)
|
370
379
|
|
371
|
-
def get_opus_binary():
|
380
|
+
def get_opus_binary(auto_download=False):
|
372
381
|
"""
|
373
382
|
Get the path to the opusenc binary, downloading it if necessary.
|
374
383
|
|
384
|
+
Args:
|
385
|
+
auto_download (bool): Whether to automatically download or install if not found
|
386
|
+
|
375
387
|
Returns:
|
376
388
|
str: Path to the opusenc binary if available, None otherwise
|
377
389
|
"""
|
378
|
-
return ensure_dependency('opusenc')
|
390
|
+
return ensure_dependency('opusenc', auto_download)
|
@@ -12,7 +12,7 @@ import os
|
|
12
12
|
from . import tonie_header_pb2
|
13
13
|
from .opus_packet import OpusPacket
|
14
14
|
from .ogg_page import OggPage
|
15
|
-
from .constants import OPUS_TAGS, SAMPLE_RATE_KHZ
|
15
|
+
from .constants import OPUS_TAGS, SAMPLE_RATE_KHZ, TIMESTAMP_DEDUCT
|
16
16
|
from .logger import get_logger
|
17
17
|
|
18
18
|
# Setup logging
|
@@ -277,7 +277,7 @@ def fix_tonie_header(out_file, chapters, timestamp, sha):
|
|
277
277
|
|
278
278
|
|
279
279
|
def create_tonie_file(output_file, input_files, no_tonie_header=False, user_timestamp=None,
|
280
|
-
bitrate=96, vbr=True, ffmpeg_binary=None, opus_binary=None, keep_temp=False):
|
280
|
+
bitrate=96, vbr=True, ffmpeg_binary=None, opus_binary=None, keep_temp=False, auto_download=False):
|
281
281
|
"""
|
282
282
|
Create a Tonie file from input files.
|
283
283
|
|
@@ -291,6 +291,7 @@ def create_tonie_file(output_file, input_files, no_tonie_header=False, user_time
|
|
291
291
|
ffmpeg_binary: Path to ffmpeg binary
|
292
292
|
opus_binary: Path to opusenc binary
|
293
293
|
keep_temp: Whether to keep temporary opus files for testing
|
294
|
+
auto_download: Whether to automatically download dependencies if not found
|
294
295
|
"""
|
295
296
|
from .audio_conversion import get_opus_tempfile
|
296
297
|
|
@@ -330,8 +331,8 @@ def create_tonie_file(output_file, input_files, no_tonie_header=False, user_time
|
|
330
331
|
timestamp = int(time.time())
|
331
332
|
logger.debug("Falling back to current timestamp: %d", timestamp)
|
332
333
|
else:
|
333
|
-
timestamp = int(time.time())
|
334
|
-
logger.debug("Using current timestamp: %d", timestamp)
|
334
|
+
timestamp = int(time.time()-TIMESTAMP_DEDUCT)
|
335
|
+
logger.debug("Using current timestamp - 0x50000000: %d", timestamp)
|
335
336
|
|
336
337
|
sha1 = hashlib.sha1()
|
337
338
|
|
@@ -360,7 +361,7 @@ def create_tonie_file(output_file, input_files, no_tonie_header=False, user_time
|
|
360
361
|
else:
|
361
362
|
logger.debug("Converting %s to Opus format (bitrate: %d kbps, VBR: %s)",
|
362
363
|
fname, bitrate, vbr)
|
363
|
-
handle, temp_file_path = get_opus_tempfile(ffmpeg_binary, opus_binary, fname, bitrate, vbr, keep_temp)
|
364
|
+
handle, temp_file_path = get_opus_tempfile(ffmpeg_binary, opus_binary, fname, bitrate, vbr, keep_temp, auto_download)
|
364
365
|
if temp_file_path:
|
365
366
|
temp_files.append(temp_file_path)
|
366
367
|
logger.debug("Temporary opus file saved to: %s", temp_file_path)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: TonieToolbox
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: Convert audio files to Tonie box compatible format
|
5
5
|
Home-page: https://github.com/Quentendo64/TonieToolbox
|
6
6
|
Author: Quentendo64
|
@@ -31,6 +31,8 @@ Happy Testing :-P
|
|
31
31
|
|
32
32
|
A Python tool for converting audio files to Tonie box compatible format (TAF - Tonie Audio Format).
|
33
33
|
|
34
|
+
# Beginners Guide
|
35
|
+
- [HOWTO](HOWTO.md)
|
34
36
|
|
35
37
|
## Table of Contents
|
36
38
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|