2016-09-04 20:44:25 +02:00
|
|
|
import re
|
2018-01-30 22:07:21 +01:00
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
2016-09-04 20:44:25 +02:00
|
|
|
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
|
2016-09-04 20:44:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Pokemon(Service, OpenGraphThumbMixin):
|
2021-09-08 10:16:00 +02:00
|
|
|
supported_domains = ["watch.pokemon.com"]
|
2016-09-04 20:44:25 +02:00
|
|
|
|
|
|
|
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)
|
2016-09-04 20:44:25 +02:00
|
|
|
if not match:
|
2021-09-08 10:16:00 +02:00
|
|
|
yield ServiceError("Cant find the ID in the url")
|
2016-09-04 20:44:25 +02:00
|
|
|
return
|
|
|
|
|
2021-09-10 20:14:24 +02:00
|
|
|
match2 = re.search(r'region: "(\w+)"', self.get_urldata())
|
|
|
|
if not match2:
|
|
|
|
yield ServiceError("Can't find region data")
|
|
|
|
return
|
2016-09-04 20:44:25 +02:00
|
|
|
|
2021-09-10 20:14:24 +02:00
|
|
|
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
|
2016-09-04 20:44:25 +02:00
|
|
|
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
|
2016-09-04 20:44:25 +02:00
|
|
|
|
2021-09-10 20:14:24 +02:00
|
|
|
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"]
|
2016-09-04 20:44:25 +02:00
|
|
|
|
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)
|