import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

from app import create_app, db
from app.models.learning import VocationalContent

app = create_app('development')
with app.app_context():
    # _ebOk8C1-po has embedding DISABLED by the video owner on YouTube.
    # Replace all entries using it with Njv1-GBMXt4 (Advanced Fashion Tailoring - confirmed embed-enabled)
    blocked_url = 'https://www.youtube.com/embed/_ebOk8C1-po'
    working_url = 'https://www.youtube.com/embed/Njv1-GBMXt4'
    
    items = VocationalContent.query.filter_by(resource_url=blocked_url).all()
    print(f'Found {len(items)} items with blocked URL')
    for item in items:
        item.resource_url = working_url
        print(f'Fixed: [{item.language}] id={item.id}')
    
    db.session.commit()
    
    # Verify
    remaining = VocationalContent.query.filter_by(resource_url=blocked_url).count()
    print(f'Remaining blocked: {remaining}')
    print('Done.')
