-
Notifications
You must be signed in to change notification settings - Fork 269
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
Concept version of upgrading based on preferred words #5987
Open
p0psicles
wants to merge
14
commits into
develop
Choose a base branch
from
feature/upgrade-pref-words
base: develop
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
561a98e
Concept version of upgrading based on preferred words.
p0psicles 9585c6a
Save score on snatched.
p0psicles afeab02
Fixed some sql errors.
p0psicles 7348fdd
Add database migration.
p0psicles e8244d4
Not needed.
p0psicles 7d32ede
Merge branch 'develop' into feature/upgrade-pref-words
p0psicles 5f8649b
Fixup rebase conflicts.
p0psicles a0b4f6d
Fixed episode_num function call.
p0psicles f7423ac
Prevent ZeroDivisionError exception.
p0psicles 809f121
Merge remote-tracking branch 'remotes/origin/develop' into feature/up…
p0psicles 40c159c
Fix error: 'DB error: 25 values for 26 columns'
p0psicles b83f484
Merge branch 'feature/upgrade-pref-words' of https://github.com/pymed…
p0psicles 3519bd9
yarn dev
p0psicles ea792fa
Fix pref_words_score reference.
p0psicles File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,15 @@ | |
# You should have received a copy of the GNU General Public License | ||
# along with Medusa. If not, see <http://www.gnu.org/licenses/>. | ||
"""Collection of generic used classes.""" | ||
from __future__ import unicode_literals | ||
from __future__ import division, unicode_literals | ||
|
||
import logging | ||
|
||
from dateutil import parser | ||
|
||
from medusa import app | ||
from medusa.common import Quality | ||
from medusa import app, db | ||
from medusa.common import statusStrings, Quality, UNSET, WANTED | ||
from medusa.helper.common import episode_num | ||
from medusa.logger.adapters.style import BraceAdapter | ||
from medusa.search import SearchType | ||
|
||
|
@@ -132,6 +133,122 @@ def __init__(self, episodes=None, provider=None): | |
# For example SearchType.MANUAL_SEARCH, SearchType.FORCED_SEARCH, SearchType.DAILY_SEARCH, SearchType.PROPER_SEARCH | ||
self.search_type = None | ||
|
||
# # Assign a score for the amount of preffered words there are in the release name | ||
self._preferred_words_score = None | ||
|
||
@property | ||
def preferred_words_score(self): | ||
"""Calculate a score based on the amount of preferred words in release name.""" | ||
preferred_words = [word.lower() for word in app.PREFERRED_WORDS] | ||
self._preferred_words_score = round((len([word for word in preferred_words if word in self.name.lower()]) / float(len(preferred_words))) * 100) | ||
return self._preferred_words_score | ||
|
||
@staticmethod | ||
def __qualities_to_string(qualities=None): | ||
return ', '.join([Quality.qualityStrings[quality] for quality in qualities or [] | ||
if quality and quality in Quality.qualityStrings]) or 'None' | ||
|
||
def want_episode(self, season, episode, quality): | ||
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. @medariox i've moved want_episode from the Series class to Result class. Imo it looks allot cleaner, with less parameter. And it just feels like this is a better home. |
||
"""Whether or not the episode with the specified quality is wanted. | ||
|
||
:param season: | ||
:type season: int | ||
:param episode: | ||
:type episode: int | ||
:param quality: | ||
:type quality: int | ||
|
||
:return: | ||
:rtype: bool | ||
""" | ||
# if the quality isn't one we want under any circumstances then just say no | ||
allowed_qualities, preferred_qualities = self.series.current_qualities | ||
log.debug( | ||
u'{id}: Allowed, Preferred = [ {allowed} ] [ {preferred} ] Found = [ {found} ]', { | ||
'id': self.series.series_id, | ||
'allowed': self.__qualities_to_string(allowed_qualities), | ||
'preferred': self.__qualities_to_string(preferred_qualities), | ||
'found': self.__qualities_to_string([quality]), | ||
} | ||
) | ||
|
||
if not Quality.wanted_quality(quality, allowed_qualities, preferred_qualities): | ||
log.debug( | ||
u"{id}: Ignoring found result for '{show}' {ep} with unwanted quality '{quality}'", { | ||
'id': self.series.series_id, | ||
'show': self.series.name, | ||
'ep': self.series.episode_num(season, episode), | ||
'quality': Quality.qualityStrings[quality], | ||
} | ||
) | ||
return False | ||
|
||
main_db_con = db.DBConnection() | ||
|
||
sql_results = main_db_con.select( | ||
'SELECT ' | ||
' status, quality, ' | ||
' manually_searched, preferred_words_score ' | ||
'FROM ' | ||
' tv_episodes ' | ||
'WHERE ' | ||
' indexer = ? ' | ||
' AND showid = ? ' | ||
' AND season = ? ' | ||
' AND episode = ?', [self.series.indexer, self.series.series_id, season, episode]) | ||
|
||
if not sql_results or not len(sql_results): | ||
log.debug( | ||
u'{id}: Unable to find a matching episode in database.' | ||
u' Ignoring found result for {show} {ep} with quality {quality}', { | ||
'id': self.series.series_id, | ||
'show': self.series.name, | ||
'ep': episode_num(season, episode), | ||
'quality': Quality.qualityStrings[quality], | ||
} | ||
) | ||
return False | ||
|
||
cur_status, cur_quality, preferred_words_score = ( | ||
int(sql_results[0]['status'] or UNSET), | ||
int(sql_results[0]['quality'] or Quality.NA), | ||
int(sql_results[0]['preferred_words_score'] or 0) | ||
) | ||
|
||
ep_status_text = statusStrings[cur_status] | ||
manually_searched = sql_results[0]['manually_searched'] | ||
|
||
# if it's one of these then we want it as long as it's in our allowed initial qualities | ||
if cur_status == WANTED: | ||
should_replace, reason = ( | ||
True, u"Current status is 'WANTED'. Accepting result with quality '{new_quality}'".format( | ||
new_quality=Quality.qualityStrings[quality] | ||
) | ||
) | ||
else: | ||
upgrade_preferred_words = all([self.series.upgrade_preferred_words, | ||
self.preferred_words_score, | ||
self.preferred_words_score < self.series.preferred_words_score]) | ||
should_replace, reason = Quality.should_replace(cur_status, cur_quality, quality, allowed_qualities, | ||
preferred_qualities, self.download_current_quality, | ||
self.forced_search, manually_searched, self.search_type, | ||
upgrade_preferred_words=upgrade_preferred_words) | ||
|
||
log.debug( | ||
u"{id}: '{show}' {ep} status is: '{status}'." | ||
u" {action} result with quality '{new_quality}'." | ||
u' Reason: {reason}', { | ||
'id': self.series.series_id, | ||
'show': self.name, | ||
'ep': episode_num(season, episode), | ||
'status': ep_status_text, | ||
'action': 'Accepting' if should_replace else 'Ignoring', | ||
'new_quality': Quality.qualityStrings[quality], | ||
'reason': reason, | ||
} | ||
) | ||
return should_replace | ||
|
||
@property | ||
def actual_episode(self): | ||
return self._actual_episode | ||
|
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
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
Oops, something went wrong.
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.
rtms: division can be removed again.