1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 12:15:40 +01:00
svtplay-dl/lib/svtplay_dl/service/pokemon.py

48 lines
1.5 KiB
Python
Raw Normal View History

import re
2018-01-30 22:07:21 +01:00
from urllib.parse import urlparse
from svtplay_dl.error import ServiceError
2019-08-25 00:40:39 +02:00
from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service
class Pokemon(Service, OpenGraphThumbMixin):
2021-09-08 10:16:00 +02:00
supported_domains = ["watch.pokemon.com"]
def get(self):
parse = urlparse(self.url)
2021-09-08 10:16:00 +02:00
if parse.fragment == "":
yield ServiceError("need the whole url")
return
match = re.search(r"id=([a-f0-9]+)\&", parse.fragment)
if not match:
2021-09-08 10:16:00 +02:00
yield ServiceError("Cant find the ID in the url")
return
match2 = re.search(r'region: "(\w+)"', self.get_urldata())
if not match2:
yield ServiceError("Can't find region data")
return
res = self.http.get(f"https://www.pokemon.com/api/pokemontv/v2/channels/{match2.group(1)}/")
2021-09-08 10:16:00 +02:00
janson = res.json()
stream = None
for i in janson:
for n in i["media"]:
2021-09-08 10:16:00 +02:00
if n["id"] == match.group(1):
stream = n
break
if stream is None:
yield ServiceError("Can't find video")
return
2018-05-13 13:06:45 +02:00
self.output["title"] = "pokemon"
2021-09-08 10:16:00 +02:00
self.output["season"] = stream["season"]
self.output["episode"] = stream["episode"]
self.output["episodename"] = stream["title"]
2021-09-08 10:16:00 +02:00
yield from hlsparse(self.config, self.http.request("get", stream["stream_url"]), stream["stream_url"], output=self.output)