diff --git a/app/library/DownloadQueue.py b/app/library/DownloadQueue.py index 265d9054..cf355311 100644 --- a/app/library/DownloadQueue.py +++ b/app/library/DownloadQueue.py @@ -870,7 +870,7 @@ class DownloadQueue(metaclass=Singleton): ) continue - LOG.info(f"Re-queuing item '{item_ref} {item.info.extras=}' for download.") + LOG.info(f"Retrying item '{item_ref} {item.info.extras=}' for download.") try: await self.clear([item.info._id], remove_file=False) diff --git a/app/library/Notifications.py b/app/library/Notifications.py index e0ca7f91..39a9578b 100644 --- a/app/library/Notifications.py +++ b/app/library/Notifications.py @@ -137,7 +137,7 @@ class Notification(metaclass=Singleton): self._file: Path = Path(file) if file else Path(config.config_path).joinpath("notifications.json") self._client: httpx.AsyncClient = client or httpx.AsyncClient() self._encoder: Encoder = encoder or Encoder() - self._version = config.version + self._version = config.app_version if self._file.exists() and "600" != self._file.stat().st_mode: try: diff --git a/app/library/config.py b/app/library/config.py index f3009903..92e8acbc 100644 --- a/app/library/config.py +++ b/app/library/config.py @@ -109,10 +109,6 @@ class Config: pip_ignore_updates: bool = False """Ignore pip package updates.""" - # immutable config vars. - version: str = APP_VERSION - "The version of the application." - app_version: str = APP_VERSION "The version of the application, same as `version`." @@ -194,7 +190,6 @@ class Config: "The variables that are set manually." _immutable: tuple = ( - "version", "__instance", "ytdl_options", "started", @@ -241,7 +236,6 @@ class Config: "download_path", "keep_archive", "output_template", - "version", "started", "remove_files", "ui_update_title", @@ -457,6 +451,9 @@ class Config: ) raise ValueError(msg) + if "dev-master" == self.app_version: + self._version_via_git() + def _get_attributes(self) -> dict: attrs: dict = {} vClass: str = self.__class__ @@ -524,3 +521,66 @@ class Config: return YTDLP_VERSION except ImportError: return "0.0.0" + + def _version_via_git(self): + """ + Updates the version of the application using git tags. + This is used to set the version to the latest git tag. + """ + git_path: str = Path(__file__).parent / ".." / ".." / ".git" + if not git_path.exists(): + return + + try: + import subprocess + + branch_result = subprocess.run( # noqa: S603 + ["git", "rev-parse", "--abbrev-ref", "HEAD"], # noqa: S607 + cwd=os.path.dirname(git_path), + capture_output=True, + text=True, + check=False, + ) + + if 0 != branch_result.returncode: + logging.error(f"Git rev-parse failed: {branch_result.stderr.strip()}") + return + + branch_name: str = branch_result.stdout.strip() + if not branch_name: + logging.warning("Git branch name is empty.") + return + + commit_result = subprocess.run( # noqa: S603 + ["git", "log", "-1", "--format=%ct_%H"], # noqa: S607 + cwd=os.path.dirname(git_path), + capture_output=True, + text=True, + check=False, + ) + + if 0 != commit_result.returncode: + logging.error(f"Git log failed: {commit_result.stderr.strip()}") + return + + commit_info: str = commit_result.stdout.strip() + if not commit_info: + logging.warning("Git commit info is empty.") + return + + commit_date, commit_sha = commit_info.split("_", 1) + commit_date = time.strftime("%Y%m%d", time.localtime(int(commit_date))) + + self.app_version = f"{branch_name}-{commit_date}-{commit_sha[:8]}" + self.app_branch = branch_name + self.app_commit_sha = commit_sha + self.app_build_date = commit_date + version_data = { + "version": self.app_version, + "branch": self.app_branch, + "commit": self.app_commit_sha, + "build_date": self.app_build_date, + } + logging.info(f"Application version info set to '{version_data}'") + except Exception as e: + logging.error(f"Error while getting git version: {e!s}") diff --git a/app/main.py b/app/main.py index bfe62777..55be9872 100644 --- a/app/main.py +++ b/app/main.py @@ -119,7 +119,7 @@ class Main: def started(_): LOG.info("=" * 40) - LOG.info(f"YTPTube {self._config.version} - started on http://{host}:{port}{self._config.base_path}") + LOG.info(f"YTPTube {self._config.app_version} - started on http://{host}:{port}{self._config.base_path}") LOG.info("=" * 40) loop = asyncio.get_event_loop() diff --git a/app/routes/api/images.py b/app/routes/api/images.py index ac794814..4eb17460 100644 --- a/app/routes/api/images.py +++ b/app/routes/api/images.py @@ -47,7 +47,7 @@ async def get_thumbnail(request: Request, config: Config) -> Response: "proxy": ytdlp_args.get("proxy", None), "headers": { "User-Agent": ytdlp_args.get( - "user_agent", request.headers.get("User-Agent", f"YTPTube/{config.version}") + "user_agent", request.headers.get("User-Agent", f"YTPTube/{config.app_version}") ), }, } @@ -118,7 +118,7 @@ async def get_background(request: Request, config: Config, cache: Cache) -> Resp opts = { "proxy": ytdlp_args.get("proxy", None), "headers": { - "User-Agent": ytdlp_args.get("user_agent", f"YTPTube/{config.version}"), + "User-Agent": ytdlp_args.get("user_agent", f"YTPTube/{config.app_version}"), }, } diff --git a/ui/layouts/default.vue b/ui/layouts/default.vue index f8a296bd..17b8ac26 100644 --- a/ui/layouts/default.vue +++ b/ui/layouts/default.vue @@ -115,7 +115,7 @@
© {{ Year }} - YTPTube -  ({{ config?.app?.app_version || 'unknown' }}) - yt-dlp diff --git a/ui/pages/changelog.vue b/ui/pages/changelog.vue index 523a23a3..e6eafa81 100644 --- a/ui/pages/changelog.vue +++ b/ui/pages/changelog.vue @@ -47,13 +47,17 @@ hr {
@@ -80,19 +84,19 @@ const REPO = `https://github.com/arabcoders/${PROJECT}` const REPO_URL = `https://arabcoders.github.io/${PROJECT}/CHANGELOG.json?version={version}` const logs = ref([]) -const api_version = ref('') -const api_branch = ref('') -const api_sha = ref('') +const app_version = ref('') +const app_branch = ref('') +const app_sha = ref('') const isLoading = ref(true) const loadContent = async () => { - if ('' === api_version.value || logs.value.length > 0) { + if ('' === app_version.value || logs.value.length > 0) { return } try { try { - const changes = await fetch(REPO_URL.replace('{branch}', api_branch.value).replace('{version}', api_version.value)) + const changes = await fetch(REPO_URL.replace('{branch}', app_branch.value).replace('{version}', app_version.value)) logs.value = await changes.json() } catch (e) { console.error(e) @@ -110,7 +114,7 @@ const loadContent = async () => { } const isInstalled = (log: changeset) => { - const installed = String(api_sha.value) + const installed = String(app_sha.value) if (log.full_sha.startsWith(installed)) { return true @@ -127,9 +131,9 @@ const isInstalled = (log: changeset) => { onMounted(async () => { await awaiter(config.isLoaded) - api_branch.value = config.app.app_branch - api_version.value = config.app.app_version - api_sha.value = config.app.app_commit_sha + app_branch.value = config.app.app_branch + app_version.value = config.app.app_version + app_sha.value = config.app.app_commit_sha loadContent() })