1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

more cleanup

This commit is contained in:
Gustav Ahlberg 2018-08-24 01:51:17 +02:00 committed by Johan Andersson
parent 471a3a8711
commit 8cc2d5625e

View File

@ -8,10 +8,28 @@ from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
def findCourse(data, courseSlug):
for c in data["content"]["coursePages"]:
if c["slug"] == courseSlug:
return c
return None
def findLesson(course, lessonSlug):
for l in course["lessons"]:
if l["slug"] == lessonSlug:
return l
return None
class Koket(Service, OpenGraphThumbMixin): class Koket(Service, OpenGraphThumbMixin):
supported_domains = ['koket.se'] supported_domains = ['koket.se']
supported_path = "/kurser" supported_path = "/kurser"
def __init__(self, config, _url, http=None):
Service.__init__(self, config, _url, http)
self._data = None
def get(self): def get(self):
urlp = urlparse(self.url) urlp = urlparse(self.url)
slugs = urlp.path.split('/') slugs = urlp.path.split('/')
@ -24,26 +42,20 @@ class Koket(Service, OpenGraphThumbMixin):
yield ServiceError("Could not login") yield ServiceError("Could not login")
return return
auth_token = self._getAuthToken() data = self._getData()
authDataRes = self.http.get("https://www.koket.se/kurser/api/data/{}".format(auth_token)) if data is None:
yield ServiceError("Could not fetch data")
return
authDataJson = authDataRes.json() course = findCourse(data, courseSlug)
courses = authDataJson["content"]["coursePages"] if course is None:
for c in courses:
if c["slug"] == courseSlug:
course = c
if not course:
yield ServiceError("Could not find course") yield ServiceError("Could not find course")
return return
lessons = course["lessons"] lesson = findLesson(course, lessonSlug)
for l in lessons:
if l["slug"] == lessonSlug:
lesson = l
if not lesson: if lesson is None:
yield ServiceError("Could not find lesson") yield ServiceError("Could not find lesson")
return return
@ -60,6 +72,7 @@ class Koket(Service, OpenGraphThumbMixin):
yield streams[n] yield streams[n]
def _login(self): def _login(self):
if self._getAuthToken() is None:
username = self.config.get("username") username = self.config.get("username")
password = self.config.get("password") password = self.config.get("password")
@ -82,3 +95,13 @@ class Koket(Service, OpenGraphThumbMixin):
def _getAuthToken(self): def _getAuthToken(self):
return self.http.cookies.get("authToken") return self.http.cookies.get("authToken")
def _getData(self):
auth_token = self._getAuthToken()
if auth_token is None:
return None
if self._data is None:
self._data = self.http.get("https://www.koket.se/kurser/api/data/{}".format(auth_token)).json()
return self._data