<commit_before>import re
from urllib.parse import urlparse

from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service


class Pokemon(Service, OpenGraphThumbMixin):
    supported_domains = ["pokemon.com"]

    def get(self):
        data = self.get_urldata()

        parse = urlparse(self.url)
        match = re.search(r"^/([a-z]{2})/", parse.path)
        if not match:
            yield ServiceError("Cant county code")
            return

        res = self.http.get(f"http://www.pokemon.com/api/pokemontv/channels?region={match.group(1)}")
        janson = res.json()
        match = re.search('data-video-season="([0-9]+)"', data)
        season = match.group(1)
        match = re.search('data-video-episode="([0-9]+)"', data)
        episode = match.group(1)

        for i in janson:
            for n in i["media"]:
                if season == n["season"] and episode == n["episode"]:
                    stream = n["stream_url"]

        self.output["title"] = "pokemon"
        self.output["season"] = season
        self.output["episode"] = episode

        yield from hlsparse(self.config, self.http.request("get", stream), stream, output=self.output)
<commit_msg>pokemon: make it work with the website<commit_after>import re
from urllib.parse import urlparse

from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service


class Pokemon(Service, OpenGraphThumbMixin):
    supported_domains = ["watch.pokemon.com"]

    def get(self):
        parse = urlparse(self.url)
        if parse.fragment == "":
            yield ServiceError("need the whole url")
            return

        match = re.search(r"id=([a-f0-9]+)\&", parse.fragment)
        if not match:
            yield ServiceError("Cant find the ID in the url")
            return

        res = self.http.get("https://www.pokemon.com/api/pokemontv/v2/channels/us/")

        janson = res.json()
        stream = None
        for i in janson:
            for n in i["media"]:
                if n["id"] == match.group(1):
                    stream = n
                    break

        self.output["title"] = "pokemon"
        self.output["season"] = stream["season"]
        self.output["episode"] = stream["episode"]
        self.output["episodename"] = stream["title"]

        yield from hlsparse(self.config, self.http.request("get", stream["stream_url"]), stream["stream_url"], output=self.output)

{'fraction_non_alphanumeric': 0.13149847094801223, 'fraction_numerical': 0.0045871559633027525, 'mean_word_length': 2.546070460704607, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '106499', 'n_tokens_mistral': 836, 'n_tokens_neox': 808, 'n_words': 182}