Skip to content

AgriciDaniel/claude-youtube / skills/claude-youtube

youtube

Verified

The ultimate YouTube creator skill. Covers channel audits, video SEO, retention-engineered scripts, hook writing, thumbnail briefs, content strategy, content calendars, Shorts optimisation, analytics interpretation, monetisation planning, competitor research, cross-platform repurposing, upload metadata packages, and data-driven video idea generation. Triggers on: "youtube", "channel", "video", "views", "subscribers", "watch time", "shorts", "thumbnail", "CTR", "retention", "monetize", "script", "hook", "upload", "youtube audit", "video ideas", "content calendar", "competitor analysis", "repurpose video", "youtube seo", "youtube strategy", "youtube analytics".

FileKindSize
SKILL.mdskill md12.2 KB
execution/fetch_channel_data.pyscript8.2 KB
execution/fetch_transcript.pyscript7.5 KB
execution/fetch_video_analytics.pyscript6.6 KB
execution/search_competitor_videos.pyscript7.0 KB
execution/utils/quota_tracker.pyscript5.8 KB
execution/utils/youtube_auth.pyscript5.7 KB
references/algorithm-guide.mdmarkdown6.3 KB
references/analytics-guide.mdmarkdown5.9 KB
references/dataforseo-integration.mdmarkdown12.8 KB
references/monetization-guide.mdmarkdown5.9 KB
references/repurposing-guide.mdmarkdown6.3 KB
references/retention-scripting-guide.mdmarkdown8.0 KB
references/seo-playbook.mdmarkdown6.0 KB
references/shorts-playbook.mdmarkdown5.2 KB
references/thumbnail-ctr-guide.mdmarkdown6.6 KB
sub-skills/analyze.mdmarkdown7.6 KB
sub-skills/audit.mdmarkdown8.9 KB
sub-skills/calendar.mdmarkdown8.6 KB
sub-skills/competitor.mdmarkdown10.2 KB
sub-skills/hook.mdmarkdown7.9 KB
sub-skills/ideate.mdmarkdown8.5 KB
sub-skills/metadata.mdmarkdown8.3 KB
sub-skills/monetize.mdmarkdown7.3 KB
sub-skills/repurpose.mdmarkdown6.7 KB
sub-skills/script.mdmarkdown7.1 KB
sub-skills/seo.mdmarkdown7.7 KB
sub-skills/shorts.mdmarkdown5.2 KB
sub-skills/strategy.mdmarkdown9.8 KB
sub-skills/thumbnail.mdmarkdown9.9 KB
templates/commentary-channel.mdmarkdown6.5 KB
templates/education-channel.mdmarkdown4.8 KB
templates/entertainment-channel.mdmarkdown5.5 KB
templates/niche-authority-channel.mdmarkdown7.8 KB
templates/personal-brand-channel.mdmarkdown8.3 KB
templates/review-channel.mdmarkdown6.3 KB
templates/shorts-first-channel.mdmarkdown8.4 KB
templates/tutorial-channel.mdmarkdown5.7 KB
templates/vlog-channel.mdmarkdown6.0 KB

execution/utils/youtube_auth.py

View on GitHub
"""
YouTube API authentication manager.

Handles API key auth for public Data API v3 and OAuth 2.0 for Analytics API.
Input: auth_type ('api_key' | 'oauth'), optional credentials path
Output: authenticated googleapiclient service object OR error dict

Usage:
    python execution/utils/youtube_auth.py --check api_key
    python execution/utils/youtube_auth.py --check oauth
"""

import argparse
import json
import os
import sys
from pathlib import Path

TMP_DIR = Path.home() / ".claude" / ".tmp"
TOKEN_PATH = TMP_DIR / "youtube_oauth_token.json"
CLIENT_SECRETS_PATH = Path.home() / ".claude" / "youtube_client_secrets.json"


def get_api_key():
    """Return YouTube Data API v3 key from environment or config file."""
    key = os.environ.get("YOUTUBE_API_KEY")
    if key:
        return key

    config_path = Path.home() / ".claude" / "youtube-credentials.json"
    if config_path.exists():
        with open(config_path) as f:
            data = json.load(f)
            key = data.get("api_key")
            if key:
                return key

    return None


