Switch update checks from GitHub API to PyPI

Update logic in updater dialog and main app to fetch latest version info from PyPI instead of GitHub API, avoiding rate limiting issues. Changelog is now fetched from GitHub only as a fallback, improving reliability of update checks.
This commit is contained in:
oop7
2025-11-29 13:31:57 +02:00
parent b58b1a6857
commit 15451f7715
2 changed files with 27 additions and 11 deletions
@@ -629,13 +629,13 @@ class UpdaterTabWidget(QWidget):
update_target = new_channel update_target = new_channel
if new_channel == "stable" and current_channel == "nightly": if new_channel == "stable" and current_channel == "nightly":
# Get the latest stable version tag # Get the latest stable version tag from PyPI (no rate limiting)
logger.info("Fetching latest stable version tag...") logger.info("Fetching latest stable version tag from PyPI...")
try: try:
import requests import requests
response = requests.get("https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest", timeout=10) response = requests.get("https://pypi.org/pypi/yt-dlp/json", timeout=10)
response.raise_for_status() response.raise_for_status()
latest_tag = response.json().get("tag_name", "") latest_tag = response.json()["info"]["version"]
if latest_tag: if latest_tag:
update_target = f"stable@{latest_tag}" update_target = f"stable@{latest_tag}"
logger.info(f"Latest stable version tag: {latest_tag}") logger.info(f"Latest stable version tag: {latest_tag}")
+23 -7
View File
@@ -1087,20 +1087,36 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
def check_for_updates(self) -> None: def check_for_updates(self) -> None:
try: try:
# Get the latest release info from GitHub # Get the latest version info from PyPI (no rate limiting unlike GitHub API)
response = requests.get( response = requests.get(
"https://api.github.com/repos/oop7/YTSage/releases/latest", "https://pypi.org/pypi/ytsage/json",
headers={"Accept": "application/vnd.github.v3+json"}, timeout=10,
) )
response.raise_for_status() response.raise_for_status()
latest_release = response.json() pypi_data = response.json()
latest_version = latest_release["tag_name"].lstrip("v") latest_version = pypi_data["info"]["version"]
# Compare versions # Compare versions
if version.parse(latest_version) > version.parse(self.version): if version.parse(latest_version) > version.parse(self.version):
changelog = latest_release.get("body", "No changelog available.") # Get changelog body release_url = "https://github.com/oop7/YTSage/releases/latest"
self.show_update_dialog(latest_version, latest_release["html_url"], changelog) # Pass changelog
# Try to fetch changelog from GitHub (with fallback if rate-limited)
changelog = "View the full changelog on the [GitHub Releases](https://github.com/oop7/YTSage/releases) page."
try:
gh_response = requests.get(
"https://api.github.com/repos/oop7/YTSage/releases/latest",
headers={"Accept": "application/vnd.github.v3+json"},
timeout=5,
)
if gh_response.status_code == 200:
gh_data = gh_response.json()
changelog = gh_data.get("body", changelog)
except Exception:
# Silently fallback to static message if GitHub API fails (rate limit, etc.)
pass
self.show_update_dialog(latest_version, release_url, changelog)
except Exception as e: except Exception as e:
logger.exception(f"Failed to check for updates: {e}") logger.exception(f"Failed to check for updates: {e}")