"""Rebuild the exact test input from YouTube's public help page and check its SHA-256.

The page text is not redistributed with this kit: this script downloads it and applies the same cuts.
If YouTube edits the page, the hash will not match and the test is a new version.
Usage: python3 fetch_input.py > input_text.txt
"""
import hashlib, html, re, sys, urllib.request

URL = "https://support.google.com/youtube/answer/72851?hl=en"
EXPECTED = "3cf75700f67a38413379b3816ac66c4489bc425a8c2bfdda0a6dc31394e8d469"
req = urllib.request.Request(URL, headers={"User-Agent": "Mozilla/5.0", "Accept-Language": "en-US"})
raw = urllib.request.urlopen(req, timeout=30).read().decode("utf-8", "replace")
raw = re.sub(r"<script.*?</script>|<style.*?</style>", "", raw, flags=re.S)
s = re.sub(r"\s+", " ", html.unescape(re.sub(r"<[^>]+>", " ", raw)))
art = s[s.find("YouTube Partner Program overview & eligibility Starting"):s.find("Was this helpful")]
# Same cuts as the test: links to resources, one pointer to another policy, and the last FAQs.
art = art.replace(" Here are some resources that can help you grow your channel: Learn solutions from other YouTube users in the YouTube Help Forum . Discover quick-and-easy tips on how to grow and build your channel in our Creator Tips hub. Go to youtube.com/creators to learn, grow, and be connected to programs, resources, and events. Check out our YouTube Help channel and YouTube Creators channel to watch tutorials, troubleshooting, and tip videos from the YouTube Help team.", "")
art = art.replace(" For info about Shorts view eligibility with regards to how we calculate payments, see our YouTube Shorts monetization policies .", "")
i = art.find(" Our team will review your channel as a whole to check whether your channel meets our YouTube channel monetization policies .")
j = art.find(" If a channel is inactive and has not uploaded or posted posts for 6 months or more")
art = art[:i] + art[j:]
art = art[:art.find(" Channels will lose monetization when they violate")]
h = hashlib.sha256(art.encode("utf-8")).hexdigest()
print(art)
print(("OK, same input: " if h == EXPECTED else "DIFFERENT INPUT (the page changed): ") + h, file=sys.stderr)
