Skip to content

Commit

Permalink
[update] implement '--update-to'
Browse files Browse the repository at this point in the history
to switch between update channels (stable or dev (alias nightly & master))
or to install a specific version

Examples:
--update-to dev
--update-to [email protected]
--update-to v1.25.2
  • Loading branch information
mikf committed May 28, 2024
1 parent 5018bd4 commit 53aadb0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 20 deletions.
5 changes: 5 additions & 0 deletions gallery_dl/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def build_parser():
dest="update", action="store_const", const="latest",
help="Update to the latest version",
)
general.add_argument(
"--update-to",
dest="update", metavar="[CHANNEL@]TAG",
help="Upgrade/downgrade to a specific version",
)
general.add_argument(
"--update-check",
dest="update", action="store_const", const="check",
Expand Down
81 changes: 61 additions & 20 deletions gallery_dl/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,38 @@
# published by the Free Software Foundation.

import os
import re
import sys

from .extractor.common import Extractor, Message
from .job import DownloadJob
from . import util, version
from . import util, version, exception

REPOS = {
"stable": "mikf/gallery-dl",
"dev" : "gdl-org/builds",
"stable" : "mikf/gallery-dl",
"dev" : "gdl-org/builds",
"nightly": "gdl-org/builds",
"master" : "gdl-org/builds",
}

BINARIES_STABLE = {
"windows" : "gallery-dl.exe",
"windows_x86": "gallery-dl.exe",
"windows_x64": "gallery-dl.exe",
"linux" : "gallery-dl.bin",
}
BINARIES_DEV = {
"windows" : "gallery-dl_windows.exe",
"windows_x86": "gallery-dl_windows_x86.exe",
"windows_x64": "gallery-dl_windows.exe",
"linux" : "gallery-dl_ubuntu",
"macos" : "gallery-dl_macos",
}
BINARIES = {
"stable": {
"windows" : "gallery-dl.exe",
"windows_x86": "gallery-dl.exe",
"linux" : "gallery-dl.bin",
},
"dev": {
"windows" : "gallery-dl_windows.exe",
"windows_x86": "gallery-dl_windows_x86.exe",
"linux" : "gallery-dl_ubuntu",
"macos" : "gallery-dl_macos",
},
"stable" : BINARIES_STABLE,
"dev" : BINARIES_DEV,
"nightly": BINARIES_DEV,
"master" : BINARIES_DEV,
}


Expand All @@ -40,7 +49,7 @@ def handle_url(self, url, kwdict):
if kwdict["_check"]:
self.status |= 1
return self.extractor.log.info(
"Current version is up to date (%s)", version.__version__)
"gallery-dl is up to date (%s)", version.__version__)

if kwdict["_check"]:
return self.extractor.log.info(
Expand Down Expand Up @@ -109,6 +118,9 @@ def handle_url(self, url, kwdict):
self.out.success(pathfmt.path)

def _check_update(self, kwdict):
if kwdict["_exact"]:
return True

tag = kwdict["tag_name"]

if tag[0] == "v":
Expand Down Expand Up @@ -149,22 +161,51 @@ class UpdateExtractor(Extractor):
pattern = r"update(?::(.+))?"

def items(self):
tag = "latest"
check = exact = False

variant = version.__variant__ or "stable/windows"
repo, _, binary = variant.partition("/")
tag = "latest"

target = self.groups[0]
if target == "latest":
pass
elif target == "check":
check = True
else:
channel, sep, target = target.partition("@")
if sep:
repo = channel
tag = target
exact = True
elif channel in REPOS:
repo = channel
else:
tag = channel
exact = True

if re.match(r"\d\.\d+\.\d+", tag):
tag = "v" + tag

try:
path_repo = REPOS[repo or "stable"]
except KeyError:
raise exception.StopExtraction("Invalid channel '%s'", repo)

path_tag = tag if tag == "latest" else "tags/" + tag
url = "{}/repos/{}/releases/{}".format(
self.root_api, REPOS[repo], tag)
self.root_api, path_repo, path_tag)
headers = {
"Accept": "application/vnd.github+json",
"User-Agent": util.USERAGENT,
"X-GitHub-Api-Version": "2022-11-28",
}
data = self.request(url, headers=headers).json()
data["_check"] = (self.groups[0] == "check")
data = self.request(url, headers=headers, notfound="tag").json()
data["_check"] = check
data["_exact"] = exact

url = "{}/{}/releases/download/{}/{}".format(
self.root, REPOS[repo], data["tag_name"], BINARIES[repo][binary])
self.root, path_repo, data["tag_name"], BINARIES[repo][binary])

yield Message.Directory, data
yield Message.Url, url, data

0 comments on commit 53aadb0

Please sign in to comment.