Skip to content

Commit

Permalink
Fix feature postpone if no subs (pymedusa#10537)
Browse files Browse the repository at this point in the history
  • Loading branch information
p0psicles authored and PaulLiang1 committed Oct 10, 2022
1 parent 47f5cc4 commit 4a3b93d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
8 changes: 8 additions & 0 deletions medusa/helper/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class EpisodePostProcessingAbortException(ApplicationException):
"""


class EpisodePostProcessingPostponedException(ApplicationException):
"""
The episode post-processing delayed.
Meaning we abort the postprocess and not update the client status if applicable.
"""


class FailedPostProcessingFailedException(ApplicationException):
"""
The failed post-processing failed
Expand Down
30 changes: 24 additions & 6 deletions medusa/process_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from medusa.helper.exceptions import (
EpisodePostProcessingAbortException,
EpisodePostProcessingFailedException,
EpisodePostProcessingPostponedException,
FailedPostProcessingFailedException,
ex
)
Expand Down Expand Up @@ -156,11 +157,13 @@ def process_path(self):
if (
self.process_single_resource
and (process_results.failed or not process_results.succeeded)
and not process_results.postpone_processing
):
process_results.process_failed(self.path)

# In case we have an info_hash or (nzbid), update the history table with the pp results.
if self.info_hash:
# Skip the history update when the postponed (because of missing subs) flag was enabled.
if self.info_hash and not process_results.postpone_processing:
self.update_history_processed(process_results)

return process_results
Expand Down Expand Up @@ -268,8 +271,13 @@ def __init__(self, path, process_method=None, failed=False, episodes=[], process
self.failed = failed
self.resource_name = None
self.result = True
# Processing aborted. So we don't want to trigger any failed download handling.
# We do want to update the history client status.
self.aborted = False
# Processing succeeded. Trigger failed downlaod handling and update history client status.
self.succeeded = True
# Processing postponed. Stop postprocessing and don't update history client status.
self.postpone_processing = False
self.missed_files = []
self.unwanted_files = []
self.allowed_extensions = app.ALLOWED_EXTENSIONS
Expand Down Expand Up @@ -873,9 +881,11 @@ def process_media(self, path, video_files, force=False, is_priority=None, ignore
processor = post_processor.PostProcessor(file_path, self.resource_name,
self.process_method, is_priority)

if app.POSTPONE_IF_NO_SUBS:
if app.POSTPONE_IF_NO_SUBS and self.process_single_resource:
if not self._process_postponed(processor, file_path, video, ignore_subs):
continue
raise EpisodePostProcessingPostponedException(
f'Postponing processing for file path {file_path} and resource {self.resource_name}'
)

self.result = processor.process()
process_fail_message = ''
Expand All @@ -888,16 +898,24 @@ def process_media(self, path, video_files, force=False, is_priority=None, ignore
self.result = True
self.aborted = True
process_fail_message = ex(error)
except EpisodePostProcessingPostponedException as error:
processor = None
self.result = True
process_fail_message = ex(error)

if processor:
self._output += processor._output

if self.result:
if not self.aborted:
self.log_and_output('Processing succeeded for {file_path}', **{'file_path': file_path})
else:
if self.aborted:
self.log_and_output('Processing aborted for {file_path}: {process_fail_message}',
level=logging.WARNING, **{'file_path': file_path, 'process_fail_message': process_fail_message})
elif self.postpone_processing:
self.log_and_output('Processing postponed for {file_path}: {process_fail_message}',
level=logging.INFO, **{'file_path': file_path, 'process_fail_message': process_fail_message})
else:
self.log_and_output('Processing succeeded for {file_path}', **{'file_path': file_path})

else:
self.log_and_output('Processing failed for {file_path}: {process_fail_message}',
level=logging.WARNING, **{'file_path': file_path, 'process_fail_message': process_fail_message})
Expand Down
14 changes: 13 additions & 1 deletion medusa/schedulers/download_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,19 @@ def _check_torrent_ratio(self, client):
self.save_status_to_history(history_result, ClientStatus(status_string='SeededAction'))

def _postprocess(self, path, info_hash, resource_name, failed=False, client_type=None):
"""Queue a postprocess action."""
"""Queue a postprocess action.
:param path: Path to process
:type path: str
:param info_hash: info hash
:type info_hash: str
:param resource_name: Resource name
:type resource_name: str
:param failed: Flag to determin if this was a failed download
:type failed: bool
:param client_type: Client type ('nzb', 'torrent')
:type client_type: str
"""
# Use the info hash get a segment of episodes.
history_items = self.main_db_con.select(
'SELECT * FROM history WHERE info_hash = ?',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_guessit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def show_list(create_tvshow):
create_tvshow(indexerid=17, name='An Anime Show 100', anime=1),
create_tvshow(indexerid=17, name='Show! Name 2', anime=1),
create_tvshow(indexerid=18, name='24'), # expected titles shouldn't contain numbers
create_tvshow(indexerid=18, name='9-1-1'), # The dash in the title makes it an expected title
create_tvshow(indexerid=18, name='Tate no Yuusha no Nariagari Season 2'), # The number 2 will qualify this as an expected title
create_tvshow(indexerid=19, name='9-1-1'), # The dash in the title makes it an expected title
create_tvshow(indexerid=20, name='Tate no Yuusha no Nariagari Season 2'), # The number 2 will qualify this as an expected title
]


Expand Down

0 comments on commit 4a3b93d

Please sign in to comment.