Skip to content

Commit 759d3b8

Browse files
authored
Remove unused combine_subtitles functionality (#69)
* chore: Remove unused combine_subtitles functionality - Remove src/sub_tools/subtitles/combiner.py - Remove paths_with_offsets() from system/directory.py - Remove TestPathsWithOffsets class from test_directory.py - Remove unused 're' import from directory.py Fixes #67 * chore: Remove unused python-ffmpeg dependency The codebase uses ffmpeg via subprocess, not the python-ffmpeg package.
1 parent d34ffda commit 759d3b8

File tree

5 files changed

+4
-238
lines changed

5 files changed

+4
-238
lines changed

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ dependencies = [
1111
"pycountry>=24.6.1",
1212
"pysrt>=1.1.2",
1313
"pytest>=9.0.1",
14-
"pytest-asyncio>=1.2.0",
15-
"python-ffmpeg>=2.0.12",
16-
"rich>=14.2.0",
14+
"pytest-asyncio>=0.23.5",
15+
"rich>=13.9.4",
1716
"whisperx>=3.1.1",
1817
]
1918

src/sub_tools/subtitles/combiner.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/sub_tools/system/directory.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import hashlib
66
import os
7-
import re
87
import tempfile
98

109

@@ -86,20 +85,3 @@ def get_cached_file_path(
8685
"""
8786
temp_dir = get_temp_directory(url, subfolder)
8887
return os.path.join(temp_dir, filename)
89-
90-
91-
def paths_with_offsets(
92-
prefix: str, file_format: str, directory: str = "."
93-
) -> list[tuple[str, int]]:
94-
"""
95-
Returns a list of paths with offsets, sorted numerically by offset.
96-
"""
97-
pattern = rf"{prefix}_(\d+)\.{file_format}"
98-
paths = [
99-
(path, int(match.group(1)))
100-
for path in os.listdir(directory)
101-
for match in [re.match(pattern, path)]
102-
if match and match.group(1)
103-
]
104-
# Sort by numeric offset, not alphabetically
105-
return sorted(paths, key=lambda x: x[1])

tests/test_directory.py

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
get_cached_file_path,
1515
get_temp_directory,
1616
get_url_hash,
17-
paths_with_offsets,
1817
)
1918

2019

@@ -287,119 +286,3 @@ def test_works_with_none_url(self):
287286
temp_dir = os.path.dirname(file_path)
288287
if os.path.exists(temp_dir):
289288
os.rmdir(temp_dir)
290-
291-
292-
class TestPathsWithOffsets:
293-
"""Tests for paths_with_offsets function."""
294-
295-
def test_returns_empty_list_for_empty_directory(self, tmp_path):
296-
"""Test that returns empty list when no matching files."""
297-
result = paths_with_offsets("prefix", "mp3", str(tmp_path))
298-
assert result == []
299-
300-
def test_finds_files_with_offsets(self, tmp_path):
301-
"""Test that finds files with numeric offsets."""
302-
# Create test files
303-
(tmp_path / "audio_0.mp3").touch()
304-
(tmp_path / "audio_5000.mp3").touch()
305-
(tmp_path / "audio_10000.mp3").touch()
306-
307-
result = paths_with_offsets("audio", "mp3", str(tmp_path))
308-
309-
assert len(result) == 3
310-
assert ("audio_0.mp3", 0) in result
311-
assert ("audio_5000.mp3", 5000) in result
312-
assert ("audio_10000.mp3", 10000) in result
313-
314-
def test_returns_sorted_list(self, tmp_path):
315-
"""Test that returns files in sorted order by numeric offset."""
316-
# Create files in random order
317-
(tmp_path / "seg_10000.wav").touch()
318-
(tmp_path / "seg_0.wav").touch()
319-
(tmp_path / "seg_5000.wav").touch()
320-
321-
result = paths_with_offsets("seg", "wav", str(tmp_path))
322-
323-
# Should be sorted numerically by offset, not alphabetically
324-
assert result[0] == ("seg_0.wav", 0)
325-
assert result[1] == ("seg_5000.wav", 5000)
326-
assert result[2] == ("seg_10000.wav", 10000)
327-
328-
def test_ignores_non_matching_files(self, tmp_path):
329-
"""Test that ignores files that don't match pattern."""
330-
(tmp_path / "audio_0.mp3").touch()
331-
(tmp_path / "audio_5000.mp3").touch()
332-
(tmp_path / "other_file.mp3").touch()
333-
(tmp_path / "audio.mp3").touch()
334-
(tmp_path / "audio_abc.mp3").touch()
335-
336-
result = paths_with_offsets("audio", "mp3", str(tmp_path))
337-
338-
assert len(result) == 2
339-
assert all("audio_" in path for path, _ in result)
340-
341-
def test_matches_different_prefixes(self, tmp_path):
342-
"""Test matching with different prefixes."""
343-
(tmp_path / "video_0.mp4").touch()
344-
(tmp_path / "audio_0.mp3").touch()
345-
346-
video_result = paths_with_offsets("video", "mp4", str(tmp_path))
347-
audio_result = paths_with_offsets("audio", "mp3", str(tmp_path))
348-
349-
assert len(video_result) == 1
350-
assert len(audio_result) == 1
351-
assert video_result[0][0] == "video_0.mp4"
352-
assert audio_result[0][0] == "audio_0.mp3"
353-
354-
def test_matches_different_formats(self, tmp_path):
355-
"""Test matching with different file formats."""
356-
(tmp_path / "seg_0.mp3").touch()
357-
(tmp_path / "seg_0.wav").touch()
358-
(tmp_path / "seg_0.srt").touch()
359-
360-
mp3_result = paths_with_offsets("seg", "mp3", str(tmp_path))
361-
wav_result = paths_with_offsets("seg", "wav", str(tmp_path))
362-
srt_result = paths_with_offsets("seg", "srt", str(tmp_path))
363-
364-
assert len(mp3_result) == 1
365-
assert len(wav_result) == 1
366-
assert len(srt_result) == 1
367-
368-
def test_handles_large_offsets(self, tmp_path):
369-
"""Test handling of large offset numbers."""
370-
(tmp_path / "seg_999999999.mp3").touch()
371-
372-
result = paths_with_offsets("seg", "mp3", str(tmp_path))
373-
374-
assert len(result) == 1
375-
assert result[0][1] == 999999999
376-
377-
def test_uses_current_directory_by_default(self):
378-
"""Test that uses current directory when no directory specified."""
379-
original_dir = os.getcwd()
380-
temp_dir = tempfile.mkdtemp()
381-
382-
try:
383-
os.chdir(temp_dir)
384-
# Create test file
385-
with open("test_0.txt", "w") as f:
386-
f.write("test")
387-
388-
result = paths_with_offsets("test", "txt")
389-
assert len(result) == 1
390-
assert result[0][0] == "test_0.txt"
391-
392-
finally:
393-
os.chdir(original_dir)
394-
shutil.rmtree(temp_dir)
395-
396-
def test_offset_as_int(self, tmp_path):
397-
"""Test that offset is returned as int for proper numeric sorting."""
398-
(tmp_path / "audio_12345.mp3").touch()
399-
400-
result = paths_with_offsets("audio", "mp3", str(tmp_path))
401-
402-
assert len(result) == 1
403-
path, offset = result[0]
404-
assert isinstance(offset, int)
405-
assert offset == 12345

uv.lock

Lines changed: 2 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)