|
|
@ -7,6 +7,7 @@ from couchpotato.core.logger import CPLog |
|
|
|
from couchpotato.core.media._base.searcher.base import SearcherBase |
|
|
|
from couchpotato.core.settings.model import Media, Release, ReleaseInfo |
|
|
|
from couchpotato.environment import Env |
|
|
|
from sqlalchemy.exc import InterfaceError |
|
|
|
from inspect import ismethod, isfunction |
|
|
|
import datetime |
|
|
|
import re |
|
|
@ -26,6 +27,7 @@ class Searcher(SearcherBase): |
|
|
|
addEvent('searcher.correct_words', self.correctWords) |
|
|
|
addEvent('searcher.download', self.download) |
|
|
|
addEvent('searcher.search', self.search) |
|
|
|
addEvent('searcher.create_releases', self.createReleases) |
|
|
|
|
|
|
|
addApiView('searcher.full_search', self.searchAllView, docs = { |
|
|
|
'desc': 'Starts a full search for all media', |
|
|
@ -154,6 +156,52 @@ class Searcher(SearcherBase): |
|
|
|
|
|
|
|
return sorted_results |
|
|
|
|
|
|
|
def createReleases(self, search_results, media, quality_type): |
|
|
|
|
|
|
|
available_status, ignored_status, failed_status = fireEvent('status.get', ['available', 'ignored', 'failed'], single = True) |
|
|
|
db = get_session() |
|
|
|
|
|
|
|
found_releases = [] |
|
|
|
|
|
|
|
for rel in search_results: |
|
|
|
|
|
|
|
nzb_identifier = md5(rel['url']) |
|
|
|
found_releases.append(nzb_identifier) |
|
|
|
|
|
|
|
rls = db.query(Release).filter_by(identifier = nzb_identifier).first() |
|
|
|
if not rls: |
|
|
|
rls = Release( |
|
|
|
identifier = nzb_identifier, |
|
|
|
media_id = media.get('id'), |
|
|
|
quality_id = quality_type.get('quality_id'), |
|
|
|
status_id = available_status.get('id') |
|
|
|
) |
|
|
|
db.add(rls) |
|
|
|
else: |
|
|
|
[db.delete(old_info) for old_info in rls.info] |
|
|
|
rls.last_edit = int(time.time()) |
|
|
|
|
|
|
|
db.commit() |
|
|
|
|
|
|
|
for info in rel: |
|
|
|
try: |
|
|
|
if not isinstance(rel[info], (str, unicode, int, long, float)): |
|
|
|
continue |
|
|
|
|
|
|
|
rls_info = ReleaseInfo( |
|
|
|
identifier = info, |
|
|
|
value = toUnicode(rel[info]) |
|
|
|
) |
|
|
|
rls.info.append(rls_info) |
|
|
|
except InterfaceError: |
|
|
|
log.debug('Couldn\'t add %s to ReleaseInfo: %s', (info, traceback.format_exc())) |
|
|
|
|
|
|
|
db.commit() |
|
|
|
|
|
|
|
rel['status_id'] = rls.status_id |
|
|
|
|
|
|
|
return found_releases |
|
|
|
|
|
|
|
def getSearchProtocols(self): |
|
|
|
|
|
|
|
download_protocols = fireEvent('download.enabled_protocols', merge = True) |
|
|
|