def youtube_search(query, max_results=5): """Call YouTube Data API and return a list of dicts with video info.""" params = "part": "snippet", "q": query, "type": "video", "order": "date", # newest first "maxResults": max_results, "key": YOUTUBE_API_KEY, "regionCode": "IN", # focus on Indian region (Tamil content) "relevanceLanguage": "ta" # Tamil language bias resp = requests.get(YOUTUBE_SEARCH_URL, params=params) resp.raise_for_status() data = resp.json()
<script> // Auto‑run the query on page load const query = "havoc brother song tamil latest"; havoc brother song tamil latest
fetch(`/search?q=$encodeURIComponent(query)`) .then(r => r.json()) .then(data => if (data.error) document.getElementById('results').innerText = "Error: " + data.error; return; const container = document.getElementById('results'); data.videos.forEach(v => const card = document.createElement('div'); card.className = 'video-card'; card.innerHTML = ` <img src="$v.thumb" alt="thumb"> <div> <strong>$v.title</strong><br> <small>Channel: $v.channel<br> Published: $new Date(v.published).toLocaleDateString()</small> </div>`; card.onclick = () => loadVideo(v.video_id); container.appendChild(card); ); ) .catch(err => document.getElementById('results').innerText = "Fetch error: " + err; ); # newest first "maxResults": max_results
# ---------------------------------------------------------------------- # CONFIG – put your YouTube API key in an environment variable for safety # ---------------------------------------------------------------------- YOUTUBE_API_KEY = os.getenv("YT_API_KEY") YOUTUBE_SEARCH_URL = "https://www.googleapis.com/youtube/v3/search" fetch(`/search?q=$encodeURIComponent(query)`) .then(r =>
app = Flask(__name__)