Make search work for multiple media types
This commit is contained in:
1 parent
8ca5c62575
commit
3925d4c215
7 files changed
+91
-12
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
from .main import Search
|
||||||
|
|
||||||
|
def start():
|
||||||
|
return Search()
|
||||||
|
|
||||||
|
config = []
|
||||||
@@ -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__()
|
super(MovieBase, self).__init__()
|
||||||
self.initType()
|
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 = {
|
addApiView('movie.list', self.listView, docs = {
|
||||||
'desc': 'List movies in wanted list',
|
'desc': 'List movies in wanted list',
|
||||||
'params': {
|
'params': {
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ Block.Search = new Class({
|
|||||||
if(!self.spinner)
|
if(!self.spinner)
|
||||||
self.spinner = createSpinner(self.mask);
|
self.spinner = createSpinner(self.mask);
|
||||||
|
|
||||||
self.api_request = Api.request('movie.search', {
|
self.api_request = Api.request('search', {
|
||||||
'data': {
|
'data': {
|
||||||
'q': q
|
'q': q
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,9 +32,32 @@ class MovieResultModifier(Plugin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
addEvent('result.modify.info.search', self.returnByType)
|
||||||
addEvent('result.modify.movie.search', self.combineOnIMDB)
|
addEvent('result.modify.movie.search', self.combineOnIMDB)
|
||||||
addEvent('result.modify.movie.info', self.checkLibrary)
|
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):
|
def combineOnIMDB(self, results):
|
||||||
|
|
||||||
temp = {}
|
temp = {}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ class OMDBAPI(MovieProvider):
|
|||||||
year = tryInt(movie.get('Year', ''))
|
year = tryInt(movie.get('Year', ''))
|
||||||
|
|
||||||
movie_data = {
|
movie_data = {
|
||||||
|
'type': 'movie',
|
||||||
'via_imdb': True,
|
'via_imdb': True,
|
||||||
'titles': [movie.get('Title')] if movie.get('Title') else [],
|
'titles': [movie.get('Title')] if movie.get('Title') else [],
|
||||||
'original_title': movie.get('Title'),
|
'original_title': movie.get('Title'),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ log = CPLog(__name__)
|
|||||||
class TheMovieDb(MovieProvider):
|
class TheMovieDb(MovieProvider):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
addEvent('info.search', self.search, priority = 2)
|
||||||
addEvent('movie.search', self.search, priority = 2)
|
addEvent('movie.search', self.search, priority = 2)
|
||||||
addEvent('movie.info', self.getInfo, priority = 2)
|
addEvent('movie.info', self.getInfo, priority = 2)
|
||||||
addEvent('movie.info_by_tmdb', self.getInfo)
|
addEvent('movie.info_by_tmdb', self.getInfo)
|
||||||
@@ -103,6 +104,7 @@ class TheMovieDb(MovieProvider):
|
|||||||
year = None
|
year = None
|
||||||
|
|
||||||
movie_data = {
|
movie_data = {
|
||||||
|
'type': 'movie',
|
||||||
'via_tmdb': True,
|
'via_tmdb': True,
|
||||||
'tmdb_id': movie.id,
|
'tmdb_id': movie.id,
|
||||||
'titles': [toUnicode(movie.title)],
|
'titles': [toUnicode(movie.title)],
|
||||||
|
|||||||
Reference in new issue
Block a user