| 13 | } |
| 14 | |
| 15 | TaskStatus AnimeScrapingTask::runTask() |
| 16 | { |
| 17 | auto script = GlobalObjects::scriptManager->getScript(curMatch.scriptId).staticCast<LibraryScript>(); |
| 18 | if (!script) |
| 19 | { |
| 20 | Logger::logger()->log(Logger::Script, QString("Match [%1] has Invalid ScriptId: %2").arg(curMatch.name, curMatch.scriptId)); |
| 21 | return TaskStatus::Failed; |
| 22 | } |
| 23 | AnimeLite ab; |
| 24 | ab.name = curMatch.name; |
| 25 | ab.scriptId = curMatch.scriptId; |
| 26 | ab.scriptData = curMatch.scriptData; |
| 27 | |
| 28 | Anime *nAnime = new Anime; |
| 29 | ScriptState state; |
| 30 | int waitTimes = 0; |
| 31 | const int maxWaitTimes = 10; |
| 32 | setInfo(tr("Fetching Anime Info[%1]...").arg(curMatch.name), NM_HIDE); |
| 33 | while (true) |
| 34 | { |
| 35 | if (_cancelFlag) |
| 36 | { |
| 37 | setInfo(tr("Task Canceled"), NM_ERROR | NM_HIDE); |
| 38 | delete nAnime; |
| 39 | return TaskStatus::Cancelled; |
| 40 | } |
| 41 | state = script->getDetail(ab, nAnime); |
| 42 | if (state.isBusy()) |
| 43 | { |
| 44 | if (waitTimes > maxWaitTimes) |
| 45 | { |
| 46 | delete nAnime; |
| 47 | Logger::logger()->log(Logger::Script, QString("Match [%1] ScriptId: %2 wait timeout").arg(curMatch.name, curMatch.scriptId)); |
| 48 | return TaskStatus::Failed; |
| 49 | } |
| 50 | ++waitTimes; |
| 51 | QThread::sleep(6); |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | if (!state) |
| 59 | { |
| 60 | delete nAnime; |
| 61 | Logger::logger()->log(Logger::Script, QString("Match [%1:%2] ScriptId: %3 failed: %4").arg(curMatch.name, curMatch.ep.toString(), curMatch.scriptId, state.info)); |
| 62 | return TaskStatus::Failed; |
| 63 | } |
| 64 | |
| 65 | QString animeName = AnimeWorker::instance()->addAnime(curAnime, nAnime); |
| 66 | Anime *tAnime = AnimeWorker::instance()->getAnime(animeName); |
| 67 | if (!tAnime) |
| 68 | { |
| 69 | setInfo(tr("Fetching Tags[%1] Failed").arg(animeName), NM_ERROR | NM_HIDE); |
| 70 | return TaskStatus::Finished; |
| 71 | } |
| 72 |
nothing calls this directly
no test coverage detected