Centralize file extension constants in ytsage_constants
Moved video, audio, and subtitle file extension lists to ytsage_constants.py as centralized frozenset constants. Updated all usages in downloader and GUI modules to reference these constants, reducing duplication and improving maintainability.
This commit is contained in:
@@ -12,7 +12,13 @@ from typing import Optional, List, Set
|
|||||||
from PySide6.QtCore import QObject, QThread, Signal
|
from PySide6.QtCore import QObject, QThread, Signal
|
||||||
|
|
||||||
from src.core.ytsage_yt_dlp import get_yt_dlp_path
|
from src.core.ytsage_yt_dlp import get_yt_dlp_path
|
||||||
from src.utils.ytsage_constants import SUBPROCESS_CREATIONFLAGS
|
from src.utils.ytsage_constants import (
|
||||||
|
SUBPROCESS_CREATIONFLAGS,
|
||||||
|
VIDEO_EXTENSIONS,
|
||||||
|
AUDIO_EXTENSIONS,
|
||||||
|
SUBTITLE_EXTENSIONS,
|
||||||
|
MEDIA_EXTENSIONS,
|
||||||
|
)
|
||||||
from src.utils.ytsage_localization import LocalizationManager
|
from src.utils.ytsage_localization import LocalizationManager
|
||||||
from src.utils.ytsage_logger import logger
|
from src.utils.ytsage_logger import logger
|
||||||
|
|
||||||
@@ -444,10 +450,6 @@ class DownloadThread(QThread):
|
|||||||
final_file_found = False
|
final_file_found = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Define video/audio extensions
|
|
||||||
video_audio_extensions = {'.mp4', '.webm', '.mkv', '.avi', '.mov', '.flv',
|
|
||||||
'.m4a', '.mp3', '.opus', '.flac', '.aac', '.wav', '.ogg'}
|
|
||||||
|
|
||||||
# First, check if last_file_path exists and is valid
|
# First, check if last_file_path exists and is valid
|
||||||
if self.last_file_path:
|
if self.last_file_path:
|
||||||
last_path = Path(self.last_file_path)
|
last_path = Path(self.last_file_path)
|
||||||
@@ -463,7 +465,7 @@ class DownloadThread(QThread):
|
|||||||
potential_files = []
|
potential_files = []
|
||||||
|
|
||||||
# Search in download directory and subdirectories (for playlists)
|
# Search in download directory and subdirectories (for playlists)
|
||||||
for ext in video_audio_extensions:
|
for ext in MEDIA_EXTENSIONS:
|
||||||
potential_files.extend(self.path.glob(f'*{ext}'))
|
potential_files.extend(self.path.glob(f'*{ext}'))
|
||||||
# Also check subdirectories (for playlist downloads)
|
# Also check subdirectories (for playlist downloads)
|
||||||
potential_files.extend(self.path.glob(f'*/*{ext}'))
|
potential_files.extend(self.path.glob(f'*/*{ext}'))
|
||||||
@@ -563,13 +565,13 @@ class DownloadThread(QThread):
|
|||||||
if is_audio_download or "Downloading audio" in line:
|
if is_audio_download or "Downloading audio" in line:
|
||||||
self.status_signal.emit(_("download.downloading_audio"))
|
self.status_signal.emit(_("download.downloading_audio"))
|
||||||
# Video file extensions with likely video content
|
# Video file extensions with likely video content
|
||||||
elif ext in [".mp4", ".webm", ".mkv", ".avi", ".mov", ".flv"]:
|
elif ext in VIDEO_EXTENSIONS:
|
||||||
self.status_signal.emit(_("download.downloading_video"))
|
self.status_signal.emit(_("download.downloading_video"))
|
||||||
# Audio file extensions
|
# Audio file extensions
|
||||||
elif ext in [".mp3", ".m4a", ".aac", ".wav", ".ogg", ".opus", ".flac"]:
|
elif ext in AUDIO_EXTENSIONS:
|
||||||
self.status_signal.emit(_("download.downloading_audio"))
|
self.status_signal.emit(_("download.downloading_audio"))
|
||||||
# Subtitle file extensions
|
# Subtitle file extensions
|
||||||
elif ext in [".vtt", ".srt", ".ass", ".ssa"]:
|
elif ext in SUBTITLE_EXTENSIONS:
|
||||||
self.status_signal.emit(_("download.downloading_subtitle"))
|
self.status_signal.emit(_("download.downloading_subtitle"))
|
||||||
# Default case
|
# Default case
|
||||||
else:
|
else:
|
||||||
@@ -704,11 +706,11 @@ class DownloadThread(QThread):
|
|||||||
# Determine file type based on extension for existing file message
|
# Determine file type based on extension for existing file message
|
||||||
ext = Path(filename).suffix.lower()
|
ext = Path(filename).suffix.lower()
|
||||||
|
|
||||||
if ext in [".mp4", ".webm", ".mkv", ".avi", ".mov", ".flv"]:
|
if ext in VIDEO_EXTENSIONS:
|
||||||
self.status_signal.emit(f"⚠️ Video file already exists")
|
self.status_signal.emit(f"⚠️ Video file already exists")
|
||||||
elif ext in [".mp3", ".m4a", ".aac", ".wav", ".ogg", ".opus", ".flac"]:
|
elif ext in AUDIO_EXTENSIONS:
|
||||||
self.status_signal.emit(f"⚠️ Audio file already exists")
|
self.status_signal.emit(f"⚠️ Audio file already exists")
|
||||||
elif ext in [".vtt", ".srt", ".ass", ".ssa"]:
|
elif ext in SUBTITLE_EXTENSIONS:
|
||||||
self.status_signal.emit(f"⚠️ Subtitle file already exists")
|
self.status_signal.emit(f"⚠️ Subtitle file already exists")
|
||||||
else:
|
else:
|
||||||
self.status_signal.emit(f"⚠️ File already exists")
|
self.status_signal.emit(f"⚠️ File already exists")
|
||||||
@@ -725,13 +727,13 @@ class DownloadThread(QThread):
|
|||||||
ext = Path(self.current_filename).suffix.lower()
|
ext = Path(self.current_filename).suffix.lower()
|
||||||
|
|
||||||
# Video file extensions
|
# Video file extensions
|
||||||
if ext in [".mp4", ".webm", ".mkv", ".avi", ".mov", ".flv"]:
|
if ext in VIDEO_EXTENSIONS:
|
||||||
self.status_signal.emit(_("download.video_completed"))
|
self.status_signal.emit(_("download.video_completed"))
|
||||||
# Audio file extensions
|
# Audio file extensions
|
||||||
elif ext in [".mp3", ".m4a", ".aac", ".wav", ".ogg", ".opus", ".flac"]:
|
elif ext in AUDIO_EXTENSIONS:
|
||||||
self.status_signal.emit(_("download.audio_completed"))
|
self.status_signal.emit(_("download.audio_completed"))
|
||||||
# Subtitle file extensions
|
# Subtitle file extensions
|
||||||
elif ext in [".vtt", ".srt", ".ass", ".ssa"]:
|
elif ext in SUBTITLE_EXTENSIONS:
|
||||||
self.status_signal.emit(_("download.subtitle_completed"))
|
self.status_signal.emit(_("download.subtitle_completed"))
|
||||||
# Default case
|
# Default case
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -47,7 +47,14 @@ from src.gui.ytsage_gui_dialogs import ( # use of src\gui\ytsage_gui_dialogs\__
|
|||||||
from src.gui.ytsage_gui_format_table import FormatTableMixin
|
from src.gui.ytsage_gui_format_table import FormatTableMixin
|
||||||
from src.gui.ytsage_gui_video_info import VideoInfoMixin
|
from src.gui.ytsage_gui_video_info import VideoInfoMixin
|
||||||
from src.gui.ytsage_gui_analysis import AnalysisMixin
|
from src.gui.ytsage_gui_analysis import AnalysisMixin
|
||||||
from src.utils.ytsage_constants import ICON_PATH, SOUND_PATH, SUBPROCESS_CREATIONFLAGS
|
from src.utils.ytsage_constants import (
|
||||||
|
ICON_PATH,
|
||||||
|
SOUND_PATH,
|
||||||
|
SUBPROCESS_CREATIONFLAGS,
|
||||||
|
VIDEO_EXTENSIONS,
|
||||||
|
AUDIO_EXTENSIONS,
|
||||||
|
SUBTITLE_EXTENSIONS,
|
||||||
|
)
|
||||||
from src.utils.ytsage_logger import logger
|
from src.utils.ytsage_logger import logger
|
||||||
from src.utils.ytsage_config_manager import ConfigManager
|
from src.utils.ytsage_config_manager import ConfigManager
|
||||||
from src.utils.ytsage_localization import LocalizationManager, _
|
from src.utils.ytsage_localization import LocalizationManager, _
|
||||||
@@ -704,13 +711,13 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
|
|||||||
ext = filename.suffix.lower()
|
ext = filename.suffix.lower()
|
||||||
|
|
||||||
# Video file extensions
|
# Video file extensions
|
||||||
if ext in [".mp4", ".webm", ".mkv", ".avi", ".mov", ".flv"]:
|
if ext in VIDEO_EXTENSIONS:
|
||||||
self.status_label.setText(_('download.video_completed'))
|
self.status_label.setText(_('download.video_completed'))
|
||||||
# Audio file extensions
|
# Audio file extensions
|
||||||
elif ext in [".mp3", ".m4a", ".aac", ".wav", ".ogg", ".opus", ".flac"]:
|
elif ext in AUDIO_EXTENSIONS:
|
||||||
self.status_label.setText(_('download.audio_completed'))
|
self.status_label.setText(_('download.audio_completed'))
|
||||||
# Subtitle file extensions
|
# Subtitle file extensions
|
||||||
elif ext in [".vtt", ".srt", ".ass", ".ssa"]:
|
elif ext in SUBTITLE_EXTENSIONS:
|
||||||
self.status_label.setText(_('download.subtitle_completed'))
|
self.status_label.setText(_('download.subtitle_completed'))
|
||||||
# Default case
|
# Default case
|
||||||
else:
|
else:
|
||||||
@@ -1109,13 +1116,13 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin):
|
|||||||
ext = Path(filename).suffix.lower()
|
ext = Path(filename).suffix.lower()
|
||||||
|
|
||||||
# Video file extensions
|
# Video file extensions
|
||||||
if ext in [".mp4", ".webm", ".mkv", ".avi", ".mov", ".flv"]:
|
if ext in VIDEO_EXTENSIONS:
|
||||||
self.status_label.setText(_("status.video_file_exists"))
|
self.status_label.setText(_("status.video_file_exists"))
|
||||||
# Audio file extensions
|
# Audio file extensions
|
||||||
elif ext in [".mp3", ".m4a", ".aac", ".wav", ".ogg", ".opus", ".flac"]:
|
elif ext in AUDIO_EXTENSIONS:
|
||||||
self.status_label.setText(_("status.audio_file_exists"))
|
self.status_label.setText(_("status.audio_file_exists"))
|
||||||
# Subtitle file extensions
|
# Subtitle file extensions
|
||||||
elif ext in [".vtt", ".srt", ".ass", ".ssa"]:
|
elif ext in SUBTITLE_EXTENSIONS:
|
||||||
self.status_label.setText(_("status.subtitle_file_exists"))
|
self.status_label.setText(_("status.subtitle_file_exists"))
|
||||||
# Default case
|
# Default case
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -182,6 +182,30 @@ FFMPEG_ZIP_SHA256_URL = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essen
|
|||||||
FFMPEG_7Z_VERSION_URL = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z.ver"
|
FFMPEG_7Z_VERSION_URL = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z.ver"
|
||||||
FFMPEG_ZIP_VERSION_URL = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip.ver"
|
FFMPEG_ZIP_VERSION_URL = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip.ver"
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# File Extension Constants
|
||||||
|
# =============================================================================
|
||||||
|
# Centralized file extension definitions to avoid duplication across modules
|
||||||
|
# Use these constants for file type detection throughout the application
|
||||||
|
|
||||||
|
# Video file extensions (container formats that typically contain video)
|
||||||
|
VIDEO_EXTENSIONS: frozenset[str] = frozenset({
|
||||||
|
".mp4", ".webm", ".mkv", ".avi", ".mov", ".flv"
|
||||||
|
})
|
||||||
|
|
||||||
|
# Audio file extensions (audio-only formats)
|
||||||
|
AUDIO_EXTENSIONS: frozenset[str] = frozenset({
|
||||||
|
".mp3", ".m4a", ".aac", ".wav", ".ogg", ".opus", ".flac"
|
||||||
|
})
|
||||||
|
|
||||||
|
# Subtitle file extensions
|
||||||
|
SUBTITLE_EXTENSIONS: frozenset[str] = frozenset({
|
||||||
|
".vtt", ".srt", ".ass", ".ssa"
|
||||||
|
})
|
||||||
|
|
||||||
|
# Combined video and audio extensions (for file search operations)
|
||||||
|
MEDIA_EXTENSIONS: frozenset[str] = VIDEO_EXTENSIONS | AUDIO_EXTENSIONS
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# If this file is run directly, print directory information; if imported, create the necessary directories for the application.
|
# If this file is run directly, print directory information; if imported, create the necessary directories for the application.
|
||||||
# for debug, to check os specific variable which can be different based on os.
|
# for debug, to check os specific variable which can be different based on os.
|
||||||
|
|||||||
Reference in New Issue
Block a user