| 141 | } |
| 142 | |
| 143 | int AnimeWorker::fetchAnimes(QVector<Anime *> *animes, int offset, int limit) |
| 144 | { |
| 145 | ThreadTask task(GlobalObjects::workThread); |
| 146 | return task.Run([=](){ |
| 147 | QSqlQuery query(DBManager::instance()->getDB(DBManager::Bangumi)); |
| 148 | query.exec(QString("select * from anime order by AddTime desc limit %1 offset %2").arg(limit).arg(offset)); |
| 149 | int animeNo=query.record().indexOf("Anime"), |
| 150 | descNo=query.record().indexOf("Desc"), |
| 151 | timeNo=query.record().indexOf("AddTime"), |
| 152 | airDateNo=query.record().indexOf("AirDate"), |
| 153 | epCountNo=query.record().indexOf("EpCount"), |
| 154 | urlNo=query.record().indexOf("URL"), |
| 155 | scriptIdNo=query.record().indexOf("ScriptId"), |
| 156 | scriptDataNo=query.record().indexOf("ScriptData"), |
| 157 | staffNo=query.record().indexOf("Staff"), |
| 158 | coverURLNo=query.record().indexOf("CoverURL"), |
| 159 | coverNo=query.record().indexOf("Cover"); |
| 160 | QSqlQuery crtQuery(DBManager::instance()->getDB(DBManager::Bangumi)); |
| 161 | crtQuery.prepare("select Name, Actor, Link, ImageURL from character where Anime=?"); |
| 162 | int count=0; |
| 163 | while (query.next()) |
| 164 | { |
| 165 | Anime *anime=new Anime; |
| 166 | anime->_name=query.value(animeNo).toString(); |
| 167 | anime->_desc=query.value(descNo).toString(); |
| 168 | anime->_airDate=query.value(airDateNo).toString(); |
| 169 | anime->_addTime=query.value(timeNo).toLongLong(); |
| 170 | anime->_epCount=query.value(epCountNo).toInt(); |
| 171 | anime->_url=query.value(urlNo).toString(); |
| 172 | anime->_scriptId=query.value(scriptIdNo).toString(); |
| 173 | anime->_scriptData=query.value(scriptDataNo).toString(); |
| 174 | anime->setStaffs(query.value(staffNo).toString()); |
| 175 | anime->_coverURL=query.value(coverURLNo).toString(); |
| 176 | anime->_coverData = query.value(coverNo).toByteArray(); |
| 177 | //anime->_cover.loadFromData(query.value(coverNo).toByteArray()); |
| 178 | |
| 179 | crtQuery.bindValue(0,anime->_name); |
| 180 | crtQuery.exec(); |
| 181 | int nameNo=crtQuery.record().indexOf("Name"), |
| 182 | actorNo=crtQuery.record().indexOf("Actor"), |
| 183 | linkNo=crtQuery.record().indexOf("Link"), |
| 184 | imageURLNo=crtQuery.record().indexOf("ImageURL"); |
| 185 | while (crtQuery.next()) |
| 186 | { |
| 187 | Character crt; |
| 188 | crt.name=crtQuery.value(nameNo).toString(); |
| 189 | crt.actor=crtQuery.value(actorNo).toString(); |
| 190 | crt.link=crtQuery.value(linkNo).toString(); |
| 191 | crt.imgURL=crtQuery.value(imageURLNo).toString(); |
| 192 | anime->characters.append(crt); |
| 193 | } |
| 194 | animes->append(anime); |
| 195 | insertAnimeInMap(anime); |
| 196 | count++; |
| 197 | } |
| 198 | return count; |
| 199 | }).toInt(); |
| 200 | } |