insta360-studio: update livecheck

This commit is contained in:
Sam Ford
2023-11-29 08:50:09 -05:00
parent 25ba127d71
commit 243840070b
+15 -7
View File
@@ -9,16 +9,24 @@ cask "insta360-studio" do
livecheck do
url "https://openapi.insta360.com/app/appDownload/getGroupApp?group=insta360-go2&X-Language=en-us"
regex(%r{/([[:xdigit:]]+)/Insta360Studio(\d+)(?:[._-]|%20)(?:\d+(?:\.\d+)+)[._-](\d+(?:[._-]\d+)*)\.pkg}i)
strategy :page_match do |page, regex|
newest_release = JSON.parse(page)["data"]["apps"]
.find { |app| app["id"] == 38 }["items"]
.select { |item| item["platform"] == "mac" }
.max_by { |item| Version.new(item["version"]) }
regex(%r{/(\h+)/Insta360Studio(\d+)(?:[._-]|%20)(?:\d+(?:\.\d+)+)[._-](\d+(?:[._-]\d+)*)\.pkg}i)
strategy :json do |json, regex|
# Find the Insta360 Studio app
app = json.dig("data", "apps")&.find { |item| item["id"] == 38 }
next if app.blank?
# Find the newest macOS version
newest_release = app["items"]&.select { |item| item["platform"] == "mac" }
&.max_by { |item| Version.new(item["version"]) }
next if newest_release.blank?
# Find the channel item (there's likely only one object in the array)
channel = newest_release["channels"]&.find { |item| item["channel"] == "official" }
next if channel.blank?
# Collect the version parts
version = newest_release["version"]
match = newest_release["channels"][0]["download_url"].match(regex)
match = channel["download_url"]&.match(regex)
next if version.blank? || match.blank?
"#{version},#{match[2]},#{match[1]},#{match[3]}"