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:
@@ -629,13 +629,13 @@ class UpdaterTabWidget(QWidget):
|
||||
update_target = new_channel
|
||||
|
||||
if new_channel == "stable" and current_channel == "nightly":
|
||||
# Get the latest stable version tag
|
||||
logger.info("Fetching latest stable version tag...")
|
||||
# Get the latest stable version tag from PyPI (no rate limiting)
|
||||
logger.info("Fetching latest stable version tag from PyPI...")
|
||||
try:
|
||||
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()
|
||||
latest_tag = response.json().get("tag_name", "")
|
||||
latest_tag = response.json()["info"]["version"]
|
||||
if latest_tag:
|
||||
update_target = f"stable@{latest_tag}"
|
||||
logger.info(f"Latest stable version tag: {latest_tag}")
|
||||
|
||||
@@ -1087,20 +1087,36 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
|
||||
|
||||
def check_for_updates(self) -> None:
|
||||
try:
|
||||
# Get the latest release info from GitHub
|
||||
# Get the latest version info from PyPI (no rate limiting unlike GitHub API)
|
||||
response = requests.get(
|
||||
"https://api.github.com/repos/oop7/YTSage/releases/latest",
|
||||
headers={"Accept": "application/vnd.github.v3+json"},
|
||||
"https://pypi.org/pypi/ytsage/json",
|
||||
timeout=10,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
latest_release = response.json()
|
||||
latest_version = latest_release["tag_name"].lstrip("v")
|
||||
pypi_data = response.json()
|
||||
latest_version = pypi_data["info"]["version"]
|
||||
|
||||
# Compare versions
|
||||
if version.parse(latest_version) > version.parse(self.version):
|
||||
changelog = latest_release.get("body", "No changelog available.") # Get changelog body
|
||||
self.show_update_dialog(latest_version, latest_release["html_url"], changelog) # Pass changelog
|
||||
release_url = "https://github.com/oop7/YTSage/releases/latest"
|
||||
|
||||
# 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:
|
||||
logger.exception(f"Failed to check for updates: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user