malahit-clip 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Max Arnold
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: malahit-clip
3
+ Version: 0.1.0
4
+ Summary: A tool to generate SWL reports from Malahit DSP3 screenshots and audio records
5
+ Keywords: malahit,sdr,shortwave,radio,ffmpeg,video
6
+ License-Expression: MIT
7
+ License-File: LICENSE.md
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: End Users/Desktop
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Multimedia :: Sound/Audio
17
+ Classifier: Topic :: Multimedia :: Video
18
+ Classifier: Topic :: Utilities
19
+ Requires-Dist: pillow
20
+ Requires-Dist: platformdirs
21
+ Maintainer: Max Arnold
22
+ Requires-Python: >=3.14
23
+ Project-URL: Homepage, https://github.com/max-arnold/malahit-clip
24
+ Project-URL: Repository, https://github.com/max-arnold/malahit-clip
25
+ Project-URL: Issues, https://github.com/max-arnold/malahit-clip/issues
26
+ Description-Content-Type: text/markdown
27
+
28
+ # Malahit DSP3 SWL report clip maker
29
+
30
+ A tool to generate SWL reports from Malahit DSP3 screenshots and audio records.
31
+
32
+ ## Run with uvx
33
+
34
+ Install uv first:
35
+
36
+ https://github.com/astral-sh/uv#installation
37
+
38
+ Fetch ffmpeg, ffprobe, and the Roboto font into the user cache:
39
+
40
+ ```bash
41
+ uvx malahit-clip fetch-assets
42
+ ```
43
+
44
+ Create a clip:
45
+
46
+ ```bash
47
+ uvx malahit-clip make \
48
+ --image SS_20251018_195749.bmp \
49
+ --audio 4.6020MHz_USB_4.WAV \
50
+ --description "Test description" \
51
+ --output out.mp4
52
+ ```
53
+
54
+ Optional metadata:
55
+
56
+ ```bash
57
+ uvx malahit-clip make \
58
+ -i screenshot.bmp \
59
+ -a recording.wav \
60
+ -d "Station description" \
61
+ -o report.mp4 \
62
+ --receiver "MALAHIT DSP3" \
63
+ --antenna "K-480WLA" \
64
+ --location "Kemerovo"
65
+ ```
@@ -0,0 +1,38 @@
1
+ # Malahit DSP3 SWL report clip maker
2
+
3
+ A tool to generate SWL reports from Malahit DSP3 screenshots and audio records.
4
+
5
+ ## Run with uvx
6
+
7
+ Install uv first:
8
+
9
+ https://github.com/astral-sh/uv#installation
10
+
11
+ Fetch ffmpeg, ffprobe, and the Roboto font into the user cache:
12
+
13
+ ```bash
14
+ uvx malahit-clip fetch-assets
15
+ ```
16
+
17
+ Create a clip:
18
+
19
+ ```bash
20
+ uvx malahit-clip make \
21
+ --image SS_20251018_195749.bmp \
22
+ --audio 4.6020MHz_USB_4.WAV \
23
+ --description "Test description" \
24
+ --output out.mp4
25
+ ```
26
+
27
+ Optional metadata:
28
+
29
+ ```bash
30
+ uvx malahit-clip make \
31
+ -i screenshot.bmp \
32
+ -a recording.wav \
33
+ -d "Station description" \
34
+ -o report.mp4 \
35
+ --receiver "MALAHIT DSP3" \
36
+ --antenna "K-480WLA" \
37
+ --location "Kemerovo"
38
+ ```
@@ -0,0 +1,54 @@
1
+ [project]
2
+ name = "malahit-clip"
3
+ version = "0.1.0"
4
+ description = "A tool to generate SWL reports from Malahit DSP3 screenshots and audio records"
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ maintainers = [
8
+ { name = "Max Arnold" },
9
+ ]
10
+ license = "MIT"
11
+ license-files = ["LICENSE.md"]
12
+ keywords = ["malahit", "sdr", "shortwave", "radio", "ffmpeg", "video"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Environment :: Console",
16
+ "Intended Audience :: End Users/Desktop",
17
+ "Operating System :: MacOS",
18
+ "Operating System :: Microsoft :: Windows",
19
+ "Operating System :: POSIX :: Linux",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Topic :: Multimedia :: Sound/Audio",
23
+ "Topic :: Multimedia :: Video",
24
+ "Topic :: Utilities",
25
+ ]
26
+ dependencies = [
27
+ "pillow",
28
+ "platformdirs",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/max-arnold/malahit-clip"
33
+ Repository = "https://github.com/max-arnold/malahit-clip"
34
+ Issues = "https://github.com/max-arnold/malahit-clip/issues"
35
+
36
+ [project.scripts]
37
+ malahit-clip = "malahit_clip:main"
38
+
39
+ [build-system]
40
+ requires = ["uv_build>=0.11.6,<0.12"]
41
+ build-backend = "uv_build"
42
+
43
+ [dependency-groups]
44
+ dev = [
45
+ "prek",
46
+ "ruff",
47
+ ]
48
+
49
+ [tool.uv]
50
+ exclude-newer = "3 days"
51
+
52
+ [tool.uv.build-backend]
53
+ module-name = "malahit_clip"
54
+ module-root = "src"
@@ -0,0 +1,163 @@
1
+ import argparse
2
+ import datetime
3
+ import platform
4
+ import stat
5
+ import subprocess
6
+ import tempfile
7
+ import urllib.request
8
+ import zipfile
9
+ from pathlib import Path
10
+ from urllib.parse import urlparse
11
+
12
+ from platformdirs import user_cache_dir
13
+ from PIL import Image, ImageDraw, ImageFont
14
+
15
+
16
+ APP_NAME = "malahit-clip"
17
+ FONT_URLS = {
18
+ "https://github.com/googlefonts/roboto-3-classic/releases/download/v3.015/Roboto_v3.015.zip": ("hinted/static/Roboto-Regular.ttf",),
19
+ }
20
+ USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
21
+ FFMPEG_URLS = {
22
+ "linux-amd64": {
23
+ "https://ffmpeg.martin-riedl.de/download/linux/amd64/1774550169_8.1/ffmpeg.zip": ("ffmpeg",),
24
+ "https://ffmpeg.martin-riedl.de/download/linux/amd64/1774550169_8.1/ffprobe.zip": ("ffprobe",),
25
+ },
26
+ "linux-arm64": {
27
+ "https://ffmpeg.martin-riedl.de/download/linux/arm64/1774548896_8.1/ffmpeg.zip": ("ffmpeg",),
28
+ "https://ffmpeg.martin-riedl.de/download/linux/arm64/1774548896_8.1/ffprobe.zip": ("ffprobe",),
29
+ },
30
+ "darwin-amd64": {
31
+ "https://ffmpeg.martin-riedl.de/download/macos/amd64/1774556648_8.1/ffmpeg.zip": ("ffmpeg",),
32
+ "https://ffmpeg.martin-riedl.de/download/macos/amd64/1774556648_8.1/ffprobe.zip": ("ffprobe",),
33
+ },
34
+ "darwin-arm64": {
35
+ "https://ffmpeg.martin-riedl.de/download/macos/arm64/1774549676_8.1/ffmpeg.zip": ("ffmpeg",),
36
+ "https://ffmpeg.martin-riedl.de/download/macos/arm64/1774549676_8.1/ffprobe.zip": ("ffprobe",),
37
+ },
38
+ "windows-amd64": {
39
+ "https://github.com/GyanD/codexffmpeg/releases/download/8.1.1/ffmpeg-8.1.1-essentials_build.zip": ("ffmpeg.exe", "ffprobe.exe"),
40
+ },
41
+ "windows-arm64": {
42
+ "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n8.1-latest-winarm64-lgpl-8.1.zip": ("ffmpeg.exe", "ffprobe.exe"),
43
+ },
44
+ }
45
+
46
+
47
+ def fetch_and_extract(url, dst, members):
48
+ tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".zip")
49
+ tmp.close()
50
+ try:
51
+ print(f"Downloading {url} to {tmp.name}")
52
+ parsed = urlparse(url)
53
+ request = urllib.request.Request(
54
+ url,
55
+ headers={"Referer": f"{parsed.scheme}://{parsed.netloc}/", "User-Agent": USER_AGENT},
56
+ )
57
+ with urllib.request.urlopen(request) as response, open(tmp.name, "wb") as out:
58
+ out.write(response.read())
59
+ with zipfile.ZipFile(tmp.name) as z:
60
+ for member in members:
61
+ name = member if member in z.namelist() else next(n for n in z.namelist() if Path(n).name == Path(member).name)
62
+ with z.open(name) as src, open(dst / Path(member).name, "wb") as out:
63
+ out.write(src.read())
64
+ finally:
65
+ Path(tmp.name).unlink(missing_ok=True)
66
+
67
+
68
+ def ensure_assets(target_platform=None, force=False):
69
+ cache = Path(user_cache_dir(APP_NAME))
70
+ cache.mkdir(parents=True, exist_ok=True)
71
+ system = platform.system().lower()
72
+ arch = "arm64" if platform.machine().lower() in {"aarch64", "arm64"} else "amd64"
73
+ target_platform = target_platform or f"{system}-{arch}"
74
+ exe = ".exe" if target_platform.startswith("windows-") else ""
75
+ paths = {
76
+ "ffmpeg": cache / f"ffmpeg{exe}",
77
+ "ffprobe": cache / f"ffprobe{exe}",
78
+ "roboto": cache / "Roboto-Regular.ttf",
79
+ }
80
+ if force or not all(p.exists() for p in paths.values()):
81
+ for url, members in FFMPEG_URLS[target_platform].items():
82
+ fetch_and_extract(url, cache, members)
83
+ for url, members in FONT_URLS.items():
84
+ fetch_and_extract(url, cache, members)
85
+ for path in (paths["ffmpeg"], paths["ffprobe"]):
86
+ path.chmod(path.stat().st_mode | stat.S_IXUSR)
87
+ return paths
88
+
89
+
90
+ def get_wrapped_text(text, font, line_length):
91
+ lines = [""]
92
+ for word in text.split():
93
+ line = f"{lines[-1]} {word}".strip()
94
+ if font.getlength(line) <= line_length:
95
+ lines[-1] = line
96
+ else:
97
+ lines.append(word)
98
+ return "\n".join(lines)
99
+
100
+
101
+ def make_clip(args):
102
+ assets = ensure_assets()
103
+ canvas = Image.new("RGB", (720, 352))
104
+ draw = ImageDraw.Draw(canvas)
105
+ draw.line([(10, 11), (501, 11), (501, 341), (10, 341), (10, 11), (501, 11)], fill="#9d9781", width=7, joint="curve")
106
+ draw.line([(512, 8), (710, 8), (710, 344), (512, 344), (512, 8)], fill="#9d9781", width=1)
107
+
108
+ image = Path(args.image)
109
+ dt = datetime.datetime.fromtimestamp(image.stat().st_mtime).strftime("%Y-%m-%d %H:%M")
110
+ img = Image.open(image)
111
+ if img.size[0] > 480 or img.size[1] > 320:
112
+ img = img.resize((480, int(img.size[1] * (480 / img.size[0]))), Image.Resampling.LANCZOS)
113
+ canvas.paste(img, (16, 17))
114
+
115
+ font_label = ImageFont.truetype(assets["roboto"], 12)
116
+ font_text = ImageFont.truetype(assets["roboto"], 18)
117
+ font_desc = ImageFont.truetype(assets["roboto"], 16)
118
+ for y, label, value in [
119
+ (13, "Recorded with:", args.receiver),
120
+ (63, "Antenna:", args.antenna),
121
+ (113, "Location:", args.location),
122
+ (163, "Date and time:", dt),
123
+ ]:
124
+ draw.text((520, y), label, fill="#9d9781", font=font_label)
125
+ draw.text((520, y + 16), value, fill="#ffffff", font=font_text)
126
+ draw.text((520, 213), "Description:", fill="#9d9781", font=font_label)
127
+ draw.multiline_text((520, 229), get_wrapped_text(args.description, font_desc, 182), fill="#ffffff", font=font_desc)
128
+
129
+ cover = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
130
+ cover.close()
131
+ try:
132
+ canvas.save(cover.name, "PNG")
133
+ subprocess.run([
134
+ assets["ffmpeg"], "-loop", "1", "-framerate", "10", "-i", cover.name, "-i", args.audio,
135
+ "-map", "0", "-map", "1:a", "-c:v", "libx264", "-tune", "stillimage", "-preset", "ultrafast",
136
+ "-c:a", "aac", "-b:a", "96k", "-max_interleave_delta", "100M", "-vf", "fps=10,format=yuv420p",
137
+ "-shortest", "-y", args.output,
138
+ ], check=True)
139
+ finally:
140
+ Path(cover.name).unlink(missing_ok=True)
141
+
142
+
143
+ def main():
144
+ parser = argparse.ArgumentParser()
145
+ subparsers = parser.add_subparsers(dest="command", required=True)
146
+ fetch_assets = subparsers.add_parser("fetch-assets")
147
+ fetch_assets.add_argument("--platform", choices=FFMPEG_URLS)
148
+ fetch_assets.add_argument("--force", action="store_true")
149
+ make = subparsers.add_parser("make")
150
+ make.add_argument("-i", "--image", required=True)
151
+ make.add_argument("-a", "--audio", required=True)
152
+ make.add_argument("-d", "--description", required=True)
153
+ make.add_argument("-o", "--output", required=True)
154
+ make.add_argument("--receiver", default="MALAHIT DSP3")
155
+ make.add_argument("--antenna", default="")
156
+ make.add_argument("--location", default="")
157
+ args = parser.parse_args()
158
+ if args.command == "fetch-assets":
159
+ for key, path in ensure_assets(args.platform, args.force).items():
160
+ print(f"{key}: {path}")
161
+ elif args.command == "make":
162
+ make_clip(args)
163
+