better-ffmpeg-progress 3.2.5__tar.gz → 3.2.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 3.2.5
3
+ Version: 3.2.6
4
4
  Summary: Run FFmpeg & see percentage progress + ETA.
5
5
  Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
6
  Author: GitHub.com/CrypticSignal
@@ -61,27 +61,26 @@ class FfmpegProcess:
61
61
  return True
62
62
 
63
63
  def _should_overwrite(self):
64
- if self._output_filepath.exists() and "-y" not in self._ffmpeg_command:
65
- try:
66
- if (
67
- input(
68
- f"{self._output_filepath} already exists. Overwrite? [Y/N]: "
69
- ).lower()
70
- != "y"
71
- ):
72
- print(
73
- "FFmpeg process cancelled. Output file exists and overwrite declined."
74
- )
75
- return False
76
- except EOFError:
77
- print("Input error. FFmpeg process cancelled.")
78
- return False
79
- except KeyboardInterrupt:
80
- print("[KeyboardInterrupt] FFmpeg process cancelled.")
64
+ try:
65
+ if (
66
+ input(
67
+ f"{self._output_filepath} already exists. Overwrite? [Y/N]: "
68
+ ).lower()
69
+ != "y"
70
+ ):
71
+ print(
72
+ "FFmpeg process cancelled. Output file exists and overwrite declined."
73
+ )
81
74
  return False
75
+ except EOFError:
76
+ print("Input error. FFmpeg process cancelled.")
77
+ return False
78
+ except KeyboardInterrupt:
79
+ print("[KeyboardInterrupt] FFmpeg process cancelled.")
80
+ return False
82
81
 
83
- self._ffmpeg_command.insert(1, "-y")
84
- return True
82
+ self._ffmpeg_command.insert(1, "-y")
83
+ return True
85
84
 
86
85
  @staticmethod
87
86
  def _get_duration(filepath: Path) -> Optional[float]:
@@ -155,9 +154,9 @@ class FfmpegProcess:
155
154
  ]
156
155
  self._ffmpeg_command.extend(command[1:])
157
156
 
158
- if not self._should_overwrite():
159
- self._return_code = 1
160
- return
157
+ if self._output_filepath.exists() and "-y" not in self._ffmpeg_command:
158
+ if not self._should_overwrite():
159
+ self._return_code = 1
161
160
 
162
161
  def _use_rich(self, process) -> int:
163
162
  task_id = None
@@ -301,13 +300,10 @@ class FfmpegProcess:
301
300
  else self._use_rich(self._process)
302
301
  )
303
302
  except KeyboardInterrupt:
304
- print("\n[KeyboardInterrupt] Terminating FFmpeg process...")
303
+ print("\n[KeyboardInterrupt] Terminating the FFmpeg process...")
305
304
  self._terminate()
306
- print("Done!")
305
+ print("Exiting Better FFmpeg Progress.")
307
306
  return 1
308
- finally:
309
- if self._process and self._process.poll() is None:
310
- self._terminate()
311
307
 
312
308
  def _terminate(self):
313
309
  if not self._process or self._process.poll() is not None:
@@ -315,37 +311,60 @@ class FfmpegProcess:
315
311
 
316
312
  try:
317
313
  proc = psutil.Process(self._process.pid)
318
- children = proc.children(recursive=True)
319
-
320
- # Windows. Use CTRL_BREAK_EVENT to terminate entire process group
321
- if os.name == "nt":
322
- if self._shell_needed:
323
- # If running under a shell, terminate shell first
324
- proc.terminate()
325
- else:
326
- from signal import CTRL_BREAK_EVENT
327
-
328
- # Send CTRL_BREAK_EVENT to entire process group
329
- os.kill(self._process.pid, CTRL_BREAK_EVENT)
330
- # Unix
331
- else:
332
- for child in children:
333
- try:
334
- child.terminate()
335
- except psutil.NoSuchProcess:
336
- pass
314
+ except (psutil.NoSuchProcess, psutil.ZombieProcess):
315
+ return
316
+
317
+ children = proc.children(recursive=True)
318
+ if children:
319
+ print(f"Found {len(children)} child process(es).")
320
+
321
+ # Windows
322
+ if os.name == "nt":
323
+ try:
324
+ # On Windows, terminate() and kill() are equivalent
337
325
  proc.terminate()
326
+ except psutil.NoSuchProcess:
327
+ return
328
+ except psutil.AccessDenied:
329
+ print("Permission error when trying to terminate the FFmpeg process.")
330
+ return
331
+
332
+ # Unix/Linux/macOS
333
+ from signal import SIGTERM, SIGKILL
334
+
335
+ try:
336
+ pgid = os.getpgid(self._process.pid)
337
+ print(f"Sending SIGTERM to process group {pgid}...")
338
+ os.killpg(pgid, SIGTERM)
339
+ except OSError:
340
+ print("Failed to send SIGTERM to process group.")
338
341
 
339
- # Wait up to 1 second for processes to exit gracefully
340
- gone, still_alive = psutil.wait_procs(children + [proc], timeout=1)
342
+ try:
343
+ proc.wait(timeout=0.5)
344
+ except subprocess.TimeoutExpired:
345
+ print(
346
+ "The FFmpeg process did not exit within 0.5s after SIGTERM, sending SIGKILL..."
347
+ )
348
+ try:
349
+ os.killpg(pgid, SIGKILL)
350
+ except OSError:
351
+ print("Failed to send SIGKILL to process group.")
341
352
 
342
- # Force kill any remaining processes
343
- for p in still_alive:
353
+ for child in children:
354
+ if child.is_running():
355
+ print(f"Force killing child process {child.pid}...")
344
356
  try:
345
- p.kill()
357
+ child.kill()
346
358
  except psutil.NoSuchProcess:
347
359
  pass
360
+ except psutil.AccessDenied:
361
+ print("Permission error when trying to kill the FFmpeg process.")
348
362
 
349
- except (psutil.NoSuchProcess, ProcessLookupError, KeyboardInterrupt):
350
- # As a last resort, force kill the main process
351
- self._process.kill()
363
+ if self._process.poll() is None:
364
+ print("Force killing the FFmpeg process...")
365
+ try:
366
+ proc.kill()
367
+ except psutil.NoSuchProcess:
368
+ pass
369
+ except psutil.AccessDenied:
370
+ print("Permission error when trying to kill the FFmpeg process.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: better-ffmpeg-progress
3
- Version: 3.2.5
3
+ Version: 3.2.6
4
4
  Summary: Run FFmpeg & see percentage progress + ETA.
5
5
  Home-page: https://github.com/CrypticSignal/better-ffmpeg-progress
6
6
  Author: GitHub.com/CrypticSignal
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
5
5
 
6
6
  setuptools.setup(
7
7
  name="better-ffmpeg-progress",
8
- version="3.2.5",
8
+ version="3.2.6",
9
9
  author="GitHub.com/CrypticSignal",
10
10
  author_email="theaudiophile@outlook.com",
11
11
  description="Run FFmpeg & see percentage progress + ETA.",