return None when None/key not exist

This commit is contained in:
kclauhk 2024-08-21 20:54:55 +08:00
parent b28dc2a424
commit 6f6cab852d

View File

@ -38,7 +38,8 @@ def slugify(string):
def get_field(field_name, idx, webpage, data): def get_field(field_name, idx, webpage, data):
value = self._html_search_regex(rf'{idx}\.{field_name}=(?P<a>"?(?P<b>.+?)"?);', webpage, value = self._html_search_regex(rf'{idx}\.{field_name}=(?P<a>"?(?P<b>.+?)"?);', webpage,
field_name, default=None, group=('a', 'b')) field_name, default=None, group=('a', 'b'))
return value[1] if value[1] != value[0] else (data.get(value[0]) or value[0]) 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]))
idx = idx.replace('$', r'\$') idx = idx.replace('$', r'\$')
video_id = get_field('id', idx, webpage, data) video_id = get_field('id', idx, webpage, data)
@ -139,7 +140,7 @@ def _real_extract(self, url):
description = self._html_search_meta('description', webpage, 'description', default=None) description = self._html_search_meta('description', webpage, 'description', default=None)
data_set = self._extract_data(webpage, video_id) data_set = self._extract_data(webpage, video_id)
info = {} info = {}
if idx := self._html_search_regex(rf'([\w\$]{{2,4}})\.seasonAndEpisode="{season_episode}";', if idx := self._html_search_regex(rf'([\w\$]{{1,4}})\.seasonAndEpisode="{season_episode}";',
webpage, 'data_idx', default=None): webpage, 'data_idx', default=None):
info = self._extract_by_idx(idx, webpage, data_set, video_id) info = self._extract_by_idx(idx, webpage, data_set, video_id)
@ -180,7 +181,7 @@ def _real_extract(self, url):
'description', default=None) 'description', default=None)
data_set = self._extract_data(webpage, series_id) data_set = self._extract_data(webpage, series_id)
entries = [] entries = []
for idx_se in sorted(re.findall(r'([\w\$]{2,4})\.seasonAndEpisode="([^"]+)";', webpage), for idx_se in sorted(re.findall(r'([\w\$]{1,4})\.seasonAndEpisode="([^"]+)";', webpage),
key=lambda x: x[1]): key=lambda x: x[1]):
if entry := self._extract_by_idx(idx_se[0], webpage, data_set): if entry := self._extract_by_idx(idx_se[0], webpage, data_set):
entry['series_id'] = series_id entry['series_id'] = series_id