Skip to content

Instantly share code, notes, and snippets.

@bryanseah234
Created October 3, 2026 10:45
Show Gist options
  • Select an option

  • Save bryanseah234/47536bb071e287c6b837dd36c3b6c866 to your computer and use it in GitHub Desktop.

Select an option

Save bryanseah234/47536bb071e287c6b837dd36c3b6c866 to your computer and use it in GitHub Desktop.
youtubepublisher-code (JavaScript helper for publishing YouTube drafts with a demo GIF)

Repository StandardsThis document is the authoritative list of standards every repository in thisworkspace is expected to follow. New repositories created fromtheprawntemplate inherit the baseline automatically; this file records whatthat baseline is, what is required vs. optional, and the packaging pattern forcontainer repositories.It exists so that humans and automation agents working across the fleet have asingle source of truth to conform to, rather than relying on implicitper-repository conventions.Last reviewed: 2026-09-27.## ScopeApplies to all owned repositories (currently 79: 71 non-container, 7 container,plus one history-managed repository). "Container repository" means a repositorythat builds and publishes one or more container images to GitHub ContainerRegistry (GHCR, ghcr.io).## 1. Security scanning (REQUIRED for every repo)Every repository must carry these GitHub Actions workflows. They are present intheprawntemplate and propagate to new repositories:| Workflow | File | Purpose || --- | --- | --- || CodeQL | .github/workflows/codeql.yml | Static analysis / code scanning || Semgrep | .github/workflows/semgrep.yml | Pattern-based SAST || TruffleHog | .github/workflows/trufflehog.yml | Secret scanning || Dependency Review | .github/workflows/dependency-review.yml | Blocks vulnerable dependency changes in PRs || Scorecard | .github/workflows/scorecard.yml | OpenSSF supply-chain posture || LFS Guard | .github/workflows/lfs-guard.yml | Blocks accidental large/binary commits |A repository is security-compliant when all six are present and enabled.## 2. Automation and CI (REQUIRED)- .github/workflows/ci.yml — project checks; adapt commands to the stack.- .github/dependabot.yml + .github/workflows/dependabot-auto-merge.yml and .github/workflows/auto-merge-bots.yml — dependency updates with guarded auto-merge.- .github/workflows/labeler.yml, greetings.yml, heartbeat.yml, summary.yml — repository hygiene and activity signals.- .github/workflows/deploy.yml — deployment (or a clear statement that the repo is not deployed).## 3. Governance and hygiene files (REQUIRED unless noted)| File | Requirement || --- | --- || LICENSE | Required — Apache-2.0. || NOTICE | Required — accompanies Apache-2.0. || SECURITY.md | Required. Use GitHub private "Report a vulnerability"; never a personal email. || CONTRIBUTING.md | Required. || AGENTS.md | Required — instructions for automation agents. || .github/dependabot.yml | Required. || .env.example | Required only when the project reads environment variables. Repos with no env config legitimately omit it. || .github/ISSUE_TEMPLATE/*, .github/pull_request_template.md | Required. || .gitignore, .gitattributes | Required. |## 4. Privacy and portability rules (REQUIRED)These reflect the fleet-wide remediation sweep and must hold for every repo:- No secrets in git. Use environment variables and .env.example. TruffleHog enforces this in CI; do not defeat it.- No personal contact details or private operator references in tracked files (READMEs, SECURITY.md, configs, .agents/). Vulnerability reporting goes through GitHub's private channel, not a personal email.- Windows/Linux portability. Launchers and paths must work on both; avoid hardcoded absolute paths and OS-specific-only launch scripts where a portable equivalent exists.- .agents/ hygiene. Never write secrets or personal details into .agents/STATE.md or .agents/JOURNAL.md.- PRs over direct commits to main. Changes land through reviewed pull requests.## 5. Container / GHCR packaging (REQUIRED for container repos; OPT-IN for others)Container repositories publish images to ghcr.io/<owner>/<repo>/<component>.The standard packaging pattern — verified present in all seven current containerrepositories (musicstream, facetracker, FORGE, unifiedcollector, unifiedanalyzer,ticketremaster-b, ctfsolver) — is:| File | Purpose || --- | --- || .github/workflows/docker-publish.yml | Builds and pushes image(s) to GHCR on the release trigger. || .github/scripts/ghcr-retention.cjs | Prunes old GHCR package versions to control storage. || Dockerfile (and variants) | Image build definition(s). |Opt-in scaffolding for these files lives under.github/optional/ so a new repository can adopt thepackaging pattern by copying them into place rather than hand-rolling each time.See .github/optional/README.md for enable steps.Package visibility: package visibility (private vs public) is governed by theorganization's package-creation policy (Org Settings → Packages). Individualcontainer package visibility is a deliberate, per-package decision — especiallyfor privacy-sensitive images (photo/OSINT/security tooling) whose layers becomeworld-pullable when public.## 6. Compliance statusA live compliance matrix across all owned repositories is maintained out-of-band(see repo-standards-compliance-matrix.md in the workspace release artifacts).As of the last review, 76/79 repositories carry the full security-workflow set;the known exceptions are actively-developed repositories that have not yetadopted the baseline. All seven container repositories carry the complete GHCRpipeline.## How to use this document- Creating a new repo: start from theprawntemplate; you inherit sections 1–4 automatically. If it will publish containers, adopt section 5 from .github/optional/.- Auditing an existing repo: check it against sections 1–4 (all repos) and section 5 (container repos). Missing required items are compliance gaps to fix via a reviewed PR.- Agents: treat this file as the conformance target for any repository work.

