Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

## [0.3.3] - 2026-11-19

### Fixed

- The Profile no longer fails with HTTP 500 on firmware whose playtime database has no `playedTimeOnConsole` column, such as 6.02 ([#18](https://github.com/marcelorsdd/OpenPSApp/issues/18)). There OpenPSApp shows the total that PSN keeps for each game, `gltTotalPlayedTime`. A missing column in the playtime database no longer causes an error: OpenPSApp uses the next column it knows, or shows no playtime.

## [0.3.2] - 2026-11-16

### Fixed
Expand Down Expand Up @@ -100,7 +106,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- Diagnostic endpoints, off by default (`"debug": true`).
- Builds take their version from the git tag.

[Unreleased]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.2...HEAD
[Unreleased]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.3...HEAD
[0.3.3]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.2...v0.3.3
[0.3.2]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/marcelorsdd/OpenPSApp/compare/v0.2.0...v0.3.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ No. It reads files on the console. The only server it ever contacts is the one y

OpenPSApp shows what this console recorded. Time played on another console is not included.

Some firmware versions, such as 6.02, do not record the console's own playtime. On those, OpenPSApp shows the total that PSN keeps for the game, which includes other consoles. The console fills in that total only when it goes online, so a console that stays offline shows no playtime.

### Which profile does it show?

The profile signed in on the PS5. Each profile links to the website on its own.
Expand Down
30 changes: 18 additions & 12 deletions payload/src/services/playtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ struct TitleMeta {
bool is_app = false;
};

std::string ColumnOr(const std::set<std::string> &cols, const char *col, const char *fallback) {
return cols.count(col) ? std::string("COALESCE(") + col + "," + fallback + ")" : fallback;
std::string FirstColumn(const std::set<std::string> &cols, std::initializer_list<const char *> names,
const char *fallback) {
for (const char *name : names) {
if (cols.count(name)) return std::string("COALESCE(") + name + "," + fallback + ")";
}
return fallback;
}

std::set<std::string> ColumnSet(const AppDb &db, const std::string &table) {
Expand All @@ -34,10 +38,11 @@ std::unordered_map<std::string, TitleMeta> LoadTitleMeta(const AppDb &db) {
std::unordered_map<std::string, TitleMeta> meta;

std::set<std::string> cols = ColumnSet(db, "tbl_contentinfo");
if (!cols.empty()) {
std::string sql = "SELECT titleId, " + ColumnOr(cols, "titleName", "''") + ", " +
ColumnOr(cols, "is3rdPartyVideoApp", "0") + ", " + ColumnOr(cols, "categoryType", "0") +
", " + ColumnOr(cols, "metaDataPath", "''") + " FROM tbl_contentinfo";
if (cols.count("titleId")) {
std::string sql = "SELECT titleId, " + FirstColumn(cols, {"titleName"}, "''") + ", " +
FirstColumn(cols, {"is3rdPartyVideoApp"}, "0") + ", " +
FirstColumn(cols, {"categoryType"}, "0") + ", " + FirstColumn(cols, {"metaDataPath"}, "''") +
" FROM tbl_contentinfo";
db.ForEachRow(sql, {}, [&meta](const AppDb::Row &r) {
TitleMeta &m = meta[r.Text(0)];
if (m.name.empty()) m.name = r.Text(1);
Expand All @@ -47,7 +52,8 @@ std::unordered_map<std::string, TitleMeta> LoadTitleMeta(const AppDb &db) {
});
}

if (ColumnSet(db, "tbl_appbrowse").count("titleName")) {
std::set<std::string> browse = ColumnSet(db, "tbl_appbrowse");
if (browse.count("titleId") && browse.count("titleName")) {
db.ForEachRow("SELECT titleId, titleName FROM tbl_appbrowse WHERE titleName IS NOT NULL AND titleName != ''",
{}, [&meta](const AppDb::Row &r) {
TitleMeta &m = meta[r.Text(0)];
Expand All @@ -60,7 +66,7 @@ std::unordered_map<std::string, TitleMeta> LoadTitleMeta(const AppDb &db) {
std::vector<std::string> PickTables(const AppDb &db, const std::optional<platform::User> &user) {
std::vector<std::string> tables;
for (const std::string &t : db.Tables(std::string(layout::kIconInfoPrefix) + "%")) {
if (ColumnSet(db, t).count("playedTimeOnConsole")) tables.push_back(t);
if (ColumnSet(db, t).count("titleId")) tables.push_back(t);
}
if (user) {
char decimal[16];
Expand Down Expand Up @@ -117,7 +123,7 @@ PlaytimeReport CollectPlaytime(const std::optional<platform::User> &user) {

report.tables = PickTables(db, user);
if (report.tables.empty()) {
report.error = "no tbl_iconinfo_* table with playedTimeOnConsole";
report.error = "no tbl_iconinfo_* table with titleId";
return report;
}

Expand All @@ -126,9 +132,9 @@ PlaytimeReport CollectPlaytime(const std::optional<platform::User> &user) {

for (const std::string &table : report.tables) {
std::set<std::string> cols = ColumnSet(db, table);
std::string last = cols.count("lastPlayedDateOnConsole") ? ColumnOr(cols, "lastPlayedDateOnConsole", "''")
: ColumnOr(cols, "lastAccessTime", "''");
std::string sql = "SELECT titleId, COALESCE(playedTimeOnConsole,0), " + last + " FROM " + table;
std::string played = FirstColumn(cols, {"playedTimeOnConsole", "gltTotalPlayedTime"}, "0");
std::string last = FirstColumn(cols, {"lastPlayedDateOnConsole", "gltlastPlayedDate", "lastAccessTime"}, "''");
std::string sql = "SELECT titleId, " + played + ", " + last + " FROM " + table;
db.ForEachRow(sql, {}, [&](const AppDb::Row &r) {
std::string title_id = r.Text(0);
if (!IsGameTitleId(title_id)) return;
Expand Down
8 changes: 8 additions & 0 deletions payload/tests/host/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ CREATE TABLE tbl_contentinfo (titleId TEXT, titleName TEXT, is3rdPartyVideoApp I
CREATE TABLE tbl_appbrowse (titleId TEXT, titleName TEXT);
CREATE TABLE tbl_iconinfo_0515316669 (titleId TEXT, playedTimeOnConsole INTEGER, lastAccessTime TEXT, lastPlayedDateOnConsole TEXT);
CREATE TABLE tbl_iconinfo_0000043690 (titleId TEXT, playedTimeOnConsole INTEGER, lastAccessTime TEXT, lastPlayedDateOnConsole TEXT);
CREATE TABLE tbl_iconinfo_0000048059 (titleId TEXT, lastAccessTime TEXT, lastPlayedDateOnConsole TEXT, gltlastPlayedDate TEXT, gltTotalPlayedTime INTEGER);
CREATE TABLE tbl_iconinfo_0000052428 (titleId TEXT, lastAccessTime TEXT);
CREATE TABLE tbl_iconinfo_0000056797 (name TEXT);

INSERT INTO tbl_contentinfo VALUES
('PPSA01234', 'Astro Test', 0, 0, '/mnt/ext0/user/app/PPSA01234/sce_sys'),
Expand All @@ -34,6 +37,11 @@ INSERT INTO tbl_iconinfo_0515316669 VALUES
INSERT INTO tbl_iconinfo_0000043690 VALUES
('PPSA01234', 99999, '2026-11-08 07:00:00', '2026-11-08 07:00:00'),
('PPSA07777', 500, '2026-09-09 09:09:09', '2026-09-09 09:09:09');
INSERT INTO tbl_iconinfo_0000048059 VALUES
('PPSA02222', '2026-11-10 12:00:00', '2026-11-10 09:00:00.000', '2026-11-10 09:30:00', 5400),
('PPSA03333', '2026-11-01 08:00:00', '2026-11-01 07:00:00.000', NULL, NULL);
INSERT INTO tbl_iconinfo_0000052428 VALUES ('PPSA04444', '2026-10-05 05:00:00');
INSERT INTO tbl_iconinfo_0000056797 VALUES ('PPSA05555');
)SQL";

bool WriteFile(const std::string &path, const std::string &data) {
Expand Down
51 changes: 49 additions & 2 deletions payload/tests/host/test_playtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,56 @@ TEST(playtime_falls_back_to_appbrowse_name_and_external_icon) {
if (old) CHECK(old->icon.path.find("/user/appmeta/external/CUSA00001/icon0.png") != std::string::npos);
}

TEST(playtime_reads_the_psn_total_on_firmware_without_console_time) {
platform::User older = fixture::User();
older.id = 48059;
older.id_hex = "0000bbbb";
PlaytimeReport r = CollectPlaytime(older);
CHECK_EQ(r.error, std::string(""));
CHECK_EQ(r.tables.size(), size_t(1));
CHECK_EQ(r.tables.empty() ? std::string() : r.tables[0], std::string("tbl_iconinfo_0000048059"));

const GamePlaytime *played = r.Find("PPSA02222");
CHECK(played != nullptr);
if (played) {
CHECK_EQ(played->playtime_seconds, int64_t(5400));
CHECK_EQ(played->last_played_at, std::string("2026-11-10T09:00:00Z"));
}
const GamePlaytime *offline = r.Find("PPSA03333");
CHECK(offline != nullptr);
if (offline) {
CHECK_EQ(offline->playtime_seconds, int64_t(0));
CHECK_EQ(offline->last_played_at, std::string("2026-11-01T07:00:00Z"));
}
}

TEST(playtime_reads_a_profile_table_with_only_the_basic_columns) {
platform::User bare = fixture::User();
bare.id = 52428;
bare.id_hex = "0000cccc";
PlaytimeReport r = CollectPlaytime(bare);
CHECK_EQ(r.error, std::string(""));
CHECK_EQ(r.games.size(), size_t(1));
const GamePlaytime *g = r.Find("PPSA04444");
CHECK(g != nullptr);
if (g) {
CHECK_EQ(g->playtime_seconds, int64_t(0));
CHECK_EQ(g->last_played_at, std::string("2026-10-05T05:00:00Z"));
}
}

TEST(playtime_skips_a_profile_table_without_title_ids) {
platform::User broken = fixture::User();
broken.id = 56797;
broken.id_hex = "0000dddd";
PlaytimeReport r = CollectPlaytime(broken);
CHECK_EQ(r.error, std::string(""));
CHECK_EQ(r.tables.size(), size_t(4));
}

TEST(playtime_without_user_merges_profiles_by_max) {
PlaytimeReport r = CollectPlaytime(std::nullopt);
CHECK_EQ(r.tables.size(), size_t(2));
CHECK_EQ(r.tables.size(), size_t(4));
const GamePlaytime *astro = r.Find("PPSA01234");
CHECK(astro != nullptr);
if (astro) {
Expand All @@ -69,7 +116,7 @@ TEST(playtime_unknown_profile_falls_back_to_merge) {
platform::User nobody = fixture::User();
nobody.id = 0x0badbeef;
nobody.id_hex = "0badbeef";
CHECK_EQ(CollectPlaytime(nobody).tables.size(), size_t(2));
CHECK_EQ(CollectPlaytime(nobody).tables.size(), size_t(4));
}

TEST(game_title_ids) {
Expand Down
Loading