Skip to content

Commit 58673e0

Browse files
committed
feat: adds update checking using git, http header uses latest version
1 parent 31a9ed9 commit 58673e0

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

functions/appFunctions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import logging
88
import os
99
import shutil
10+
from library.app import getCurrentVersion
11+
import git
1012

1113
def initializeFolders():
1214
folders = [MOUNT_PATH]
@@ -67,6 +69,14 @@ def bootUp():
6769
logging.info("Mount path: %s", MOUNT_PATH)
6870
logging.info("TorBox API Key: %s", TORBOX_API_KEY)
6971
logging.info("Mount refresh time: %s %s", MOUNT_REFRESH_TIME, "hours")
72+
73+
# check version
74+
latest_version = getLatestVersion()
75+
current_version = getCurrentVersion()
76+
77+
if latest_version != current_version:
78+
logging.warning(f"!!! A new version of TorBox Media Center is available: {latest_version}. You are running version: {current_version}. Please consider updating to the latest version. !!!")
79+
7080
initializeFolders()
7181

7282
return True
@@ -79,3 +89,18 @@ def getMountPath():
7989

8090
def getMountRefreshTime():
8191
return MOUNT_REFRESH_TIME
92+
93+
def getLatestVersion():
94+
try:
95+
url = "https://github.com/torbox-app/torbox-media-center.git"
96+
g = git.cmd.Git()
97+
tags_output = g.ls_remote("--tags", url)
98+
tags = [line.split("refs/tags/")[1] for line in tags_output.splitlines() if "refs/tags/" in line]
99+
tags = [tag for tag in tags if not tag.endswith("^{}")]
100+
tags.sort(key=lambda s: list(map(int, s.lstrip('v').split('.'))))
101+
latest_tag = tags[-1] if tags else None
102+
return latest_tag
103+
except Exception as e:
104+
logging.error(f"Error fetching latest version: {e}")
105+
return None
106+

library/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ class MountRefreshTimes(Enum):
3535
MOUNT_REFRESH_TIME = MountRefreshTimes.fast.value
3636
else:
3737
MOUNT_REFRESH_TIME = MountRefreshTimes[MOUNT_REFRESH_TIME].value
38+
39+
def getCurrentVersion():
40+
return "v2.0.0"

library/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import httpx
22
from library.torbox import TORBOX_API_KEY
3+
from library.app import getCurrentVersion
34
import time
45
import logging
56
import hashlib
67
import json
78

89
TORBOX_API_URL = "https://api.torbox.app/v1/api"
910
TORBOX_SEARCH_API_URL = "https://search-api.torbox.app"
10-
USER_AGENT = "TorBox-Media-Center/1.4 TorBox/1.0"
11+
USER_AGENT = f"TorBox-Media-Center/{getCurrentVersion()} TorBox/1.0"
1112
CACHE_TTL = 300 # cache time-to-live in seconds
1213
_cache: dict[str, tuple[float, httpx.Response]] = {}
1314

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ httpx
44
python-dotenv
55
parse-torrent-title
66
fuse-python; sys_platform != "win32" and sys_platform != "darwin"
7-
git+https://github.com/libfuse/python-fuse; sys_platform == "darwin"
7+
git+https://github.com/libfuse/python-fuse; sys_platform == "darwin"
8+
GitPython

0 commit comments

Comments
 (0)