(() => { // ----------------------------------------------------------------- // CONFIG (you're safe to edit this) // ----------------------------------------------------------------- // ~ GLOBAL CONFIG // ----------------------------------------------------------------- const MODE = 'publish_drafts' // 'publish_drafts' / 'sort_playlist'; const DEBUG_MODE = true // true / false, enable for more context // ----------------------------------------------------------------- // ~ PUBLISH CONFIG // ----------------------------------------------------------------- const MADE_FOR_KIDS = false // true / false; const VISIBILITY = 'Public' // 'Public' / 'Private' / 'Unlisted' // ----------------------------------------------------------------- // ~ SORT PLAYLIST CONFIG // ----------------------------------------------------------------- const SORTING_KEY = (one, other) => { const numberRegex = /\d+/ const number = (name) => name.match(numberRegex)[0] if (number(one.name) === undefined || number(other.name) === undefined) { return one.name.localeCompare(other.name) } return number(one.name) - number(other.name) } // END OF CONFIG (not safe to edit stuff below) // ----------------------------------------------------------------- // COMMON STUFF // --------------------------------- const TIMEOUT_STEP_MS = 20 const DEFAULT_ELEMENT_TIMEOUT_MS = 10000 function debugLog (...args) { if (!DEBUG_MODE) { return } console.debug(...args) } const sleep = (ms) => new Promise((resolve, _) => setTimeout(resolve, ms)) async function waitForElement (selector, baseEl, timeoutMs) { if (timeoutMs === undefined) { timeoutMs = DEFAULT_ELEMENT_TIMEOUT_MS } if (baseEl === undefined) { baseEl = document } let timeout = timeoutMs while (timeout > 0) { const element = baseEl.querySelector(selector) if (element !== null) { return element } await sleep(TIMEOUT_STEP_MS) timeout -= TIMEOUT_STEP_MS } debugLog(`could not find ${selector} inside`, baseEl) return null } function click (element) { const event = document.createEvent('MouseEvents') event.initMouseEvent('mousedown', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) element.dispatchEvent(event) element.click() debugLog(element, 'clicked') } // ---------------------------------- // PUBLISH STUFF // ---------------------------------- const VISIBILITY_PUBLISH_ORDER = { Private: 0, Unlisted: 1, Public: 2 } // SELECTORS // --------- const VIDEO_ROW_SELECTOR = 'ytcp-video-row' const DRAFT_MODAL_SELECTOR = '.style-scope.ytcp-uploads-dialog' const DRAFT_BUTTON_SELECTOR = '.edit-draft-button' const MADE_FOR_KIDS_SELECTOR = '#made-for-kids-group' const RADIO_BUTTON_SELECTOR = 'tp-yt-paper-radio-button' const VISIBILITY_STEPPER_SELECTOR = '#step-badge-3' const VISIBILITY_PAPER_BUTTONS_SELECTOR = 'tp-yt-paper-radio-group' const NEXT_BUTTON_SELECTOR = '#next-button' const CHECKS_STEPPER_SELECTOR = '#step-badge-2' const SAVE_BUTTON_SELECTOR = '#done-button' const SUCCESS_ELEMENT_SELECTOR = 'ytcp-video-thumbnail-with-info' const DIALOG_SELECTOR = 'ytcp-dialog.ytcp-video-share-dialog > tp-yt-paper-dialog:nth-child(1)' const DIALOG_CLOSE_BUTTON_SELECTOR = 'tp-yt-iron-icon' class SuccessDialog { constructor (raw) { this.raw = raw } async closeDialogButton () { return await waitForElement(DIALOG_CLOSE_BUTTON_SELECTOR, this.raw) } async close () { click(await this.closeDialogButton()) await sleep(50) debugLog('closed') } } class VisibilityModal { constructor (raw) { this.raw = raw } async radioButtonGroup () { return await waitForElement(VISIBILITY_PAPER_BUTTONS_SELECTOR, this.raw) } async visibilityRadioButton () { const group = await this.radioButtonGroup() const value = VISIBILITY_PUBLISH_ORDER[VISIBILITY] return [...group.querySelectorAll(RADIO_BUTTON_SELECTOR)][value] } async setVisibility () { click(await this.visibilityRadioButton()) debugLog(`visibility set to ${VISIBILITY}`) await sleep(50) } async saveButton () { return await waitForElement(SAVE_BUTTON_SELECTOR, this.raw) } async isSaved () { await waitForElement(SUCCESS_ELEMENT_SELECTOR, document) } async dialog () { return await waitForElement(DIALOG_SELECTOR) } async save () { click(await this.saveButton()) await this.isSaved() debugLog('saved') const dialogElement = await this.dialog() const success = new SuccessDialog(dialogElement) return success } } class DraftModal { constructor (raw) { this.raw = raw } async madeForKidsToggle () { return await waitForElement(MADE_FOR_KIDS_SELECTOR, this.raw) } async madeForKidsPaperButton () { const nthChild = MADE_FOR_KIDS ? 1 : 2 return await waitForElement(`${RADIO_BUTTON_SELECTOR}:nth-child(${nthChild})`, this.raw) } async selectMadeForKids () { click(await this.madeForKidsPaperButton()) await sleep(50) debugLog('"Made for kids" set as ${MADE_FOR_KIDS}') } async visibilityStepper () { return await waitForElement(VISIBILITY_STEPPER_SELECTOR, this.raw) } async clickNextButton () { const nextButton = await waitForElement(NEXT_BUTTON_SELECTOR, this.raw, 2000) if (nextButton !== null) { click(nextButton) debugLog('clicked Next button (intermediate step)') await sleep(500) return true } return false } async goToVisibility () { debugLog('going to Visibility') await sleep(50) // Try clicking the visibility stepper directly click(await this.visibilityStepper()) await sleep(200) // Check if we landed on visibility (radio group visible) const radioGroup = this.raw.querySelector(VISIBILITY_PAPER_BUTTONS_SELECTOR) if (radioGroup === null) { // Visibility stepper click did not work - likely blocked by Checks step // (e.g., copyright warning). Navigate through intermediate steps via Next. debugLog('Visibility not reached directly, clicking through intermediate steps') for (let i = 0; i < 5; i++) { const landed = this.raw.querySelector(VISIBILITY_PAPER_BUTTONS_SELECTOR) if (landed !== null) break const clicked = await this.clickNextButton() if (!clicked) break } } const visibility = new VisibilityModal(this.raw) await sleep(50) await waitForElement(VISIBILITY_PAPER_BUTTONS_SELECTOR, visibility.raw) return visibility } } class VideoRow { constructor (raw) { this.raw = raw } get editDraftButton () { return waitForElement(DRAFT_BUTTON_SELECTOR, this.raw, 20) } async openDraft () { debugLog('focusing draft button') click(await this.editDraftButton) return new DraftModal(await waitForElement(DRAFT_MODAL_SELECTOR)) } } function allVideos () { return [...document.querySelectorAll(VIDEO_ROW_SELECTOR)].map((el) => new VideoRow(el)) } async function editableVideos () { let editable = [] for (const video of allVideos()) { if ((await video.editDraftButton) !== null) { editable = [...editable, video] } } return editable } async function publishDrafts () { const videos = await editableVideos() debugLog(`found ${videos.length} videos`) debugLog('starting in 1000ms') await sleep(1000) for (const video of videos) { const draft = await video.openDraft() debugLog({ draft }) await draft.selectMadeForKids() const visibility = await draft.goToVisibility() await visibility.setVisibility() const dialog = await visibility.save() await dialog.close() await sleep(100) } } // ---------------------------------- // SORTING STUFF // ---------------------------------- const SORTING_MENU_BUTTON_SELECTOR = 'button' const SORTING_ITEM_MENU_SELECTOR = 'paper-listbox#items' const SORTING_ITEM_MENU_ITEM_SELECTOR = 'ytd-menu-service-item-renderer' const MOVE_TO_TOP_INDEX = 4 const MOVE_TO_BOTTOM_INDEX = 5 class SortingDialog { constructor (raw) { this.raw = raw } async anyMenuItem () { const item = await waitForElement(SORTING_ITEM_MENU_ITEM_SELECTOR, this.raw) if (item === null) { throw new Error('could not locate any menu item') } return item } menuItems () { return [...this.raw.querySelectorAll(SORTING_ITEM_MENU_ITEM_SELECTOR)] } async moveToTop () { click(this.menuItems()[MOVE_TO_TOP_INDEX]) } async moveToBottom () { click(this.menuItems()[MOVE_TO_BOTTOM_INDEX]) } } class PlaylistVideo { constructor (raw) { this.raw = raw } get name () { return this.raw.querySelector('#video-title').textContent } async dialog () { return this.raw.querySelector(SORTING_MENU_BUTTON_SELECTOR) } async openDialog () { click(await this.dialog()) const dialog = new SortingDialog(await waitForElement(SORTING_ITEM_MENU_SELECTOR)) await dialog.anyMenuItem() return dialog } } async function playlistVideos () { return [...document.querySelectorAll('ytd-playlist-video-renderer')] .map((el) => new PlaylistVideo(el)) } async function sortPlaylist () { debugLog('sorting playlist') const videos = await playlistVideos() debugLog(`found ${videos.length} videos`) videos.sort(SORTING_KEY) const videoNames = videos.map((v) => v.name) let index = 1 for (const name of videoNames) { debugLog({ index, name }) const video = videos.find((v) => v.name === name) const dialog = await video.openDialog() await dialog.moveToBottom() await sleep(1000) index += 1 } } // ---------------------------------- // ENTRY POINT // ---------------------------------- ({ publish_drafts: publishDrafts, sort_playlist: sortPlaylist })[MODE]()})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment