Make search work for multiple media types
This commit is contained in:
6
couchpotato/core/media/_base/search/__init__.py
Normal file
6
couchpotato/core/media/_base/search/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .main import Search
|
||||
|
||||
def start():
|
||||
return Search()
|
||||
|
||||
config = []
|
||||
58
couchpotato/core/media/_base/search/main.py
Normal file
58
couchpotato/core/media/_base/search/main.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import fireEvent, addEvent
|
||||
from couchpotato.core.helpers.variable import mergeDicts
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
|
||||
class Search(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
addApiView('search', self.search, docs = {
|
||||
'desc': 'Search the info in providers for a movie',
|
||||
'params': {
|
||||
'q': {'desc': 'The (partial) movie name you want to search for'},
|
||||
'type': {'desc': 'Search for a specific media type. Leave empty to search all.'},
|
||||
},
|
||||
'return': {'type': 'object', 'example': """{
|
||||
'success': True,
|
||||
'empty': bool, any movies returned or not,
|
||||
'results': object {'movie': [], 'show': []}, by media type found,
|
||||
}"""}
|
||||
})
|
||||
|
||||
addEvent('app.load', self.addSingleSearches)
|
||||
|
||||
def search(self, q = '', types = None, **kwargs):
|
||||
|
||||
# Make sure types is the correct instance
|
||||
if isinstance(types, (str, unicode)):
|
||||
types = [types]
|
||||
elif isinstance(types, (list, tuple, set)):
|
||||
types = list(types)
|
||||
|
||||
if not types:
|
||||
result = fireEvent('info.search', q = q, merge = True)
|
||||
else:
|
||||
result = {}
|
||||
for media_type in types:
|
||||
result[media_type] = fireEvent('%s.search' % media_type)
|
||||
|
||||
return mergeDicts({
|
||||
'success': True,
|
||||
}, result)
|
||||
|
||||
def createSingleSearch(self, media_type):
|
||||
|
||||
def singleSearch(q, **kwargs):
|
||||
return self.search(q, type = media_type, **kwargs)
|
||||
|
||||
return singleSearch
|
||||
|
||||
def addSingleSearches(self):
|
||||
|
||||
for media_type in fireEvent('media.types', merge = True):
|
||||
addApiView('%s.search' % media_type, self.createSingleSearch(media_type))
|
||||
@@ -34,17 +34,6 @@ class MovieBase(MovieTypeBase):
|
||||
super(MovieBase, self).__init__()
|
||||
self.initType()
|
||||
|
||||
addApiView('movie.search', self.search, docs = {
|
||||
'desc': 'Search the movie providers for a movie',
|
||||
'params': {
|
||||
'q': {'desc': 'The (partial) movie name you want to search for'},
|
||||
},
|
||||
'return': {'type': 'object', 'example': """{
|
||||
'success': True,
|
||||
'empty': bool, any movies returned or not,
|
||||
'movies': array, movies found,
|
||||
}"""}
|
||||
})
|
||||
addApiView('movie.list', self.listView, docs = {
|
||||
'desc': 'List movies in wanted list',
|
||||
'params': {
|
||||
|
||||
@@ -131,7 +131,7 @@ Block.Search = new Class({
|
||||
if(!self.spinner)
|
||||
self.spinner = createSpinner(self.mask);
|
||||
|
||||
self.api_request = Api.request('movie.search', {
|
||||
self.api_request = Api.request('search', {
|
||||
'data': {
|
||||
'q': q
|
||||
},
|
||||
|
||||
@@ -32,9 +32,32 @@ class MovieResultModifier(Plugin):
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
addEvent('result.modify.info.search', self.returnByType)
|
||||
addEvent('result.modify.movie.search', self.combineOnIMDB)
|
||||
addEvent('result.modify.movie.info', self.checkLibrary)
|
||||
|
||||
def returnByType(self, results):
|
||||
|
||||
new_results = {'unknown':[]}
|
||||
for r in results:
|
||||
if r.get('type'):
|
||||
type_name = r.get('type') + 's'
|
||||
if not new_results.has_key(type_name):
|
||||
new_results[type_name] = []
|
||||
|
||||
new_results[type_name].append(r)
|
||||
else:
|
||||
new_results['unknown'].append(r)
|
||||
|
||||
if len(new_results['unknown']) == 0:
|
||||
del new_results['unknown']
|
||||
|
||||
# Combine movies, needs a cleaner way..
|
||||
if new_results.has_key('movies'):
|
||||
new_results['movies'] = self.combineOnIMDB(new_results['movies'])
|
||||
|
||||
return new_results
|
||||
|
||||
def combineOnIMDB(self, results):
|
||||
|
||||
temp = {}
|
||||
|
||||
@@ -84,6 +84,7 @@ class OMDBAPI(MovieProvider):
|
||||
year = tryInt(movie.get('Year', ''))
|
||||
|
||||
movie_data = {
|
||||
'type': 'movie',
|
||||
'via_imdb': True,
|
||||
'titles': [movie.get('Title')] if movie.get('Title') else [],
|
||||
'original_title': movie.get('Title'),
|
||||
|
||||
@@ -11,6 +11,7 @@ log = CPLog(__name__)
|
||||
class TheMovieDb(MovieProvider):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('info.search', self.search, priority = 2)
|
||||
addEvent('movie.search', self.search, priority = 2)
|
||||
addEvent('movie.info', self.getInfo, priority = 2)
|
||||
addEvent('movie.info_by_tmdb', self.getInfo)
|
||||
@@ -103,6 +104,7 @@ class TheMovieDb(MovieProvider):
|
||||
year = None
|
||||
|
||||
movie_data = {
|
||||
'type': 'movie',
|
||||
'via_tmdb': True,
|
||||
'tmdb_id': movie.id,
|
||||
'titles': [toUnicode(movie.title)],
|
||||
|
||||
Reference in New Issue
Block a user