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