|
a/src/mediaserver/cdplugins/uprcl/uprcl-app.py |
|
b/src/mediaserver/cdplugins/uprcl/uprcl-app.py |
|
... |
|
... |
21 |
import json
|
21 |
import json
|
22 |
import posixpath
|
22 |
import posixpath
|
23 |
import re
|
23 |
import re
|
24 |
import conftree
|
24 |
import conftree
|
25 |
import cmdtalkplugin
|
25 |
import cmdtalkplugin
|
|
|
26 |
|
26 |
import folders
|
27 |
import uprclfolders
|
|
|
28 |
import uprclsearch
|
27 |
from uprclutils import *
|
29 |
from uprclutils import *
|
|
|
30 |
|
|
|
31 |
from recoll import recoll
|
|
|
32 |
from recoll import rclconfig
|
|
|
33 |
g_myprefix = '0$uprcl$folders'
|
28 |
|
34 |
|
29 |
# Func name to method mapper
|
35 |
# Func name to method mapper
|
30 |
dispatcher = cmdtalkplugin.Dispatch()
|
36 |
dispatcher = cmdtalkplugin.Dispatch()
|
31 |
# Pipe message handler
|
37 |
# Pipe message handler
|
32 |
msgproc = cmdtalkplugin.Processor(dispatcher)
|
38 |
msgproc = cmdtalkplugin.Processor(dispatcher)
|
33 |
|
39 |
|
34 |
def module_init():
|
40 |
def uprcl_init():
|
35 |
global httphp
|
41 |
global httphp, pathprefix, uprclhost, pathmap
|
36 |
global pathprefix
|
|
|
37 |
|
42 |
|
38 |
if "UPMPD_HTTPHOSTPORT" not in os.environ:
|
43 |
if "UPMPD_HTTPHOSTPORT" not in os.environ:
|
39 |
raise Exception("No UPMPD_HTTPHOSTPORT in environment")
|
44 |
raise Exception("No UPMPD_HTTPHOSTPORT in environment")
|
40 |
httphp = os.environ["UPMPD_HTTPHOSTPORT"]
|
45 |
httphp = os.environ["UPMPD_HTTPHOSTPORT"]
|
41 |
if "UPMPD_PATHPREFIX" not in os.environ:
|
46 |
if "UPMPD_PATHPREFIX" not in os.environ:
|
|
... |
|
... |
43 |
pathprefix = os.environ["UPMPD_PATHPREFIX"]
|
48 |
pathprefix = os.environ["UPMPD_PATHPREFIX"]
|
44 |
if "UPMPD_CONFIG" not in os.environ:
|
49 |
if "UPMPD_CONFIG" not in os.environ:
|
45 |
raise Exception("No UPMPD_CONFIG in environment")
|
50 |
raise Exception("No UPMPD_CONFIG in environment")
|
46 |
upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
|
51 |
upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
|
47 |
|
52 |
|
48 |
global uprclhost, pathmap
|
|
|
49 |
|
|
|
50 |
uprclhost = upconfig.get("uprclhost")
|
53 |
uprclhost = upconfig.get("uprclhost")
|
51 |
if uprclhost is None:
|
54 |
if uprclhost is None:
|
52 |
msgproc.log("uprcl init: no uprclhost in config file")
|
55 |
raise Exception("uprclhost not in config")
|
53 |
return False
|
|
|
54 |
|
56 |
|
55 |
pthstr = upconfig.get("uprclpaths")
|
57 |
pthstr = upconfig.get("uprclpaths")
|
56 |
if pthstr is None:
|
58 |
if pthstr is None:
|
57 |
msgproc.log("uprcl init: no uprclpaths in config file")
|
59 |
raise Exception("uprclpaths not in config")
|
58 |
return False
|
|
|
59 |
lpth = pthstr.split(',')
|
60 |
lpth = pthstr.split(',')
|
60 |
pathmap = {}
|
61 |
pathmap = {}
|
61 |
for ptt in lpth:
|
62 |
for ptt in lpth:
|
62 |
l = ptt.split(':')
|
63 |
l = ptt.split(':')
|
63 |
pathmap[l[0]] = l[1]
|
64 |
pathmap[l[0]] = l[1]
|
64 |
|
65 |
|
65 |
return True
|
66 |
global rclconfdir
|
|
|
67 |
rclconfdir = upconfig.get("uprclconfdir")
|
|
|
68 |
if rclconfdir is None:
|
|
|
69 |
raise Exception("uprclconfdir not in config")
|
|
|
70 |
|
|
|
71 |
uprclfolders.inittree(rclconfdir)
|
|
|
72 |
|
66 |
|
73 |
|
67 |
@dispatcher.record('trackuri')
|
74 |
@dispatcher.record('trackuri')
|
68 |
def trackuri(a):
|
75 |
def trackuri(a):
|
69 |
msgproc.log("trackuri: [%s]" % a)
|
76 |
msgproc.log("trackuri: [%s]" % a)
|
70 |
if 'path' not in a:
|
77 |
if 'path' not in a:
|
|
... |
|
... |
103 |
# Build up root directory. No external data needed, this is our
|
110 |
# Build up root directory. No external data needed, this is our
|
104 |
# top internal structure
|
111 |
# top internal structure
|
105 |
entries.append(rcldirentry('0$uprcl$' + 'folders', '0$uprcl$',
|
112 |
entries.append(rcldirentry('0$uprcl$' + 'folders', '0$uprcl$',
|
106 |
'[folders]'))
|
113 |
'[folders]'))
|
107 |
elif idpath.startswith("folders"):
|
114 |
elif idpath.startswith("folders"):
|
108 |
entries = folders.browse(objid, bflg, httphp, pathprefix)
|
115 |
entries = uprclfolders.browse(objid, bflg, httphp, pathprefix)
|
109 |
else:
|
116 |
else:
|
110 |
pass
|
117 |
pass
|
111 |
|
118 |
|
112 |
|
119 |
|
113 |
#msgproc.log("%s" % entries)
|
120 |
#msgproc.log("%s" % entries)
|
|
... |
|
... |
117 |
|
124 |
|
118 |
@dispatcher.record('search')
|
125 |
@dispatcher.record('search')
|
119 |
def search(a):
|
126 |
def search(a):
|
120 |
msgproc.log("search: [%s]" % a)
|
127 |
msgproc.log("search: [%s]" % a)
|
121 |
objid = a['objid']
|
128 |
objid = a['objid']
|
122 |
field = a['field'] if 'field' in a else None
|
|
|
123 |
value = a['value']
|
|
|
124 |
objkind = a['objkind'] if 'objkind' in a else None
|
|
|
125 |
|
|
|
126 |
if re.match('0\$uprcl\$', objid) is None:
|
129 |
if re.match('0\$uprcl\$', objid) is None:
|
127 |
raise Exception("bad objid [%s]" % objid)
|
130 |
raise Exception("bad objid [%s]" % objid)
|
|
|
131 |
|
|
|
132 |
upnps = a['origsearch']
|
|
|
133 |
rcls = uprclsearch.upnpsearchtorecoll(upnps)
|
|
|
134 |
uplog("Search: recoll search: %s" % rcls)
|
128 |
|
135 |
|
129 |
searchresults = session.search(value)
|
136 |
rcldb = recoll.connect(confdir=rclconfdir)
|
|
|
137 |
rclq = rcldb.query()
|
|
|
138 |
rclq.execute(rcls)
|
|
|
139 |
uplog("Estimated query results: %d" % (rclq.rowcount))
|
130 |
|
140 |
|
131 |
if objkind and objkind not in ['artist', 'album', 'playlist', 'track']:
|
141 |
entries = []
|
132 |
msgproc.log('Unknown objkind \'%s\'' % objkind)
|
142 |
maxcnt = 0
|
133 |
objkind = None
|
143 |
totcnt = 0
|
134 |
if objkind is None or objkind == 'artist':
|
144 |
while True:
|
135 |
view(searchresults.artists,
|
145 |
docs = rclq.fetchmany()
|
136 |
urls_from_id(artist_view, searchresults.artists), end=False)
|
146 |
for doc in docs:
|
137 |
if objkind is None or objkind == 'album':
|
147 |
id = g_myprefix + '$' + 'seeyoulater'
|
138 |
view(searchresults.albums,
|
148 |
e = rcldoctoentry(id, objid, httphp, pathprefix, doc)
|
139 |
urls_from_id(album_view, searchresults.albums), end=False)
|
149 |
entries.append(e)
|
140 |
if objkind is None or objkind == 'playlist':
|
150 |
totcnt += 1
|
141 |
view(searchresults.playlists,
|
151 |
if (maxcnt > 0 and totcnt >= maxcnt) or len(docs) != rclq.arraysize:
|
142 |
urls_from_id(playlist_view, searchresults.playlists), end=False)
|
152 |
break
|
143 |
if objkind is None or objkind == 'track':
|
153 |
uplog("Search retrieved %d docs" % (totcnt,))
|
144 |
track_list(searchresults.tracks)
|
|
|
145 |
|
154 |
|
146 |
#msgproc.log("%s" % xbmcplugin.entries)
|
|
|
147 |
encoded = json.dumps(xbmcplugin.entries)
|
155 |
encoded = json.dumps(entries)
|
148 |
return {"entries" : encoded}
|
156 |
return {"entries" : encoded}
|
149 |
|
157 |
|
150 |
if not module_init():
|
158 |
uprcl_init()
|
151 |
msgproc.log("Uprcl init failed")
|
|
|
152 |
sys.exit(1)
|
|
|
153 |
|
159 |
|
154 |
msgproc.log("Uprcl running")
|
160 |
msgproc.log("Uprcl running")
|
155 |
msgproc.mainloop()
|
161 |
msgproc.mainloop()
|