Skip to content

Commit

Permalink
Fix Hosszupuska provider not returning results
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko98 committed Nov 30, 2021
1 parent cce6857 commit 247f69c
Show file tree
Hide file tree
Showing 4 changed files with 2,227 additions and 15 deletions.
38 changes: 23 additions & 15 deletions libs/subliminal_patch/providers/hosszupuska.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def fix_inconsistent_naming(title):

language_converters.register('hosszupuska = subliminal_patch.converters.hosszupuska:HosszupuskaConverter')

_SUB_ENGLISH_NAME_RE = re.compile(r's(\d{1,2})e(\d{1,2})')
_SUB_YEAR_RE = re.compile(r"(?<=\()(\d{4})(?=\))")


class HosszupuskaSubtitle(Subtitle):
"""Hosszupuska Subtitle."""
Expand Down Expand Up @@ -141,11 +144,10 @@ def get_language(self, text):
return None

def query(self, series, season, episode, year=None, video=None):

# Search for s01e03 instead of s1e3
seasona = "%02d" % season
episodea = "%02d" % episode
series = fix_inconsistent_naming(series)
seriesa = fix_inconsistent_naming(series)
seriesa = series.replace(' ', '+')

# get the episode page
Expand All @@ -156,16 +158,22 @@ def query(self, series, season, episode, year=None, video=None):

r = self.session.get(url, timeout=10).content

i = 0
soup = ParserBeautifulSoup(r, ['lxml'])

table = soup.find_all("table")[9]

subtitles = []
# loop over subtitles rows

for num, temp in enumerate(soup.find_all("table")):
if "this.style.backgroundImage='url(css/over2.jpg)" in str(temp) and "css/infooldal.png" in str(temp):
logger.debug("Found valid table (%d index)", num)
subtitles += self._loop_over_table(temp, season, episode, video)

return subtitles

def _loop_over_table(self, table, season, episode, video):
i = 0
for row in table.find_all("tr"):
i = i + 1
if "this.style.backgroundImage='url(css/over2.jpg)" in str(row) and i > 5:
if "this.style.backgroundImage='url(css/over2.jpg)" in str(row): #and i > 5:
datas = row.find_all("td")

# Currently subliminal not use these params, but maybe later will come in handy
Expand All @@ -177,18 +185,20 @@ def query(self, series, season, episode, year=None, video=None):

sub_year = sub_english_name = sub_version = None
# Handle the case when '(' in subtitle


if datas[1].getText().count('(') == 1:
sub_english_name = re.split('s(\d{1,2})e(\d{1,2})', datas[1].getText())[3]
sub_english_name = _SUB_ENGLISH_NAME_RE.split(datas[1].getText())[3]
if datas[1].getText().count('(') == 2:
sub_year = re.findall(r"(?<=\()(\d{4})(?=\))", datas[1].getText().strip())[0]
sub_english_name = re.split('s(\d{1,2})e(\d{1,2})', datas[1].getText().split('(')[0])[0]
sub_year = _SUB_YEAR_RE.findall(datas[1].getText().strip())[0]
sub_english_name = _SUB_ENGLISH_NAME_RE.split(datas[1].getText().split('(')[0])[0]

if not sub_english_name:
continue

sub_season = int((re.findall('s(\d{1,2})', datas[1].find_all('b')[0].getText(), re.VERBOSE)[0])
sub_season = int((re.findall(r's(\d{1,2})', datas[1].find_all('b')[0].getText(), re.VERBOSE)[0])
.lstrip('0'))
sub_episode = int((re.findall('e(\d{1,2})', datas[1].find_all('b')[0].getText(), re.VERBOSE)[0])
sub_episode = int((re.findall(r'e(\d{1,2})', datas[1].find_all('b')[0].getText(), re.VERBOSE)[0])
.lstrip('0'))

if sub_season == season and sub_episode == episode:
Expand All @@ -209,9 +219,7 @@ def query(self, series, season, episode, year=None, video=None):
asked_for_episode=episode)

logger.debug('Found subtitle: %r', subtitle)
subtitles.append(subtitle)

return subtitles
yield subtitle

def list_subtitles(self, video, languages):
titles = [video.series] + video.alternative_series
Expand Down

1 comment on commit 247f69c

@vitiko98
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.