File size: 1,674 Bytes
a09a20c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""Test YouTube API integration"""

import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

print("๐Ÿงช Testing YouTube Data API Integration")
print("=" * 60)
print()

# Test 1: Check API key
api_key = os.getenv("YOUTUBE_API_KEY")
if api_key:
    print(f"โœ… API Key found: {api_key[:10]}...{api_key[-5:]}")
else:
    print("โŒ API Key not found in environment")
    exit(1)

print()

# Test 2: Import and initialize
try:
    from youtube_api import YouTubeAPIClient
    print("โœ… YouTubeAPIClient imported successfully")
    
    client = YouTubeAPIClient(api_key)
    print("โœ… YouTubeAPIClient initialized")
except Exception as e:
    print(f"โŒ Import/initialization failed: {e}")
    exit(1)

print()

# Test 3: Search for videos
try:
    print("๐Ÿ“บ Searching for: 'League of Legends Miss Fortune guide'")
    videos = client.search_videos('League of Legends Miss Fortune guide', 3)
    
    print(f"โœ… Found {len(videos)} videos")
    print()
    
    if videos:
        for i, video in enumerate(videos, 1):
            print(f"{i}. {video.get('title', 'No title')}")
            print(f"   URL: {video.get('url', 'No URL')}")
            print(f"   Views: {video.get('views', 'Unknown')}")
            print(f"   Duration: {video.get('duration', 'Unknown')}")
            print()
        
        print("=" * 60)
        print("๐ŸŽ‰ SUCCESS! YouTube Data API is working perfectly!")
        print("=" * 60)
    else:
        print("โš ๏ธ  No videos found (might be API issue)")
        
except Exception as e:
    print(f"โŒ Search failed: {e}")
    import traceback
    traceback.print_exc()
    exit(1)