| 93 | } |
| 94 | |
| 95 | ScriptState LibraryScript::getDetail(const AnimeLite &base, Anime *anime) |
| 96 | { |
| 97 | MutexLocker locker(scriptLock); |
| 98 | if(!locker.tryLock()) return ScriptState(ScriptState::S_BUSY); |
| 99 | QString errInfo; |
| 100 | QVariantList rets = call(detailFunc, {base.toMap()}, 1, errInfo, false); |
| 101 | if (!errInfo.isEmpty()) return ScriptState(ScriptState::S_ERROR, errInfo); |
| 102 | if (rets[0].metaType().id() != QMetaType::QVariantMap) return ScriptState(ScriptState::S_ERROR, "Wrong Return Value Type"); |
| 103 | // {name=xx, <desc=xx>, airdate=xx(yyyy-mm-dd), data=xx, <epcount=xx(int)>, <coverurl=xx>, <cover=xx> <url=xx>, |
| 104 | // <staff=xx("xx:xx;yy:yy;...")>, <crt=[{name=xx,<actor=xx>,<link=xx>, <imgurl=xx>, <image=xx>},...]>>} |
| 105 | auto aobj = rets[0].toMap(); |
| 106 | QString name = aobj.value("name").toByteArray(), |
| 107 | scriptData=aobj.value("data").toByteArray(), |
| 108 | airdate=aobj.value("airdate").toByteArray(); |
| 109 | if (name.isEmpty() || airdate.isEmpty()) return ScriptState(ScriptState::S_ERROR, "Wrong anime info"); |
| 110 | anime->_name = name; |
| 111 | anime->_desc = aobj.value("desc").toByteArray(); |
| 112 | anime->_url = aobj.value("url").toByteArray(); |
| 113 | anime->_scriptId = id(); |
| 114 | anime->_scriptData = scriptData; |
| 115 | anime->_airDate = airdate; |
| 116 | anime->_epCount = aobj.value("epcount", 0).toInt(); |
| 117 | anime->_coverURL = aobj.value("coverurl").toByteArray(); |
| 118 | if (aobj.contains("cover")) |
| 119 | { |
| 120 | anime->_coverData = aobj.value("cover").toByteArray(); |
| 121 | } |
| 122 | else if (!anime->_coverURL.isEmpty()) |
| 123 | { |
| 124 | Network::Reply reply(Network::httpGet(anime->coverURL(), QUrlQuery())); |
| 125 | if (!reply.hasError) |
| 126 | { |
| 127 | anime->_coverData = reply.content; |
| 128 | } |
| 129 | } |
| 130 | anime->staff.clear(); |
| 131 | if (aobj.contains("staff")) |
| 132 | { |
| 133 | QString staffstr = aobj.value("staff").toString(); |
| 134 | auto strs = staffstr.split(';', Qt::SkipEmptyParts); |
| 135 | for(const auto &s : strs) |
| 136 | { |
| 137 | int pos = s.indexOf(':'); |
| 138 | anime->staff.append({s.mid(0, pos), s.mid(pos+1)}); |
| 139 | } |
| 140 | } |
| 141 | anime->characters.clear(); |
| 142 | if (aobj.contains("crt") && aobj.value("crt").metaType().id() == QMetaType::QVariantList) |
| 143 | { |
| 144 | auto crts = aobj.value("crt").toList(); |
| 145 | auto crtImgLoad = [](QByteArray &data, Character *crt){ |
| 146 | QBuffer bufferImage(&data); |
| 147 | bufferImage.open(QIODevice::ReadOnly); |
| 148 | QImageReader reader(&bufferImage); |
| 149 | QSize s = reader.size(); |
| 150 | int w = qMin(s.width(), s.height()); |
| 151 | reader.setScaledClipRect(QRect(0, 0, w, w)); |
| 152 | crt->image = QPixmap::fromImageReader(&reader); |
nothing calls this directly
no test coverage detected