-
Notifications
You must be signed in to change notification settings - Fork 278
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
Remove forcedSearchQueueItem, in favor of using backlogQueueItem for single ep searches #6718
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b6e58ad
* Added api/v2 search endpoint.
p0psicles cc8111d
Removed the SearchHandler changes, as that's done in PR #6716
p0psicles a2cc5b9
Remove the old FailedSearchQueueItem class.
p0psicles 22df811
Fix import order.
p0psicles 48c49de
Replace ForcedSearchQueueItem in api\v1\core.py
p0psicles 8bd3148
Merge branch 'develop' into feature/remove-forced-search
p0psicles f0dea9d
Fix loading displayShow using python3 when app.DOWNLOAD_URL is used.
p0psicles c562beb
Merge branch 'develop' into feature/remove-forced-search
p0psicles 1c979d4
Merge remote-tracking branch 'remotes/origin/develop' into feature/re…
p0psicles f709f8b
Update server/api/v2/search.py after upmerge from develop.
p0psicles 8876565
Removed unused import
p0psicles 8554eaa
Fixed doc
p0psicles f57b284
Review
p0psicles f3dc341
added changelog
p0psicles d5a879c
Update CHANGELOG.md
medariox 8346588
Merge branch 'develop' into feature/remove-forced-search
medariox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
from medusa import app, common, failed_history, generic_queue, history, ui | ||
from medusa.helpers import pretty_file_size | ||
from medusa.logger.adapters.style import BraceAdapter | ||
from medusa.search import BACKLOG_SEARCH, DAILY_SEARCH, FAILED_SEARCH, FORCED_SEARCH, SNATCH_RESULT, SearchType | ||
from medusa.search import BACKLOG_SEARCH, DAILY_SEARCH, FAILED_SEARCH, MANUAL_SEARCH, SNATCH_RESULT, SearchType | ||
from medusa.search.core import ( | ||
search_for_needed_episodes, | ||
search_providers, | ||
|
@@ -25,8 +25,8 @@ | |
|
||
search_queue_lock = threading.Lock() | ||
|
||
FORCED_SEARCH_HISTORY = [] | ||
FORCED_SEARCH_HISTORY_SIZE = 100 | ||
SEARCH_HISTORY = [] | ||
SEARCH_HISTORY_SIZE = 100 | ||
|
||
|
||
class SearchQueue(generic_queue.GenericQueue): | ||
|
@@ -42,7 +42,7 @@ def is_in_queue(self, show, segment): | |
"""Check if item is in queue.""" | ||
for cur_item in self.queue: | ||
if isinstance(cur_item, (BacklogQueueItem, FailedQueueItem, | ||
ForcedSearchQueueItem, SnatchQueueItem)) \ | ||
SnatchQueueItem, ManualSearchQueueItem)) \ | ||
and cur_item.show == show and cur_item.segment == segment: | ||
return True | ||
return False | ||
|
@@ -90,7 +90,7 @@ def add_item(self, item): | |
# daily searches | ||
generic_queue.GenericQueue.add_item(self, item) | ||
elif isinstance(item, (BacklogQueueItem, FailedQueueItem, | ||
SnatchQueueItem, ForcedSearchQueueItem)) \ | ||
SnatchQueueItem, ManualSearchQueueItem)) \ | ||
and not self.is_in_queue(item.show, item.segment): | ||
generic_queue.GenericQueue.add_item(self, item) | ||
else: | ||
|
@@ -105,12 +105,12 @@ def force_daily(self): | |
|
||
|
||
class ForcedSearchQueue(generic_queue.GenericQueue): | ||
"""Search Queueu used for Forced Search, Failed Search.""" | ||
"""Search Queueu used for Manual, Failed Search.""" | ||
|
||
def __init__(self): | ||
"""Initialize ForcedSearch Queue.""" | ||
generic_queue.GenericQueue.__init__(self) | ||
self.queue_name = 'SEARCHQUEUE' | ||
self.queue_name = 'FORCEDSEARCHQUEUE' | ||
|
||
def is_in_queue(self, show, segment): | ||
"""Verify if the show and segment (episode or number of episodes) are scheduled.""" | ||
|
@@ -122,14 +122,14 @@ def is_in_queue(self, show, segment): | |
def is_ep_in_queue(self, segment): | ||
"""Verify if the show and segment (episode or number of episodes) are scheduled.""" | ||
for cur_item in self.queue: | ||
if isinstance(cur_item, (ForcedSearchQueueItem, FailedQueueItem)) and cur_item.segment == segment: | ||
if isinstance(cur_item, (BacklogQueueItem, FailedQueueItem, ManualSearchQueueItem)) and cur_item.segment == segment: | ||
return True | ||
return False | ||
|
||
def is_show_in_queue(self, show): | ||
"""Verify if the show is queued in this queue as a ForcedSearchQueueItem or FailedQueueItem.""" | ||
"""Verify if the show is queued in this queue as a BacklogQueueItem, ManualSearchQueueItem or FailedQueueItem.""" | ||
for cur_item in self.queue: | ||
if isinstance(cur_item, (ForcedSearchQueueItem, FailedQueueItem)) and cur_item.show.indexerid == show: | ||
if isinstance(cur_item, (BacklogQueueItem, FailedQueueItem, ManualSearchQueueItem)) and cur_item.show.indexerid == show: | ||
return True | ||
return False | ||
|
||
|
@@ -139,11 +139,11 @@ def get_all_ep_from_queue(self, series_obj): | |
|
||
@param series_obj: Series object. | ||
|
||
@return: A list of ForcedSearchQueueItem or FailedQueueItem items | ||
@return: A list of BacklogQueueItem, FailedQueueItem or FailedQueueItem items | ||
""" | ||
ep_obj_list = [] | ||
for cur_item in self.queue: | ||
if isinstance(cur_item, (ForcedSearchQueueItem, FailedQueueItem)): | ||
if isinstance(cur_item, (BacklogQueueItem, FailedQueueItem, ManualSearchQueueItem)): | ||
if series_obj and cur_item.show.identifier != series_obj.identifier: | ||
continue | ||
ep_obj_list.append(cur_item) | ||
|
@@ -159,8 +159,11 @@ def is_backlog_paused(self): | |
return self.min_priority >= generic_queue.QueuePriorities.NORMAL | ||
|
||
def is_forced_search_in_progress(self): | ||
"""Test of a forced search is currently running, it doesn't check what's in queue.""" | ||
if isinstance(self.currentItem, (ForcedSearchQueueItem, FailedQueueItem)): | ||
"""Test of a forced search is currently running (can be backlog, manual or failed search). | ||
|
||
it doesn't check what's in queue. | ||
""" | ||
if isinstance(self.currentItem, (BacklogQueueItem, ManualSearchQueueItem, FailedQueueItem)): | ||
return True | ||
return False | ||
|
||
|
@@ -170,15 +173,15 @@ def queue_length(self): | |
for cur_item in self.queue: | ||
if isinstance(cur_item, FailedQueueItem): | ||
length['failed'] += 1 | ||
elif isinstance(cur_item, ForcedSearchQueueItem) and not cur_item.manual_search: | ||
length['forced_search'] += 1 | ||
elif isinstance(cur_item, ForcedSearchQueueItem) and cur_item.manual_search: | ||
elif isinstance(cur_item, BacklogQueueItem) and not cur_item.manual_search: | ||
length['backlog_search'] += 1 | ||
elif isinstance(cur_item, ManualSearchQueueItem): | ||
length['manual_search'] += 1 | ||
return length | ||
|
||
def add_item(self, item): | ||
"""Add a new ForcedSearchQueueItem or FailedQueueItem to the ForcedSearchQueue.""" | ||
if isinstance(item, (ForcedSearchQueueItem, FailedQueueItem)) and not self.is_ep_in_queue(item.segment): | ||
"""Add a new ManualSearchQueueItem or FailedQueueItem to the ForcedSearchQueue.""" | ||
if isinstance(item, (ManualSearchQueueItem, FailedQueueItem, BacklogQueueItem)) and not self.is_ep_in_queue(item.segment): | ||
# manual, snatch and failed searches | ||
generic_queue.GenericQueue.add_item(self, item) | ||
else: | ||
|
@@ -315,26 +318,22 @@ def run(self): | |
self.finish() | ||
|
||
|
||
class ForcedSearchQueueItem(generic_queue.QueueItem): | ||
"""Forced search queue item class.""" | ||
class ManualSearchQueueItem(generic_queue.QueueItem): | ||
"""Manual search queue item class.""" | ||
|
||
def __init__(self, show, segment, down_cur_quality=False, manual_search=False, manual_search_type='episode'): | ||
def __init__(self, show, segment, manual_search_type='episode'): | ||
""" | ||
Initialize class of a QueueItem used to queue forced and manual searches. | ||
|
||
:param show: A show object | ||
:param segment: A list of episode objects. | ||
:param down_cur_quality: Not sure what it's used for. Maybe legacy. | ||
:param manual_search: Passed as True (bool) when the search should be performed without snatching a result | ||
:param manual_search_type: Used to switch between episode and season search. Options are 'episode' or 'season'. | ||
:return: The run() method searches and snatches the episode(s) if possible or it only searches and saves results to cache tables. | ||
""" | ||
generic_queue.QueueItem.__init__(self, u'Forced Search', FORCED_SEARCH) | ||
generic_queue.QueueItem.__init__(self, u'Manual Search', MANUAL_SEARCH) | ||
self.priority = generic_queue.QueuePriorities.HIGH | ||
# SEARCHQUEUE-MANUAL-12345 | ||
# SEARCHQUEUE-FORCED-12345 | ||
self.name = '{search_type}-{indexerid}'.format( | ||
search_type=('FORCED', 'MANUAL')[bool(manual_search)], | ||
search_type='MANUAL', | ||
indexerid=show.indexerid | ||
) | ||
|
||
|
@@ -344,8 +343,6 @@ def __init__(self, show, segment, down_cur_quality=False, manual_search=False, m | |
|
||
self.show = show | ||
self.segment = segment | ||
self.down_cur_quality = down_cur_quality | ||
self.manual_search = manual_search | ||
self.manual_search_type = manual_search_type | ||
|
||
def run(self): | ||
|
@@ -356,57 +353,16 @@ def run(self): | |
try: | ||
log.info( | ||
'Beginning {search_type} {season_pack}search for: {ep}', { | ||
'search_type': ('forced', 'manual')[bool(self.manual_search)], | ||
'search_type': 'manual', | ||
'season_pack': ('', 'season pack ')[bool(self.manual_search_type == 'season')], | ||
'ep': self.segment[0].pretty_name() | ||
} | ||
) | ||
|
||
search_result = search_providers(self.show, self.segment, True, self.down_cur_quality, | ||
self.manual_search, self.manual_search_type) | ||
|
||
if not self.manual_search and search_result: | ||
for result in search_result: | ||
# Just use the first result for now | ||
if result.seeders not in (-1, None) and result.leechers not in (-1, None): | ||
log.info( | ||
'Downloading {name} with {seeders} seeders and {leechers} leechers ' | ||
'and size {size} from {provider}', { | ||
'name': result.name, | ||
'seeders': result.seeders, | ||
'leechers': result.leechers, | ||
'size': pretty_file_size(result.size), | ||
'provider': result.provider.name, | ||
} | ||
) | ||
else: | ||
log.info( | ||
'Downloading {name} with size: {size} from {provider}', { | ||
'name': result.name, | ||
'size': pretty_file_size(result.size), | ||
'provider': result.provider.name, | ||
} | ||
) | ||
|
||
# Set the search_type for the result. | ||
result.search_type = SearchType.FORCED_SEARCH | ||
search_result = search_providers(self.show, self.segment, True, True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to use named arguments here, especially for the Trues. It makes it much more readable. |
||
True, self.manual_search_type) | ||
|
||
# Create the queue item | ||
snatch_queue_item = SnatchQueueItem(result.series, result.episodes, result) | ||
|
||
# Add the queue item to the queue | ||
app.manual_snatch_scheduler.action.add_item(snatch_queue_item) | ||
|
||
self.success = False | ||
while snatch_queue_item.success is False: | ||
if snatch_queue_item.started and snatch_queue_item.success: | ||
self.success = True | ||
time.sleep(1) | ||
|
||
# Give the CPU a break | ||
time.sleep(common.cpu_presets[app.CPU_PRESET]) | ||
|
||
elif self.manual_search and search_result: | ||
if search_result: | ||
self.results = search_result | ||
self.success = True | ||
|
||
|
@@ -435,7 +391,7 @@ def run(self): | |
log.debug(traceback.format_exc()) | ||
|
||
# Keep a list with the 100 last executed searches | ||
fifo(FORCED_SEARCH_HISTORY, self, FORCED_SEARCH_HISTORY_SIZE) | ||
fifo(SEARCH_HISTORY, self, SEARCH_HISTORY_SIZE) | ||
|
||
if self.success is None: | ||
self.success = False | ||
|
@@ -693,7 +649,7 @@ def run(self): | |
log.info(traceback.format_exc()) | ||
|
||
# ## Keep a list with the 100 last executed searches | ||
fifo(FORCED_SEARCH_HISTORY, self, FORCED_SEARCH_HISTORY_SIZE) | ||
fifo(SEARCH_HISTORY, self, SEARCH_HISTORY_SIZE) | ||
|
||
if self.success is None: | ||
self.success = False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be capitalized for consistency.