view src/library/library.cc @ 229:adc20fa321c1

theme: force Fusion style on platforms other than Win32 or OS X I was reluctant to do this, but most of the other styles just look like pure shite regardless of whether I force a stylesheet on them or not. KDE's style is actually hilariously bad paired with my stylesheet, so I've decided to also make the stylesheet Windows-specific as well, because that's really the only platform where it makes sense in the first place.
author Paper <paper@paper.us.eu.org>
date Wed, 10 Jan 2024 21:23:57 -0500
parents b9f111d84d95
children 84e0a3c4737a
line wrap: on
line source

#include "library/library.h"
#include "core/anime_db.h"
#include "core/strings.h"
#include "core/session.h"

#include "anitomy/anitomy.h"

#include <filesystem>
#include <unordered_map>
#include <string>

// int = anime id, map = episode, paths
std::unordered_map<int, std::unordered_map<int, std::string>> library;

void SearchLibraryFolders() {
	library.clear();

	for (const auto& spath : session.config.library.paths) {
		const std::filesystem::path path(spath);
		for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
			if (!std::filesystem::is_regular_file(entry.path()))
				continue;

			const std::string basename = path.filename();

			anitomy::Anitomy anitomy;
			anitomy.Parse(Strings::ToWstring(basename));

			const auto& elements = anitomy.elements();

			const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));

			const int id = Anime::db.GetAnimeFromTitle(title);
			if (id <= 0)
				continue;

			const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)));

			// we have an ID now!
			library[id][episode] = entry.path();
		}
	}
}