Skip to content

Commit

Permalink
Update kidoodletv.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kclauhk committed Dec 17, 2024
1 parent e9d5849 commit 9f90121
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions yt_dlp/extractor/kidoodletv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

class KidoodleTVBaseIE(InfoExtractor):
def _extract_data(self, webpage, video_id):
keys = self._html_search_regex(r'__NUXT__=\(function\(([^\)]+)\)\{', webpage, 'key', default=None)
keys = self._html_search_regex(r'__NUXT__=\(function\(([^\)]+)\)\{', webpage,
'key', default=None)
key_list = self._parse_json(js_to_json(f'[{keys}]'), video_id, fatal=False)
data = self._html_search_regex(r'\}\}\}\((".+)\)\);</script>', webpage, 'data', default=None)
data = self._html_search_regex(r'\}\}\}\((".+)\)\);</script>', webpage,
'data', default=None)
data_list = self._parse_json(js_to_json(f'[{data}]'), video_id, fatal=False)
data_set = {}
if key_list and data_list and (len(data_list) == len(key_list)):
Expand All @@ -36,8 +38,8 @@ def slugify(string):
return re.sub(r'^-+|-+$', '', s)

def get_field(field_name, idx, webpage, data):
value = self._html_search_regex(rf'{idx}\.{field_name}=(?P<a>"?(?P<b>.+?)"?);', webpage,
field_name, default=None, group=('a', 'b'))
value = self._html_search_regex(rf'{idx}\.{field_name}=(?P<a>"?(?P<b>.+?)"?);',
webpage, field_name, default=None, group=('a', 'b'))
return (value[1] if value[1] != value[0] else (
data.get(value[0]) if re.search(r'^[a-zA-Z_\$]{1,4}$', value[0]) else value[0]))

Expand Down Expand Up @@ -114,8 +116,10 @@ def _real_extract(self, url):
fatal=False, expected_status=(404, 500))
if 'Server error' in webpage or 'Something went wrong' in webpage:
qs = urlencode_postdata({'origin': urllib.parse.urlparse(url).path})
self._download_webpage(f'https://kidoodle.tv/welcome?{qs}', video_id, note='Downloading welcome page')
self._download_webpage(f'https://kidoodle.tv/welcome/verify?{qs}', video_id, note='Performing age verification')
self._download_webpage(f'https://kidoodle.tv/welcome?{qs}', video_id,
note='Downloading welcome page')
self._download_webpage(f'https://kidoodle.tv/welcome/verify?{qs}', video_id,
note='Performing age verification')
# the above lines download the webpages to change verification status, not really get verified
webpage = self._download_webpage(url, video_id)

Expand Down Expand Up @@ -147,21 +151,22 @@ class KidoodleTVSeriesIE(KidoodleTVBaseIE):
}]

def _real_extract(self, url):
def extract_video(idx):
if video := self._extract_by_idx(idx, webpage, data_set):
video['series_id'] = series_id
video['webpage_url'] = join_nonempty('https://kidoodle.tv', series_id, slug,
video['display_id'], delim='/')
video['webpage_url_basename'] = video['display_id']
return video
return None

series_id, slug = self._match_valid_url(url).group('id', 'slug')
webpage = self._download_webpage(url, series_id)

title = self._html_search_regex(r'<h2[^>]+>(.*?)</h2>', webpage, 'title', default=None)
description = self._html_search_regex(r'<p class="mb[^>]+>(.*?)</p>', webpage,
'description', default=None)
data_set = self._extract_data(webpage, series_id)
entries = []
for idx_se in sorted(re.findall(r'([\w\$]{1,4})\.seasonAndEpisode="([^"]+)";', webpage),
key=lambda x: x[1]):
if entry := self._extract_by_idx(idx_se[0], webpage, data_set):
entry['series_id'] = series_id
entry['webpage_url'] = join_nonempty('https://kidoodle.tv', series_id, slug,
entry['display_id'], delim='/')
entry['webpage_url_basename'] = entry['display_id']
entries.append(entry)

return self.playlist_result(entries, series_id, title, description)
idx = sorted(re.findall(r'([\w\$]{1,4})\.seasonAndEpisode="([^"]+)";', webpage),
key=lambda x: x[1])
return self.playlist_result((extract_video(e[0]) for e in idx),
series_id, title, description)

0 comments on commit 9f90121

Please sign in to comment.