Mercurial > minori
comparison src/core/anime_db.cc @ 317:b1f4d1867ab1
services: VERY initial Kitsu support
it only supports user authentication for now, but it's definitely
a start.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 12 Jun 2024 04:07:10 -0400 |
parents | 53e3c015a973 |
children | d928ec7b6a0d |
comparison
equal
deleted
inserted
replaced
316:180714442770 | 317:b1f4d1867ab1 |
---|---|
10 #include <QDate> | 10 #include <QDate> |
11 | 11 |
12 #include <fstream> | 12 #include <fstream> |
13 | 13 |
14 #include <exception> | 14 #include <exception> |
15 #include <cstdlib> | |
15 #include <iostream> | 16 #include <iostream> |
17 #include <random> | |
16 | 18 |
17 namespace Anime { | 19 namespace Anime { |
18 | 20 |
19 size_t Database::GetTotalAnimeAmount() { | 21 size_t Database::GetTotalAnimeAmount() { |
20 size_t total = 0; | 22 size_t total = 0; |
298 return false; | 300 return false; |
299 | 301 |
300 return true; | 302 return true; |
301 } | 303 } |
302 | 304 |
305 int Database::GetUnusedId() { | |
306 /* TODO: move these out of here */ | |
307 | |
308 std::random_device rd; | |
309 std::mt19937 gen(rd()); | |
310 std::uniform_int_distribution<int> distrib(1, INT_MAX); | |
311 int res; | |
312 | |
313 do { | |
314 res = distrib(gen); | |
315 } while (items.count(res)); | |
316 | |
317 return res; | |
318 } | |
319 | |
320 int Database::LookupServiceId(Service service, const std::string& id_to_find) { | |
321 for (const auto& [id, anime] : items) { | |
322 std::optional<std::string> service_id = anime.GetServiceId(service); | |
323 if (!service_id) | |
324 continue; | |
325 | |
326 if (service_id == id_to_find) | |
327 return id; | |
328 } | |
329 | |
330 return 0; | |
331 } | |
332 | |
333 int Database::LookupServiceIdOrUnused(Service service, const std::string& id_to_find) { | |
334 int id = LookupServiceId(service, id_to_find); | |
335 if (id) | |
336 return id; | |
337 | |
338 return GetUnusedId(); | |
339 } | |
340 | |
303 Database db; | 341 Database db; |
304 | 342 |
305 } // namespace Anime | 343 } // namespace Anime |