import sys
import time
from pathlib import Path

sys.path.append(str(Path("05_Production_Pipeline").resolve()))
from invisible_playwright import InvisiblePlaywright
from muse_invpw_driver import sync_worker_profile, DEFAULT_PROFILE

def inspect_download_button():
    sync_worker_profile()
    with InvisiblePlaywright(profile_dir=DEFAULT_PROFILE, headless=True) as ctx:
        page = ctx.pages[0] if ctx.pages else ctx.new_page()
        page.goto("https://muse.ai", wait_until="domcontentloaded", timeout=30000)
        time.sleep(3)
        
        btn = page.locator('button[aria-label*="Tải video xuống"]').last
        if btn.count() > 0:
            print("Button outerHTML:")
            print(btn.evaluate("el => el.outerHTML"))
            print("\nButton parent outerHTML:")
            print(btn.evaluate("el => el.parentElement.outerHTML"))
            
            # Check video tag src
            videos = page.locator("video").all()
            print(f"\nVideos count: {len(videos)}")
            for i, v in enumerate(videos):
                print(f"Video [{i}]: src={v.get_attribute('src')}, currentSrc={v.evaluate('el => el.currentSrc')}")
        else:
            print("No button found")

if __name__ == "__main__":
    inspect_download_button()
