Support approved YouTube previews in Play listing publishing
This commit is contained in:
1 parent
0728ba7da5
commit
c5080ef200
4 files changed
+90
-5
No files matched your search
@@ -9,6 +9,9 @@ PLAY_DELETE_EXISTING=1
|
||||
# Short and full descriptions from every locale folder here. 0 skips text.
|
||||
PLAY_METADATA_DIR=fastlane/metadata/android
|
||||
PLAY_LISTING_TEXT=1
|
||||
# Optional public/unlisted, embeddable YouTube video for PLAY_LANGUAGE.
|
||||
# Leave empty to preserve the existing video.
|
||||
PLAY_VIDEO_URL=
|
||||
|
||||
# Default is validate-only and discards the draft edit.
|
||||
# Set to 1 only when you want the uploaded screenshots committed to Play.
|
||||
|
||||
@@ -130,7 +130,14 @@ The chat example runs real local theme actions; the surrounding forest and
|
||||
glow are marketing effects. Inspect `build/lumi-promo/storyboard.jpg` and
|
||||
`build/lumi-promo/inner-breeze-lumi-review.mp4` before using it publicly.
|
||||
Google Play's preview video field takes a YouTube URL, so the MP4 needs an
|
||||
approved YouTube upload before it can be added to the listing.
|
||||
approved public or unlisted YouTube upload with embedding enabled before it can
|
||||
be added to the listing. Pass `--video-url https://www.youtube.com/watch?v=VIDEO_ID`
|
||||
to the listing uploader, or configure `PLAY_VIDEO_URL`. To update only the
|
||||
video, use `PLAY_COMMIT=1 python3 scripts/upload-play-screenshots.py --video-only --video-url URL`.
|
||||
The approved [Lumi preview](https://www.youtube.com/watch?v=XESpbMRaz4o) is
|
||||
available on YouTube and configured in the English Google Play listing.
|
||||
Screenshot publishing still requires the complete current
|
||||
capture, visual review, export and locked build preflight.
|
||||
|
||||
To test sync and recovery against an isolated local server:
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import json
|
||||
import mimetypes
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -126,6 +127,35 @@ def upload_url(package_name, path):
|
||||
return f"{UPLOAD_BASE}/applications/{package}{path}"
|
||||
|
||||
|
||||
def youtube_video_url(value):
|
||||
parsed = urllib.parse.urlsplit(value.strip())
|
||||
if parsed.scheme != "https" or parsed.netloc not in {
|
||||
"youtube.com", "www.youtube.com", "youtu.be"
|
||||
}:
|
||||
raise ValueError("The Play preview video must use an HTTPS YouTube URL")
|
||||
if parsed.netloc == "youtu.be":
|
||||
video_id = parsed.path.removeprefix("/")
|
||||
elif parsed.path == "/watch":
|
||||
values = urllib.parse.parse_qs(parsed.query).get("v", [])
|
||||
video_id = values[0] if len(values) == 1 else ""
|
||||
else:
|
||||
video_id = ""
|
||||
if not re.fullmatch(r"[A-Za-z0-9_-]{11}", video_id):
|
||||
raise ValueError("The Play preview video URL must identify one YouTube video")
|
||||
return "https://www.youtube.com/watch?v=" + video_id
|
||||
|
||||
|
||||
def upload_listing_video(package_name, edit_id, language, video_url, token):
|
||||
http_request(
|
||||
"PATCH",
|
||||
api_url(package_name, f"/edits/{edit_id}/listings/{language}"),
|
||||
body=json.dumps({"video": video_url}).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json"},
|
||||
token=token,
|
||||
)
|
||||
print(f"Updated {language} preview video: {video_url}")
|
||||
|
||||
|
||||
def list_images(images_root, image_type):
|
||||
folder = images_root / image_type
|
||||
if not folder.is_dir():
|
||||
@@ -182,6 +212,8 @@ def upload_listing_texts(package_name, edit_id, metadata_root, token):
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Preflight, validate, or publish reviewed Play listing assets.")
|
||||
parser.add_argument("--preflight-only", action="store_true", help="Check local assets without credentials or network access")
|
||||
parser.add_argument("--video-url", help="Public or unlisted, embeddable YouTube preview video")
|
||||
parser.add_argument("--video-only", action="store_true", help="Update only the preview video; leave listing text and screenshots unchanged")
|
||||
args = parser.parse_args()
|
||||
load_env_file(ROOT / ".env.play")
|
||||
language = os.environ.get("PLAY_LANGUAGE", "en-US")
|
||||
@@ -204,7 +236,17 @@ def main():
|
||||
listing_text = os.environ.get("PLAY_LISTING_TEXT", "1") != "0"
|
||||
commit = os.environ.get("PLAY_COMMIT", "0") == "1"
|
||||
delete_existing = os.environ.get("PLAY_DELETE_EXISTING", "1") != "0"
|
||||
video_url = args.video_url or os.environ.get("PLAY_VIDEO_URL", "")
|
||||
if video_url:
|
||||
video_url = youtube_video_url(video_url)
|
||||
if args.video_only and not video_url:
|
||||
raise SystemExit("--video-only requires --video-url or PLAY_VIDEO_URL")
|
||||
if args.video_only:
|
||||
listing_text = False
|
||||
image_types = []
|
||||
|
||||
harness = None
|
||||
if not args.video_only:
|
||||
spec = importlib.util.spec_from_file_location("screenshot_harness", ROOT / "scripts/screenshot-harness.py")
|
||||
harness = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(harness)
|
||||
@@ -214,12 +256,14 @@ def main():
|
||||
if len(text["shortDescription"]) > 80 or len(text["fullDescription"]) > 4000:
|
||||
raise SystemExit(f"{locale} description is over Play's length limit")
|
||||
allowed_types = {"phoneScreenshots", "sevenInchScreenshots", "tenInchScreenshots"}
|
||||
if not image_types or not set(image_types) <= allowed_types:
|
||||
if not args.video_only and (not image_types or not set(image_types) <= allowed_types):
|
||||
raise SystemExit("PLAY_IMAGE_TYPES must name reviewed phone/tablet screenshot types")
|
||||
if args.preflight_only:
|
||||
print("Local listing preflight passed; no Google Play edit was created.")
|
||||
return
|
||||
|
||||
reviewed_hashes = {}
|
||||
if image_types:
|
||||
reviewed_hashes = {item["file"]: item["sha256"] for item in
|
||||
json.loads((images_root / "screenshot-review.json").read_text())["files"]}
|
||||
image_payloads = {}
|
||||
@@ -243,6 +287,8 @@ def main():
|
||||
try:
|
||||
if listing_text:
|
||||
upload_listing_texts(package_name, edit_id, metadata_root, token)
|
||||
if video_url:
|
||||
upload_listing_video(package_name, edit_id, language, video_url, token)
|
||||
for image_type in image_types:
|
||||
files = image_payloads[image_type]
|
||||
if not files:
|
||||
@@ -263,6 +309,7 @@ def main():
|
||||
)
|
||||
print(f"Uploaded {image_type}/{path.name}")
|
||||
|
||||
if harness is not None:
|
||||
harness.store_preflight(images_root)
|
||||
http_request("POST", api_url(package_name, f"/edits/{edit_id}:validate"), token=token)
|
||||
if commit:
|
||||
|
||||
@@ -12,27 +12,43 @@ publisher = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(publisher)
|
||||
|
||||
|
||||
def scenario(commit=False, fail=False, unreviewed=False):
|
||||
def scenario(commit=False, fail=False, unreviewed=False, video_url=None, video_only=False):
|
||||
calls = []
|
||||
bodies = []
|
||||
preflights = []
|
||||
def preflight(*args):
|
||||
preflights.append(args)
|
||||
if unreviewed:
|
||||
raise AssertionError("unreviewed")
|
||||
harness = SimpleNamespace(store_preflight=preflight)
|
||||
def request(method, url, **kwargs):
|
||||
calls.append((method, url))
|
||||
bodies.append(kwargs.get("body"))
|
||||
if method == "POST" and url.endswith("/edits"):
|
||||
return b'{"id":"test-edit"}'
|
||||
if fail and url.endswith(":validate"):
|
||||
raise SystemExit("simulated HTTP error")
|
||||
return b"{}"
|
||||
env = dict(PLAY_PACKAGE_NAME="xyz.waozi.inbe", PLAY_SERVICE_ACCOUNT_JSON="unused.json", PLAY_COMMIT="1" if commit else "0", PLAY_LISTING_TEXT="0")
|
||||
with patch.dict(os.environ, env, clear=True), patch.object(sys, "argv", ["upload"]), patch.object(publisher, "load_env_file"), patch.object(publisher, "service_account_token", return_value="unused") as token, patch.object(publisher, "http_request", side_effect=request), patch.object(publisher, "list_images", return_value=[]), patch.object(publisher.pathlib.Path, "read_text", return_value='{"files":[]}'), patch.object(publisher.importlib.util, "module_from_spec", return_value=harness), patch.object(publisher.importlib.util, "spec_from_file_location", return_value=SimpleNamespace(loader=SimpleNamespace(exec_module=lambda module: None))):
|
||||
argv = ["upload"]
|
||||
if video_url:
|
||||
argv.extend(["--video-url", video_url])
|
||||
if video_only:
|
||||
argv.append("--video-only")
|
||||
with patch.dict(os.environ, env, clear=True), patch.object(sys, "argv", argv), patch.object(publisher, "load_env_file"), patch.object(publisher, "service_account_token", return_value="unused") as token, patch.object(publisher, "http_request", side_effect=request), patch.object(publisher, "list_images", return_value=[]) as images, patch.object(publisher.pathlib.Path, "read_text", return_value='{"files":[]}') as reads, patch.object(publisher.importlib.util, "module_from_spec", return_value=harness), patch.object(publisher.importlib.util, "spec_from_file_location", return_value=SimpleNamespace(loader=SimpleNamespace(exec_module=lambda module: None))):
|
||||
try:
|
||||
publisher.main()
|
||||
except (AssertionError, SystemExit):
|
||||
assert fail or unreviewed
|
||||
if unreviewed:
|
||||
assert not calls and not token.called, "unreviewed input reached authentication/network"
|
||||
if video_only:
|
||||
assert not preflights and not images.called and not reads.called
|
||||
elif not unreviewed:
|
||||
assert len(preflights) == 2, "screenshot publishing lost its before/after gates"
|
||||
if video_url and not unreviewed:
|
||||
index = next(i for i, (method, url) in enumerate(calls) if method == "PATCH" and url.endswith("/listings/en-US"))
|
||||
assert bodies[index] == b'{"video": "https://www.youtube.com/watch?v=abcdefghijk"}'
|
||||
if fail:
|
||||
assert calls[-1] == ("DELETE", publisher.api_url("xyz.waozi.inbe", "/edits/test-edit")), "failed edit survived SystemExit"
|
||||
assert not any(url.endswith(":commit") for _, url in calls)
|
||||
@@ -48,4 +64,16 @@ scenario()
|
||||
scenario(commit=True)
|
||||
scenario(commit=True, fail=True)
|
||||
scenario(unreviewed=True)
|
||||
print("PASS Play transaction gates: preflight, validate-only, validate-before-commit and failed-edit cleanup")
|
||||
scenario(commit=True, video_url="https://youtu.be/abcdefghijk")
|
||||
scenario(commit=True, video_url="https://www.youtube.com/watch?v=abcdefghijk", video_only=True)
|
||||
scenario(commit=True, fail=True, video_url="https://youtu.be/abcdefghijk", video_only=True)
|
||||
for url in ("http://www.youtube.com/watch?v=abcdefghijk", "https://youtube.com.evil.test/watch?v=abcdefghijk", "https://www.youtube.com/watch?v=bad", "https://www.youtube.com/watch?v=abcdefghijk&v=lmnopqrstuv"):
|
||||
with patch.dict(os.environ, {}, clear=True), patch.object(sys, "argv", ["upload", "--video-only", "--video-url", url]), patch.object(publisher, "load_env_file"), patch.object(publisher, "service_account_token") as token:
|
||||
try:
|
||||
publisher.main()
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("invalid YouTube URL accepted")
|
||||
assert not token.called, "invalid URL reached authentication"
|
||||
print("PASS Play transaction gates: screenshot review, video-only isolation, URL validation, validate-before-commit and failed-edit cleanup")
|
||||
Reference in new issue
Block a user