Skip to content

Commit

Permalink
Bug fix for Napiprojekt downloads under some conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
destpstrzy committed Dec 18, 2024
1 parent 87f32dc commit 407d1c5
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions custom_libs/subliminal_patch/providers/napiprojekt.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def __init__(self, only_authors=None, only_real_names=None):
self.only_real_names = only_real_names

def query(self, language, hash):
if self.only_authors or self.only_real_names:
return None
params = {
'v': 'dreambox',
'kolejka': 'false',
Expand All @@ -74,11 +72,23 @@ def query(self, language, hash):
return subtitle

def list_subtitles(self, video, languages):
def flatten(l):
return [item for sublist in l for item in sublist]
def flatten(nested_list):
"""Flatten a nested list."""
return [item for sublist in nested_list for item in sublist]

# Determine the source of subtitles based on conditions
hash_subtitles = []
if not (self.only_authors or self.only_real_names):
hash_subtitles = [
subtitle
for language in languages
if (subtitle := self.query(language, video.hashes.get('napiprojekt'))) is not None
]

# Scrape additional subtitles
scraped_subtitles = flatten([self._scrape(video, language) for language in languages])

return [s for s in [self.query(l, video.hashes['napiprojekt']) for l in languages] if s is not None] + \
flatten([self._scrape(video, l) for l in languages])
return hash_subtitles + scraped_subtitles

def download_subtitle(self, subtitle):
if subtitle.content is not None:
Expand Down Expand Up @@ -125,7 +135,7 @@ def _scrape(self, video, language):
author = ""

if self.only_authors:
if author.lower() in ["brak", "automat", "si", "chatgpt", "ai", "robot"]:
if author.lower() in ["brak", "automat", "si", "chatgpt", "ai", "robot", "maszynowe", "tłumaczenie maszynowe"]:
continue

if self.only_real_names:
Expand Down

0 comments on commit 407d1c5

Please sign in to comment.