import json
from g4f.client import Client

def generate_video_podcast_data(subject, language):
    client = Client()
    system_prompt = f"""You are a JSON generator. Your ONLY task is to output valid JSON.

CRITICAL RULES:
1. Output ONLY valid JSON - no explanations, no markdown, no extra text
2. Do NOT use ```json code blocks
3. Do NOT include any text before or after the JSON
4. Response must be in {language} language
5. Use this EXACT structure: {{"context": "string", "specific_focus": "string"}}

Generate video podcast data for: {subject}

Requirements:
- context: Comprehensive background information about {subject}
- specific_focus: Specific angle or focus point for the podcast
- All text must be in {language}
- Response format: {{"context": "...", "specific_focus": "..."}}

RESPOND WITH ONLY THE JSON OBJECT."""
 
    response = client.chat.completions.create(
        model="gpt-5-nano",
        provider="PollinationsAI",
        messages=[
            {"role": "system", "content": "You are a JSON generator. Output only valid JSON with no additional text or formatting."},
            {"role": "user", "content": system_prompt}
        ],
        web_search=False
    )
    
    print(response.choices[0].message.content)
    data = response.choices[0].message.content
    
    try:
        # Fixed: Remove the indent parameter from json.loads()
        js = json.loads(data)
        context = js.get("context")
        specific_focus = js.get("specific_focus")
        return context, specific_focus
    except json.JSONDecodeError as e:
        print(f"JSON parsing error: {e}")
        print(f"Raw response: {data}")
        # Return default values or re-raise the exception
        return None, None