5
5
from json_database import JsonStorageXDG
6
6
from ovos_bus_client .apis .ocp import OCPInterface
7
7
from ovos_bus_client .message import Message
8
-
9
8
from ovos_utils import classproperty
10
9
from ovos_utils .log import LOG
10
+ from ovos_utils .ocp import MediaType , PlaybackType
11
+ from ovos_utils .parse import fuzzy_match , MatchStrategy
11
12
from ovos_utils .process_utils import RuntimeRequirements
12
13
from ovos_workshop .decorators import intent_handler
13
14
from ovos_workshop .decorators .ocp import ocp_search
14
15
from ovos_workshop .skills .common_play import OVOSCommonPlaybackSkill
15
- from ovos_utils .ocp import MediaType , PlaybackType
16
16
17
17
18
18
class LocalMediaSkill (OVOSCommonPlaybackSkill ):
@@ -24,7 +24,7 @@ class LocalMediaSkill(OVOSCommonPlaybackSkill):
24
24
25
25
def __init__ (self , * args , ** kwargs ):
26
26
self .archive = JsonStorageXDG ("LocalMedia" , subfolder = "OCP" )
27
- super ().__init__ (skill_icon = join (dirname (__file__ ), "res" , "icon" , "ovos-file-browser.svg" ),
27
+ super ().__init__ (skill_icon = join (dirname (__file__ ), "res" , "icon" , "ovos-file-browser.svg" ),
28
28
supported_media = [MediaType .SHORT_FILM , MediaType .MUSIC ,
29
29
MediaType .RADIO , MediaType .RADIO_THEATRE ,
30
30
MediaType .MOVIE , MediaType .AUDIOBOOK ,
@@ -146,16 +146,24 @@ def search_db(self, phrase, media_type):
146
146
entities = self .ocp_voc_match (phrase )
147
147
base_score += 30 * len (entities )
148
148
149
+ if media_type == MediaType .GENERIC :
150
+ candidates = self .archive .values ()
151
+ else :
152
+ candidates = [video for video in self .archive .values ()
153
+ if video ["media_type" ] == media_type ]
154
+
149
155
if entities :
150
- if media_type == MediaType .GENERIC :
151
- candidates = self .archive .values ()
152
- else :
153
- candidates = [video for video in self .archive .values ()
154
- if video ["media_type" ] == media_type ]
155
-
156
156
title = list (entities .values ())[0 ]
157
- return [video for video in candidates
158
- if title .lower () in video ["title" ].lower ()]
157
+ for video in candidates :
158
+ if title .lower () in video ["title" ].lower ():
159
+ video ["match_confidence" ] = base_score
160
+ yield video
161
+ else :
162
+ for entry in candidates :
163
+ score = fuzzy_match (phrase , entry ["title" ],
164
+ strategy = MatchStrategy .DAMERAU_LEVENSHTEIN_SIMILARITY )
165
+ entry ["match_confidence" ] = score * 100
166
+ yield entry
159
167
return []
160
168
161
169
## File Browser
0 commit comments