| 252 | } |
| 253 | |
| 254 | ScriptState LibraryScript::match(const QString &path, MatchResult &result) |
| 255 | { |
| 256 | MutexLocker locker(scriptLock); |
| 257 | if(!locker.tryLock()) return ScriptState(ScriptState::S_BUSY); |
| 258 | QString errInfo; |
| 259 | QVariantList rets = call(matchFunc, {path}, 1, errInfo); |
| 260 | if(!errInfo.isEmpty()) return ScriptState(ScriptState::S_ERROR, errInfo); |
| 261 | if(rets[0].type()!=QVariant::Map) return ScriptState(ScriptState::S_ERROR, "Wrong Return Value Type"); |
| 262 | auto m = rets[0].toMap(); //{success=xx, anime={name=xx,data=xx}, ep={name=xx, index=number, <type=xx>}} |
| 263 | do |
| 264 | { |
| 265 | if(!m.value("success", false).toBool()) break; |
| 266 | if(!m.contains("anime") || !m.contains("ep")) break; |
| 267 | auto anime = m.value("anime"), ep = m.value("ep"); |
| 268 | if(anime.type()!=QVariant::Map || ep.type()!= QVariant::Map) break; |
| 269 | auto aobj = anime.toMap(), epobj = ep.toMap(); |
| 270 | QString animeName = aobj.value("name").toString(), animeId = aobj.value("data").toString(); |
| 271 | QString epName = epobj.value("name").toString(); |
| 272 | double epIndex = epobj.value("index", -1).toDouble(); |
| 273 | if(animeName.isEmpty() || animeId.isEmpty() || epName.isEmpty() || epIndex<0) break; |
| 274 | result.success = true; |
| 275 | result.name = animeName; |
| 276 | result.scriptId = aobj.contains("scriptId")?aobj.value("scriptId").toString():id(); |
| 277 | result.scriptData = animeId; |
| 278 | EpInfo &epinfo = result.ep; |
| 279 | epinfo.localFile = path; |
| 280 | epinfo.index = epIndex; epinfo.name = epName; |
| 281 | epinfo.type = EpType(qBound(1, epobj.value("type", 1).toInt(), int(EpType::Other))); |
| 282 | return ScriptState(ScriptState::S_NORM); |
| 283 | }while(false); |
| 284 | result.success = false; |
| 285 | return ScriptState(ScriptState::S_NORM); |
| 286 | } |
| 287 | |
| 288 | ScriptState LibraryScript::menuClick(const QString &mid, Anime *anime) |
| 289 | { |