Skip to content

The only downloader you need. 下载器的集大成者。

Closes #349

XiaoYouChR7201ee2f35e4
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index dc13d72c..a03b7b66 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -4,7 +4,7 @@ import traceback
from time import localtime, strftime, time
from loguru import logger
-from PySide6.QtCore import QStandardPaths
+from app.supports.paths import APP_DATA_DIR
# import orjson
# sys.modules['json'] = orjson
@@ -25,8 +25,7 @@ def exceptionHook(exceptionType, value, tb):
if "__compiled__" not in globals():
sys.__excepthook__(*exceptionInfo)
-appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)
-logger.add(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log", rotation="512 KB", enqueue=True)
+logger.add(f"{APP_DATA_DIR}/GhostDownloader.log", rotation="512 KB", enqueue=True)
sys.excepthook = exceptionHook
from qfluentwidgets import qconfig, setTheme
@@ -40,7 +39,7 @@ logger.info(
strftime("%Y-%m-%d %H:%M:%S", localtime(time())),
)
-qconfig.load(f"{appLocalDataLocation}/GhostDownloader/UserConfig.json", cfg)
+qconfig.load(f"{APP_DATA_DIR}/UserConfig.json", cfg)
if cfg.get(cfg.dpiScale) != 0:
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
diff --git a/app/supports/paths.py b/app/supports/paths.py
new file mode 100644
index 00000000..e4f1405b
--- /dev/null
+++ b/app/supports/paths.py
@@ -0,0 +1,11 @@
+import sys
+from pathlib import Path
+
+from PySide6.QtCore import QStandardPaths
+
+_executableDir = Path(sys.argv[0]).resolve().parent
+APP_DATA_DIR: str = (
+ str(_executableDir / "GhostDownloader")
+ if (_executableDir / "GhostDownloader").is_dir()
+ else f"{QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)}/GhostDownloader"
+)
diff --git a/app/supports/recorder.py b/app/supports/recorder.py
index 094545bd..9c05a06e 100644
--- a/app/supports/recorder.py
+++ b/app/supports/recorder.py
@@ -1,17 +1,16 @@
from pathlib import Path
import orjson
-from PySide6.QtCore import QStandardPaths
from loguru import logger
from app.bases.models import Task
+from app.supports.paths import APP_DATA_DIR
class TaskRecorder:
def __init__(self):
- appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)
- self.recordFile = Path(f"{appLocalDataLocation}/GhostDownloader/Memory.log")
+ self.recordFile = Path(APP_DATA_DIR) / "Memory.log"
if not self.recordFile.exists():
self.recordFile.parent.mkdir(parents=True, exist_ok=True)
self.recordFile.touch()
diff --git a/app/supports/utils.py b/app/supports/utils.py
index 26bbe650..d9d25efd 100644
--- a/app/supports/utils.py
+++ b/app/supports/utils.py
@@ -9,12 +9,13 @@ from typing import TYPE_CHECKING, Callable
from http.cookiejar import CookieJar
from niquests.cookies import RequestsCookieJar, cookiejar_from_dict
from urllib.request import getproxies
-from PySide6.QtCore import QUrl, Qt, QProcess, QStandardPaths
+from PySide6.QtCore import QUrl, Qt, QProcess
from PySide6.QtGui import QDesktopServices
from loguru import logger
from qfluentwidgets import MessageBox, ToolButton, FluentIcon
from app.supports.config import cfg
+from app.supports.paths import APP_DATA_DIR
if TYPE_CHECKING:
from app.bases.models import Task
@@ -102,8 +103,7 @@ def openFolder(path):
def openAppLogFolder():
- appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)
- openFolder(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log")
+ openFolder(f"{APP_DATA_DIR}/GhostDownloader.log")
def getProxies():
diff --git a/features/ffmpeg_pack/config.py b/features/ffmpeg_pack/config.py
index fbfc4bb7..a614a834 100644
--- a/features/ffmpeg_pack/config.py
+++ b/features/ffmpeg_pack/config.py
@@ -4,7 +4,7 @@ import sys
from pathlib import Path
from typing import TYPE_CHECKING
-from PySide6.QtCore import QStandardPaths, Qt, Signal
+from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QFileDialog
from qfluentwidgets import (
ConfigItem,
@@ -18,6 +18,7 @@ from qfluentwidgets import (
from app.bases.models import PackConfig
from app.services.core_service import coreService
from app.supports.config import cfg
+from app.supports.paths import APP_DATA_DIR
from app.supports.utils import toExecutable, toPosixPath
if TYPE_CHECKING:
@@ -106,7 +107,7 @@ class FFmpegInstallFolderCard(SettingCard):
self._updatePath(folder)
def _restoreDefault(self):
- self._updatePath(f"{QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)}/GhostDownloader/FFmpeg")
+ self._updatePath(f"{APP_DATA_DIR}/FFmpeg")
class FFmpegRuntimeCard(SettingCard):
@@ -169,7 +170,7 @@ class FFmpegRuntimeCard(SettingCard):
class FFmpegConfig(PackConfig):
- installFolder = ConfigItem("FFmpeg", "InstallFolder", f"{QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)}/GhostDownloader/FFmpeg", FolderValidator())
+ installFolder = ConfigItem("FFmpeg", "InstallFolder", f"{APP_DATA_DIR}/FFmpeg", FolderValidator())
def setupSettings(self, settingPage: "SettingPage"):
self.ffmpegGroup = SettingCardGroup(self.tr("FFmpeg"), settingPage.container)
diff --git a/features/m3u8_pack/config.py b/features/m3u8_pack/config.py
index 1ecdb601..0cda560d 100644
--- a/features/m3u8_pack/config.py
+++ b/features/m3u8_pack/config.py
@@ -4,7 +4,7 @@ import sys
from pathlib import Path
from typing import TYPE_CHECKING
-from PySide6.QtCore import QStandardPaths, Qt, Signal
+from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QFileDialog
from qfluentwidgets import (
BoolValidator,
@@ -29,6 +29,7 @@ from qfluentwidgets import (
from app.bases.models import PackConfig
from app.services.core_service import coreService
from app.supports.config import cfg
+from app.supports.paths import APP_DATA_DIR
from app.supports.utils import toExecutable, toPosixPath
from app.view.components.setting_cards import SpinBoxSettingCard
@@ -114,7 +115,7 @@ class M3U8InstallFolderCard(SettingCard):
self._updatePath(folder)
def _restoreDefault(self):
- defaultPath = f"{QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)}/GhostDownloader/M3U8DL"
+ defaultPath = f"{APP_DATA_DIR}/M3U8DL"
self._updatePath(defaultPath)
@@ -181,7 +182,7 @@ class M3U8Config(PackConfig):
installFolder = ConfigItem(
"M3U8",
"InstallFolder",
- f"{QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)}/GhostDownloader/M3U8DL",
+ f"{APP_DATA_DIR}/M3U8DL",
FolderValidator(),
)
outputFormat = OptionsConfigItem("M3U8", "OutputFormat", "mp4", OptionsValidator(["mp4", "mkv"]))