view src/track/media.cc @ 327:b5d6c27c308f

anime: refactor Anime::SeriesSeason to Season class ToLocalString has also been altered to take in both season and year because lots of locales actually treat formatting seasons differently! most notably is Russian which adds a suffix at the end to notate seasons(??)
author Paper <paper@paper.us.eu.org>
date Thu, 13 Jun 2024 01:49:18 -0400
parents b1f4d1867ab1
children 1faa72660932
line wrap: on
line source

#include "track/media.h"
#include "core/filesystem.h"
#include "core/session.h"
#include "core/strings.h"

#include <QFile>
#include <QTextStream>

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

#include <iostream>

#include "animone.h"

namespace Track {
namespace Media {

static bool GetCurrentlyPlayingResults(std::vector<animone::Result>& results) {
	std::vector<animone::Player> players;

	players.reserve(session.config.recognition.players.size());
	for (const auto& [enabled, player] : session.config.recognition.players)
		if (enabled && player.type == animone::PlayerType::Default)
			players.push_back(player);

	return animone::GetResults(players, results);
}

/* meh */
bool GetCurrentlyPlaying(std::vector<std::string>& vec) {
	std::vector<animone::Result> results;

	if (!GetCurrentlyPlayingResults(results))
		return false;

	bool success = false;

	for (const auto& result : results) {
		for (const auto& media : result.media) {
			for (const auto& info : media.information) {
				switch (info.type) {
					case animone::MediaInfoType::File:
						vec.push_back(std::filesystem::path(info.value).filename().u8string());
						success |= true;
						break;
					case animone::MediaInfoType::Title:
						vec.push_back(info.value);
						success |= true;
						break;
					default: break;
				}
			}
		}
	}

	return success;
}

} // namespace Media
} // namespace Track