Explorar o código

add overburn flag to cdrecord + fix process kill on win32 + fix path handling for win32 + fix empty segment file handling for uploading sermon

Noah Vogt hai 9 meses
pai
achega
6f99ae7fd7
Modificáronse 6 ficheiros con 43 adicións e 16 borrados
  1. 1 0
      os_agnostic/__init__.py
  2. 28 0
      os_agnostic/tasks.py
  3. 1 1
      recording/cd.py
  4. 10 4
      recording/sermon.py
  5. 1 8
      set_cd_marker.py
  6. 2 3
      stop_cd_recording.py

+ 1 - 0
os_agnostic/__init__.py

@@ -14,3 +14,4 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from .cd import eject_drive, get_cd_drives, get_cdrecord_devname
+from .tasks import kill_process

+ 28 - 0
os_agnostic/tasks.py

@@ -0,0 +1,28 @@
+# Copyright © 2024 Noah Vogt <noah@noahvogt.com>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+if os.name == "nt":
+    from signal import SIGTERM
+else:
+    from subprocess import call
+
+
+def kill_process(pid: int) -> None:
+    if os.name == "nt":
+        call(["taskkill", "/F", "/T", "/PID", str(pid)])
+    else:
+        os.kill(pid, SIGTERM)

+ 1 - 1
recording/cd.py

@@ -55,7 +55,7 @@ def get_burn_cmd(cd_drive: str, yyyy_mm_dd, padded_zfill_num: str) -> str:
     )
     return (
         f"cdrecord -pad dev={get_cdrecord_devname(cd_drive)} -dao -swab "
-        + f"-text -audio -cuefile='{cue_sheet_path}'"
+        + f"-text -audio -overburn -cuefile='{cue_sheet_path}'"
     )
 
 

+ 10 - 4
recording/sermon.py

@@ -90,7 +90,7 @@ def get_audio_base_path_from_segment(segment: SermonSegment) -> str:
 
 def make_sermon_mp3(source_audio: str, target_audio: str) -> None:
     log("Generating final mp3...")
-    cmd = "ffmpeg -y -i {} -acodec libmp3lame {}".format(
+    cmd = "ffmpeg -y -i \"{}\" -acodec libmp3lame \"{}\"".format(
         source_audio,
         target_audio,
     )
@@ -108,11 +108,17 @@ def make_sermon_mp3(source_audio: str, target_audio: str) -> None:
 
 def generate_wav_for_segment(segment: SermonSegment) -> None:
     cmd = (
-        f"ffmpeg -y -i {get_full_wav_path(segment)} -ss "
+        f"ffmpeg -y -i \"{get_full_wav_path(segment)}\" -ss "
         + f" {get_ffmpeg_timestamp_from_frame(segment.start_frame)} "
         + f"-to {get_ffmpeg_timestamp_from_frame(segment.end_frame)} "
-        + f"-acodec copy {get_audio_base_path_from_segment(segment)}.wav"
+        + f"-acodec copy \"{get_audio_base_path_from_segment(segment)}.wav\""
     )
+    if segment.start_frame >= segment.end_frame:
+        log("Empty segment detected, generating silent 1 sec wav in place...")
+        cmd = (
+            "ffmpeg -y -f lavfi -i anullsrc=r=11025:cl=mono -t 1 "
+            + f"\"{get_audio_base_path_from_segment(segment)}.wav\""
+        )
     process = Popen(split(cmd))
     _ = process.communicate()[0]  # wait for subprocess to end
     if process.returncode not in [255, 0]:
@@ -347,7 +353,7 @@ def create_concat_file(file_path: str, wave_paths: list[str]) -> None:
 
 
 def merge_files_with_ffmpeg(concat_file_path, target_dir) -> None:
-    cmd = "ffmpeg -y -f concat -safe 0 -i {} -acodec copy {}".format(
+    cmd = "ffmpeg -y -f concat -safe 0 -i \"{}\" -acodec copy \"{}\"".format(
         concat_file_path,
         path.join(target_dir, "merged.wav"),
     )

+ 1 - 8
set_cd_marker.py

@@ -74,7 +74,7 @@ def start_cd_recording() -> None:
         unix_milis = get_unix_milis()
 
         log(f"starting cd #{cd_num} recording...")
-        cmd = "ffmpeg -y {} -ar 44100 -t {} {}".format(
+        cmd = 'ffmpeg -y {} -ar 44100 -t {} "{}"'.format(
             const.CD_RECORD_FFMPEG_INPUT_ARGS,
             const.CD_RECORD_MAX_SECONDS,
             filename,
@@ -115,13 +115,6 @@ def start_cd_recording() -> None:
         cd_num += 1
         if process.returncode not in [255, 0]:
             mark_end_of_recording(cachefile_content)
-            app = QApplication
-            InfoMsgBox(
-                QMessageBox.Critical,
-                "Error",
-                f"ffmpeg terminated with exit code {process.returncode}",
-            )
-            del app
             sys.exit(1)
 
 

+ 2 - 3
stop_cd_recording.py

@@ -16,8 +16,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
-from os import kill
-from signal import SIGTERM
 from time import sleep
 
 import colorama
@@ -37,6 +35,7 @@ from utils import (
 from input import get_cachefile_content, validate_cd_record_config
 import config as const
 from recording import is_valid_cd_record_checkfile, mark_end_of_recording
+from os_agnostic import kill_process
 
 
 def stop_cd_recording() -> None:
@@ -56,7 +55,7 @@ def stop_cd_recording() -> None:
             sleep(milis_diff / 1000 + 1)
 
         try:
-            kill(int(cachefile_content[2]), SIGTERM)
+            kill_process(int(cachefile_content[2]))
         except ProcessLookupError:
             app = QApplication
             InfoMsgBox(