Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtitle Post-Processing Fix #552

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/subsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, pref_counter: float) -> None:
self.system_tray.start()

if self.file_exist:
VIDEO_FILE.file_hash = io_file_system.get_file_hash(VIDEO_FILE.file_path)
io_log.stdout_dataclass(VIDEO_FILE, level="debug", print_allowed=False)
io_file_system.create_directory(VIDEO_FILE.file_directory)

Expand Down Expand Up @@ -173,23 +174,23 @@ def subtitle_post_processing(self):
@decorators.call_conditions
def subtitle_rename(self) -> None:
io_log.stdout_in_brackets("Renaming best match")
self.core_state.set_state(self.core_state.state.AUTOLOAD_RENAME)
self.core_state.set_state(self.core_state.state.SUBTITLE_RENAME)
new_name = io_file_system.autoload_rename(VIDEO_FILE.filename, ".srt")
self.autoload_src = new_name
io_log.stdout("Done with task", level="info", end_new_line=True)

@decorators.call_conditions
def subtitle_move_best(self, target: Path) -> None:
io_log.stdout_in_brackets("Move best match")
self.core_state.set_state(self.core_state.state.AUTOLOAD_MOVE)
self.core_state.set_state(self.core_state.state.SUBTITLE_MOVE)

io_file_system.move_and_replace(self.autoload_src, target)
io_log.stdout("Done with task", level="info", end_new_line=True)

@decorators.call_conditions
def subtitle_move_all(self, target: Path) -> None:
io_log.stdout_in_brackets("Move all")
self.core_state.set_state(self.core_state.state.AUTOLOAD_MOVE_ALL)
self.core_state.set_state(self.core_state.state.SUBTITLE_MOVE_ALL)
io_file_system.move_all(VIDEO_FILE.subs_dir, target)
io_log.stdout("Done with task", level="info", end_new_line=True)

Expand Down
4 changes: 2 additions & 2 deletions src/subsearch/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ def conditions(cls: Union["core.SubsearchCore", "core.Initializer"], *args, **kw
],
"extract_files": [len(cls.accepted_subtitles) >= 1],
"subtitle_post_processing": [],
"subtitle_rename": [cls.app_config.subtitle_post_processing["rename"], cls.subtitles_found > 1],
"subtitle_rename": [cls.app_config.subtitle_post_processing["rename"], cls.subtitles_found >= 1],
"subtitle_move_best": [
cls.app_config.subtitle_post_processing["move_best"],
cls.subtitles_found > 1,
cls.subtitles_found >= 1,
not cls.app_config.subtitle_post_processing["move_all"],
],
"subtitle_move_all": [cls.app_config.subtitle_post_processing["move_all"], cls.subtitles_found > 1],
Expand Down
28 changes: 10 additions & 18 deletions src/subsearch/utils/imdb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,20 @@ def __init__(self, title: str, year: int):

url = adv_search.get_url()
tree = core_provider.get_html_parser(url)
product = tree.select("div.lister-item-content")

for item in product.matches:
self.data = item.css_first("h3.lister-item-header")
product = tree.css("a.ipc-title-link-wrapper h3.ipc-title__text")

if self.title != self.find_imdb_title():
for item in product:
href_ = item.parent.attrs["href"]
imdb_id = href_.split("/")[2]
title_ = item.text().split(". ")[-1]
year_ = int(item.parent.parent.next.child.child.html)

if self.title != title_.lower():
continue

if self.year != self.find_imdb_year() and (self.year - 1) != self.find_imdb_year():
if self.year != year_ and (self.year - 1) != year_:
continue

self.id = self.get_imdb_id()
self.id = imdb_id
break

def find_imdb_title(self) -> str:
title = self.data.css_first("a").text()
return title.lower()

def find_imdb_year(self) -> int:
year = self.data.css_first("span.lister-item-year").child.text_content
return int(re.findall("[0-9]+", year)[0])

def get_imdb_id(self) -> str:
href = self.data.css_first("a")
return re.findall("tt[0-9]+", href.attributes["href"])[0]
6 changes: 3 additions & 3 deletions src/subsearch/utils/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class CoreState(Enum):
CALL_YIFYSUBTITLES = auto()
DOWNLOAD_FILES = auto()
MANUAL_DOWNLOAD = auto()
AUTOLOAD_RENAME = auto()
AUTOLOAD_MOVE = auto()
AUTOLOAD_MOVE_ALL = auto()
SUBTITLE_RENAME = auto()
SUBTITLE_MOVE = auto()
SUBTITLE_MOVE_ALL = auto()
EXTRACT_FILES = auto()
SUMMARY_TOAST = auto()
CLEAN_UP = auto()
Expand Down