# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse import hashlib import json import logging import re from urllib.parse import urlparse, urlunparse
import requests
def fetch_url_for_cdms(cdms, urlParams):
any_version = None for cdm in cdms: if"fileName"in cdm:
cdm["fileUrl"] = cdm["fileName"].format_map(urlParams)
response = requests.get(cdm["fileUrl"], allow_redirects=False) if response.status_code != 302: raise Exception( "{} unexpected status code {}".format(
cdm["target"], response.status_code
)
)
# Note that here we modify the returned URL from the # component update service because it returns a preferred # server for the caller of the script. This may not match # up with what the end users require. Google has requested # that we instead replace these results with the # edgedl.me.gvt1.com domain/path, which should be location # agnostic.
normalizedUrl = re.sub(
r"https.+?release2", "https://edgedl.me.gvt1.com/edgedl/release2",
sanitizedUrl,
) ifnot normalizedUrl: raise Exception( "{} cannot normalize '{}'".format(cdm["target"], sanitizedUrl)
)
# Because some users are unable to resolve *.gvt1.com # URLs, we supply an alternative based on www.google.com. # This should resolve with success more frequently.
mirrorUrl = re.sub(
r"https.+?release2", "https://www.google.com/dl/release2",
sanitizedUrl,
)
version = re.search(r".*?_([\d]+\.[\d]+\.[\d]+\.[\d]+)/", sanitizedUrl) if version isNone: raise Exception( "{} cannot extract version '{}'".format(cdm["target"], sanitizedUrl)
) if any_version isNone:
any_version = version.group(1) elif version.group(1) != any_version: raise Exception( "{} version {} mismatch {}".format(
cdm["target"], version.group(1), any_version
)
)
cdm["fileName"] = normalizedUrl if mirrorUrl and mirrorUrl != normalizedUrl:
cdm["fileNameMirror"] = mirrorUrl return any_version
def fetch_data_for_cdms(cdms, urlParams): for cdm in cdms: if"fileName"in cdm:
cdm["fileUrl"] = cdm["fileName"].format_map(urlParams)
response = requests.get(cdm["fileUrl"])
response.raise_for_status()
cdm["hashValue"] = hashlib.sha512(response.content).hexdigest() if"fileNameMirror"in cdm:
cdm["mirrorUrl"] = cdm["fileNameMirror"].format_map(urlParams)
mirrorresponse = requests.get(cdm["mirrorUrl"])
mirrorresponse.raise_for_status()
mirrorhash = hashlib.sha512(mirrorresponse.content).hexdigest() if cdm["hashValue"] != mirrorhash: raise Exception( "Primary hash {} and mirror hash {} differ",
cdm["hashValue"],
mirrorhash,
)
cdm["filesize"] = len(response.content) if cdm["filesize"] == 0: raise Exception("Empty response for {target}".format_map(cdm))
parser = argparse.ArgumentParser(
description="Generate JSON for GMP plugin updates",
epilog=examples,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument( "plugin",
help="which plugin: openh264, widevine, widevine_component, widevine_l1_component",
)
parser.add_argument("version", help="version of plugin", nargs="?")
parser.add_argument("revision", help="revision hash of plugin", nargs="?")
parser.add_argument("--url", help="override base URL from which to fetch plugins")
parser.add_argument( "--testrequest",
action="store_true",
help="request upcoming version for component update service",
)
args = parser.parse_args()
if args.plugin == "openh264":
url_base = "http://ciscobinary.openh264.org" if args.version isNoneor args.revision isNone:
parser.error("openh264 requires version and revision") elif args.plugin == "widevine":
url_base = "https://redirector.gvt1.com/edgedl/widevine-cdm" if args.version isNone:
parser.error("widevine requires version") if args.revision isnotNone:
parser.error("widevine cannot use revision") elif args.plugin in ("widevine_component", "widevine_l1_component"):
url_base = "https://update.googleapis.com/service/update2/crx?response=redirect&x=id%3D{guid}%26uc&acceptformat=crx3&updaterversion=999" if args.testrequest:
url_base += "&testrequest=1" if args.version isnotNoneor args.revision isnotNone:
parser.error("chrome component cannot use version or revision") else:
parser.error("plugin not recognized")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.