def get_data_api_service(api_key=None):
    """Build and return YouTube Data API v3 service object."""
    try:
        from googleapiclient.discovery import build
    except ImportError:
        return None, {
            "error": "google-api-python-client not installed",
            "fix": "pip install google-api-python-client google-auth-oauthlib",
        }

    if api_key is None:
        api_key = get_api_key()

    if not api_key:
        return None, {
            "error": "YouTube API key not found",
            "fix": (
                "Set YOUTUBE_API_KEY environment variable or add to "
                "~/.claude/youtube-credentials.json as {\"api_key\": \"YOUR_KEY\"}. "
                "Get a key at https://console.cloud.google.com/apis/credentials"
            ),
        }

    try:
        service = build("youtube", "v3", developerKey=api_key)
        return service, None
    except Exception as e:
        return None, {"error": f"Failed to build YouTube service: {e}"}


def get_oauth_service(scopes=None):
    """Build YouTube Analytics API service with OAuth 2.0."""
    try:
        from google.auth.transport.requests import Request
        from google.oauth2.credentials import Credentials
        from google_auth_oauthlib.flow import InstalledAppFlow
        from googleapiclient.discovery import build
    except ImportError:
        return None, {
            "error": "OAuth dependencies not installed",
            "fix": "pip install google-api-python-client google-auth-oauthlib",
        }

    if scopes is None:
        scopes = [
            "https://www.googleapis.com/auth/yt-analytics.readonly",
            "https://www.googleapis.com/auth/youtube.readonly",
        ]

    TMP_DIR.mkdir(parents=True, exist_ok=True)
    creds = None

    if TOKEN_PATH.exists():
        try:
            creds = Credentials.from_authorized_user_file(str(TOKEN_PATH), scopes)
        except Exception:
            creds = None

    if creds and creds.expired and creds.refresh_token:
        try:
            creds.refresh(Request())
            with open(TOKEN_PATH, "w") as f:
                f.write(creds.to_json())
        except Exception:
            creds = None

    if not creds or not creds.valid:
        if not CLIENT_SECRETS_PATH.exists():
            return None, {
                "error": "OAuth client secrets not found",
                "fix": (
                    f"Download OAuth 2.0 client secrets from Google Cloud Console "
                    f"and save to {CLIENT_SECRETS_PATH}. "
                    f"Guide: https://developers.google.com/youtube/analytics/registering_an_application"
                ),
            }

        try:
            flow = InstalledAppFlow.from_client_secrets_file(
                str(CLIENT_SECRETS_PATH), scopes
            )
            creds = flow.run_local_server(port=0)
            with open(TOKEN_PATH, "w") as f:
                f.write(creds.to_json())
        except Exception as e:
            return None, {"error": f"OAuth flow failed: {e}"}

    try:
        service = build("youtubeAnalytics", "v2", credentials=creds)
        return service, None
    except Exception as e:
        return None, {"error": f"Failed to build Analytics service: {e}"}


def check_auth(auth_type):
    """Check if authentication is configured and return status."""
    if auth_type == "api_key":
        key = get_api_key()
        if key:
            masked = key[:4] + "..." + key[-4:]
            return {"status": "ok", "type": "api_key", "key": masked}
        return {"status": "missing", "type": "api_key",
                "fix": "Set YOUTUBE_API_KEY env var or add to ~/.claude/youtube-credentials.json"}

    elif auth_type == "oauth":
        if TOKEN_PATH.exists():
            return {"status": "ok", "type": "oauth", "token_path": str(TOKEN_PATH)}
        if CLIENT_SECRETS_PATH.exists():
            return {"status": "needs_auth", "type": "oauth",
                    "message": "Client secrets found but no token yet. Run OAuth flow."}
        return {"status": "missing", "type": "oauth",
                "fix": f"Download OAuth client secrets to {CLIENT_SECRETS_PATH}"}

    return {"status": "error", "message": f"Unknown auth type: {auth_type}"}


def main():
    parser = argparse.ArgumentParser(description="YouTube API auth manager")
    parser.add_argument("--check", choices=["api_key", "oauth"],
                        help="Check auth status")
    args = parser.parse_args()

    if args.check:
        result = check_auth(args.check)
        print(json.dumps(result, indent=2))
        sys.exit(0 if result["status"] == "ok" else 1)
    else:
        parser.print_help()


if __name__ == "__main__":
    main()
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall