diff --git a/Casks/i/insta360-studio.rb b/Casks/i/insta360-studio.rb index 97410af58e..058f4dc917 100644 --- a/Casks/i/insta360-studio.rb +++ b/Casks/i/insta360-studio.rb @@ -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]}"