From 3fbcdd50eedc72969e7a339a761b5e2744b34343 Mon Sep 17 00:00:00 2001 From: Marcelo Camargo <90155206+marcelorsdd@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:33:09 -0300 Subject: [PATCH 1/2] fix(playtime): read firmware without playedTimeOnConsole and treat every column as optional On firmware such as 6.02, tbl_iconinfo_ has no playedTimeOnConsole column, so no table qualified, the games list returned an error and the Profile showed HTTP 500 (#18). A profile table now only needs titleId. Playtime comes from playedTimeOnConsole, then gltTotalPlayedTime (the PSN total), then 0. The last-played date comes from lastPlayedDateOnConsole, then gltlastPlayedDate, then lastAccessTime. tbl_contentinfo and tbl_appbrowse are read only when they have titleId. Fixes #18 --- CHANGELOG.md | 4 +++ README.md | 2 ++ payload/src/services/playtime.cpp | 30 +++++++++------- payload/tests/host/fixture.cpp | 8 +++++ payload/tests/host/test_playtime.cpp | 51 ++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccdfa9d..c8885b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### 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 diff --git a/README.md b/README.md index b73caf5..ef120ff 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/payload/src/services/playtime.cpp b/payload/src/services/playtime.cpp index 2dbf7fb..e452309 100644 --- a/payload/src/services/playtime.cpp +++ b/payload/src/services/playtime.cpp @@ -21,8 +21,12 @@ struct TitleMeta { bool is_app = false; }; -std::string ColumnOr(const std::set &cols, const char *col, const char *fallback) { - return cols.count(col) ? std::string("COALESCE(") + col + "," + fallback + ")" : fallback; +std::string FirstColumn(const std::set &cols, std::initializer_list names, + const char *fallback) { + for (const char *name : names) { + if (cols.count(name)) return std::string("COALESCE(") + name + "," + fallback + ")"; + } + return fallback; } std::set ColumnSet(const AppDb &db, const std::string &table) { @@ -34,10 +38,11 @@ std::unordered_map LoadTitleMeta(const AppDb &db) { std::unordered_map meta; std::set 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); @@ -47,7 +52,8 @@ std::unordered_map LoadTitleMeta(const AppDb &db) { }); } - if (ColumnSet(db, "tbl_appbrowse").count("titleName")) { + std::set 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)]; @@ -60,7 +66,7 @@ std::unordered_map LoadTitleMeta(const AppDb &db) { std::vector PickTables(const AppDb &db, const std::optional &user) { std::vector 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]; @@ -117,7 +123,7 @@ PlaytimeReport CollectPlaytime(const std::optional &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; } @@ -126,9 +132,9 @@ PlaytimeReport CollectPlaytime(const std::optional &user) { for (const std::string &table : report.tables) { std::set 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; diff --git a/payload/tests/host/fixture.cpp b/payload/tests/host/fixture.cpp index 91600b7..22af709 100644 --- a/payload/tests/host/fixture.cpp +++ b/payload/tests/host/fixture.cpp @@ -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'), @@ -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) { diff --git a/payload/tests/host/test_playtime.cpp b/payload/tests/host/test_playtime.cpp index 60cd60f..0fb2ec4 100644 --- a/payload/tests/host/test_playtime.cpp +++ b/payload/tests/host/test_playtime.cpp @@ -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) { @@ -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) { From ea6d73d0e8af2a62356622af2f436029a8bb49a7 Mon Sep 17 00:00:00 2001 From: Marcelo Camargo <90155206+marcelorsdd@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:37:50 -0300 Subject: [PATCH 2/2] chore: release v0.3.3 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8885b0..e0f9e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ 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. @@ -104,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