Skip to content

Check YouTube Links

Check YouTube Links #4

Workflow file for this run

name: Check YouTube Links
on:
schedule:
- cron: "0 15 * * 1" # Every Monday at 8:00 AM PDT (15:00 UTC)
workflow_dispatch:
jobs:
check-youtube-links:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python with uv
uses: astral-sh/setup-uv@v6
- name: Set up Python
run: uv python install
- name: Install package
run: uv sync && uv pip install -e .
- name: Extract and check YouTube links
id: check_links
run: |
mkdir -p broken
# Extract the list of URLs from Python constant
python -c "from fastapi_spam.constants import TEN_HOURS_OF_FUN; print('\n'.join(TEN_HOURS_OF_FUN))" > links.txt
# Check each URL using curl and grep
while read -r url; do
echo "Checking: $url"
if curl -s "$url" | grep -q "This video isn't available anymore"; then
echo "Broken: $url"
echo "$url" >> broken/urls.txt
else
echo "Valid: $url"
fi
done < links.txt
- name: Open issues for broken links
if: success()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const urlsPath = './broken/urls.txt';
if (!fs.existsSync(urlsPath)) {
console.log("No broken URLs found.");
return;
}
const urls = fs.readFileSync(urlsPath, 'utf8').split('\n').filter(Boolean);
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open"
});
for (const url of urls) {
const alreadyExists = issues.data.some(issue =>
issue.title.includes(url) || issue.body.includes(url)
);
if (!alreadyExists) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Broken YouTube link detected: ${url}`,
body: `The following YouTube video appears to be unavailable:\n\n${url}\n\nPlease review and update or remove it.`,
});
console.log(`Created issue for ${url}`);
} else {
console.log(`Issue already exists for ${url}`);
}
}