# -*- coding: utf-8 -*-
import requests
from scraper.utils.resolve import Resolver

class SweetTV(Resolver):
    """
    Sweet.tv free TV kanaly - https://sweet.tv/sk/free_tv
    """
    def __init__(self):
        self.channels = {
        "3787": "MEGAHIT HD",
        "3583": "Worldwide Hits HD",
        "2981": "Top Movies HD",
        "2488": "Travel & Adventures HD",
        "3257": "The World Inside Out HD",
        "3399": "Smurfs HD",
        "3599": "PAW Patrol HD",
        "3825": "Premium ACTION HD",
        "3829": "Premium COMEDY HD",
        "3833": "Premium THRILLER HD",
        "3831": "Premium DRAMA HD",
        "3828": "PREMIERE HD",
        "3315": "Saving Hope HD",
        "3642": "Money Games HD",
        "3578": "Adventure Caleidoscope HD",
        "2006": "Action Zone HD",
        "3824": "Action Plus HD",
        "2007": "Comedy Universe HD",
        "3775": "Romance HD",
        "2005": "Family Fun HD",
        "2008": "Real Drama HD",
        "2009": "Thriller Time HD",
        "3790": "Thriller Plus HD",
        "3830": "Crime TV HD",
        "3826": "Sci-Fi & Fantasy HD",
        "3479": "Horror Land HD",
        "3581": "Big Steps HD",
        "2318": "Murder maps HD",
        "2323": "Political History HD",
        "2331": "Presidents & leaders HD",
        "2648": "Men With The Pot HD",
        "3621": "SpongeBob SquarePants HD",
        "3517": "Mattel Junior HD",
        "3633": "Loud House HD",
        "3606": "Teenage Mutant Ninja Turtles HD",
        "3649": "Trace Sport Stars HD",
        "3784": "World of free sports HD",
        "3098": "Unbeaten Channel HD",
        "3128": "Sport Fishing HD",
        "3009": "Truth About Sports HD",
        "2322": "Historical Figures HD",
        "3560": "Science & Innovation HD",
        "3605": "Movie legends HD",
        "2321": "Fashion history HD",
        "3162": "Hollywood stories HD",
        "2320": "Movie stars HD",
        "2319": "Video killed the radio star HD",
        "2329": "Monarchies & Dynasties HD",
        "2330": "Raiders of the lost art HD",
        "2328": "Legends of the opera HD",
        "2338": "World's personalities HD",
        "2337": "Myths & Monsters HD",
        "2659": "Pure Nature HD",
        "3319": "Cooking with Byron Talbott HD",
        "3443": "Talking Tom Shorts HD",
        "3110": "Cocobi TV. Song HD",
        "3109": "Cocobi TV. Fun Play HD",
        "3591": "BABY SHARK TV HD",
        "3453": "Blip TV HD",
        "3487": "Magical Smile TV HD",
        "3474": "Family Entertainment TV HD",
        "3339": "English club HD",
        "2105": "Da Vinci: Explore the World HD",
        "2114": "Da Vinci: Operation Ouch HD",
        "2099": "Da Vinci: Fun Learning HD",
        "3687": "Trace Urban HD",
        "3715": "Trace UK HD",
        "3712": "Trace Brasil HD",
        "3684": "Trace Latina HD",
        "2302": "London Live Music HD",
        "2307": "LivePop Concerts HD",
        "3406": "France 24 HD"
        }

    def grab(self, channel_id):
        if channel_id not in self.channels:
            return "Channel not found", {}
        headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
            "Content-Type": "application/json",
            "Referer": "https://sweet.tv/sk/free_tv",
            "Origin": "https://sweet.tv"
        }
        try:
            r = requests.post("https://api.sweet.tv/TvService/OpenStream.json", json={"channel_id": int(channel_id)}, headers=headers, timeout=15)
            data = r.json()
            if data.get("result") == "OK":
                url = data.get("url", "")
                if url:
                    return url, headers
            return "", {}
        except Exception:
            return "", {}
