]> git.poda.fr Git - converter.git/commitdiff
Stop copy from preserving modification timestamp
authorJulien <None>
Thu, 8 Oct 2026 09:34:31 +0000 (11:34 +0200)
committerJulien <None>
Thu, 8 Oct 2026 09:34:31 +0000 (11:34 +0200)
converter.py

index 4d8e9f26af9b83f799ad47e3b7e91ba9f6816d10..f5d8c856ebe201cd1a36d3398523deb6a05f1729 100755 (executable)
@@ -27,16 +27,16 @@ import collections.abc
 import filecmp # diff
 import os
 import queue
-import shutil # copy2
+import shutil # copy
 import signal
 import subprocess
 import sys
 import threading
 import typing
-import urllib.parse # Decode XSPF URL formatted lines
-import xml.etree.ElementTree # Read XSPF files
+import urllib.parse # Decode XSPF URL formatted lines.
+import xml.etree.ElementTree # Read XSPF files.
 
-# GUI
+# GUI.
 import tkinter as tk
 import tkinter.filedialog as tkfd
 import tkinter.scrolledtext as tkst
@@ -77,39 +77,41 @@ class ConvertProfile:
         self.converterArgs: list[str] = list()
 
     def init(self, profileName: str) -> bool:
+        commonConvertExtensions: list[str] = [".aif", ".aiff", ".fla", ".flac", ".wav"]
+        commonCopyExtensions: list[str] = [".aac", ".mp3", ".mp4"]
+
         # "-n" to prevent overwriting any existing file.
         # "-ar 44100" for 44.1 kHz audio output.
         # "-codec:v copy" to copy the integrated image from source
         #                 instead of converting it to png (default encoder).
-        commonFlags: list[str] = ["-loglevel", "warning", "-n",
-                                  "-ar", "44100", "-codec:v", "copy"]
+        commonArgs: list[str] = ["-loglevel", "warning", "-n", "-ar", "44100", "-codec:v", "copy"]
 
         # "-sample_fmt s16" for 16 bits audio output.
         # "-write_id3v2 1" to write metadata in aiff files.
         if profileName == "aiff":
             self.name = "aiff"
             self.targetExtension = ".aiff"
-            self.convertExtensions = [".aiff", ".flac", ".wav"]
-            self.copyExtensions = [".mp3"]
-            self.converterArgs = (commonFlags
+            self.convertExtensions = commonConvertExtensions
+            self.copyExtensions = commonCopyExtensions
+            self.converterArgs = (commonArgs
                                   + ["-f", "aiff", "-sample_fmt", "s16", "-write_id3v2", "1"])
             return True
         # "-sample_fmt s16" for 16 bits audio output.
         elif profileName == "flac":
             self.name = "flac"
             self.targetExtension = ".flac"
-            self.convertExtensions = [".aiff", ".flac", ".wav"]
-            self.copyExtensions = [".mp3"]
-            self.converterArgs = (commonFlags
+            self.convertExtensions = commonConvertExtensions
+            self.copyExtensions = commonCopyExtensions
+            self.converterArgs = (commonArgs
                                   + ["-f", "flac", "-sample_fmt", "s16"])
             return True
         # "-b:a 320k" for CBR 320 kbps.
         elif profileName == "mp3":
             self.name = "mp3"
             self.targetExtension = ".mp3"
-            self.convertExtensions = [".aiff", ".flac", ".wav"]
-            self.copyExtensions = [".mp3"]
-            self.converterArgs = (commonFlags
+            self.convertExtensions = commonConvertExtensions
+            self.copyExtensions = commonCopyExtensions
+            self.converterArgs = (commonArgs
                                   + ["-f", "mp3", "-b:a", "320k"])
             return True
         else:
@@ -507,7 +509,8 @@ class Converter:
                 command, capture_output=True, text=True)
 
             if result.returncode != 0:
-                self._log("Error from converter on file \"" + task.inputFilePath + "\": " + result.stderr)
+                self._log("Error from converter on file \""
+                          + task.inputFilePath + "\": " + result.stderr)
                 stats.errors += 1
             else:
                 if len(result.stderr) != 0:
@@ -720,7 +723,7 @@ class Converter:
         os.makedirs(dirPath, exist_ok=True)
 
     def copyFile(self, oriFilePath: str, newFilePath: str) -> None:
-        shutil.copy2(oriFilePath, newFilePath)
+        shutil.copy(oriFilePath, newFilePath)
 
     # Compare last modification date.
     def isFileChanged(self, sourceFilePath: str,