achievements-app/psn-api

Add User playtime calculation

TheYuriG opened this issue · 7 comments

Housekeeping job for pending requests.
Requested by chaZmich on Jan 16th, 2022, here.

Reference: endpoint (right click and copy link address, don't click), psnawp.

User loadingpix requested the ability to fetch the most recently played games (not recently earned trophies) here. Once this issue is complete, that can also, most likely, be done.

Also requested by alekpentchev, here and researched by FunkeyFlo, which offered assistance if contacted through Twitter.

References found added to OP.

Alright, this is a doozer, but here we go. The endpoint will return good data, as seen below from one game example.

This data is from... uh, a friend of mine...

{
            "titleId": "CUSA01810_00",
            "name": "Tom Clancy's The Division™",
            "localizedName": "Tom Clancy's The Division™",
            "imageUrl": "https://image.api.playstation.com/gs2-sec/appkgo/prod/CUSA01262_00/3/i_e6d232ba4d068e89ed9de881fa1fa3939d7e3d00a77bcd43ad652f4bd3f1029d/i/icon0.png",
            "localizedImageUrl": "https://image.api.playstation.com/gs2-sec/appkgo/prod/CUSA01262_00/3/i_e6d232ba4d068e89ed9de881fa1fa3939d7e3d00a77bcd43ad652f4bd3f1029d/i/icon0.png",
            "category": "ps4_game",
            "service": "none_purchased",
            "playCount": 291,
            "concept": {
                "id": 204941,
                "titleIds": [
                    "CUSA07926_00",
                    "CUSA01663_00",
                    "CUSA01451_00",
                    "CUSA04438_00",
                    "CUSA01262_00",
                    "CUSA02999_00",
                    "CUSA01810_00",
                    "CUSA03074_00",
                    "CUSA03566_00",
                    "CUSA07810_00",
                    "CUSA03058_00",
                    "CUSA03073_00"
                ],
                "name": "Tom Clancy's The Division™",
                "media": {
                    "audios": [],
                    "videos": [],
                    "images": [
                        {
                            "url": "https://image.api.playstation.com/vulcan/img/rnd/202010/0200/ppAHkINcbMsgOAbvA8R4NyLI.jpg",
                            "format": "UNKNOWN",
                            "type": "GAMEHUB_COVER_ART"
                        },
                        {
                            "url": "https://image.api.playstation.com/vulcan/img/rnd/202011/1122/laFNMWkxIz0XdcrxKfS8nScq.png",
                            "format": "UNKNOWN",
                            "type": "LOGO"
                        },
                        {
                            "url": "https://image.api.playstation.com/gs2-sec/appkgo/prod/CUSA01262_00/3/i_e6d232ba4d068e89ed9de881fa1fa3939d7e3d00a77bcd43ad652f4bd3f1029d/i/icon0.png",
                            "format": "UNKNOWN",
                            "type": "MASTER"
                        }
                    ]
                },
                "genres": [
                    "ACTION",
                    "SHOOTER"
                ],
                "localizedName": {
                    "defaultLanguage": "en-US",
                    "metadata": {
                        "ar-AE": "Tom Clancy's The Division™",
                        "da-DK": "Tom Clancy's The Division™",
                        "de-DE": "Tom Clancy's The Division™",
                        "en-GB": "Tom Clancy's The Division™",
                        "en-US": "Tom Clancy's The Division™",
                        "es-419": "Tom Clancy's The Division™",
                        "es-ES": "Tom Clancy's The Division™",
                        "fi-FI": "Tom Clancy's The Division™",
                        "fr-CA": "Tom Clancy's The Division™",
                        "fr-FR": "Tom Clancy's The Division™",
                        "it-IT": "Tom Clancy's The Division™",
                        "ja-JP": "ディビジョン",
                        "ko-KR": "톰 클랜시의 디비전",
                        "nl-NL": "Tom Clancy's The Division™",
                        "no-NO": "Tom Clancy's The Division™",
                        "pl-PL": "Tom Clancy's The Division™",
                        "pt-BR": "Tom Clancy's The Division™",
                        "pt-PT": "Tom Clancy's The Division™",
                        "ru-RU": "Tom Clancy's The Division™",
                        "sv-SE": "Tom Clancy's The Division™",
                        "tr-TR": "Tom Clancy's The Division™",
                        "uk-UA": "Tom Clancy's The Division™",
                        "zh-Hans": "《汤姆克兰西:全境封锁》",
                        "zh-Hant": "《湯姆克蘭西:全境封鎖》"
                    }
                },
                "country": "BR",
                "language": "pt"
            },
            "media": {
                "audios": [],
                "videos": [],
                "images": [
                    {
                        "url": "https://image.api.playstation.com/vulcan/img/rnd/202010/0200/ppAHkINcbMsgOAbvA8R4NyLI.jpg",
                        "format": "UNKNOWN",
                        "type": "GAMEHUB_COVER_ART"
                    },
                    {
                        "url": "https://image.api.playstation.com/vulcan/img/rnd/202011/1122/laFNMWkxIz0XdcrxKfS8nScq.png",
                        "format": "UNKNOWN",
                        "type": "LOGO"
                    },
                    {
                        "url": "https://image.api.playstation.com/gs2-sec/appkgo/prod/CUSA01262_00/3/i_e6d232ba4d068e89ed9de881fa1fa3939d7e3d00a77bcd43ad652f4bd3f1029d/i/icon0.png",
                        "format": "UNKNOWN",
                        "type": "MASTER"
                    }
                ]
            },
            "firstPlayedDateTime": "2018-04-05T11:18:27.460000Z",
            "lastPlayedDateTime": "2023-01-29T16:03:44.310000Z",
            "playDuration": "PT799H55M7S"
        }

Once again, there is no reference to the user itself on these. Very important data entry points here are:

  • titleId: Average title ID, not trophy list npCommunicationId (those are always NPWR[5 digit code]_00). No way to link these to the original games.
  • name/concept.name: These seems to be the same trophyTitleName provided when querying from titles, since it's not localized. The localized versions are below in concept.localizedName.metadata.
  • service: What is this? Microtransactions purchased? I'm curious to know.
  • playCount: Number of times the user have launched the game, regardless of time played in each session. Could use this to calculate average playtime, I guess?
  • firstPlayedDateTime: First time the user booted the game, doesn't matter how much time played or trophies earned.
  • lastPlayedDateTime: Last time the user booted the game, doesn't matter how much time played or trophies earned. This is what @loadingpix asked for.
  • playDuration: How long the user has played this title overall. As Wes mentioned, this time is inaccurate, but it's what Sony provides to us.

@alekpentchev please don't delete your comments, you can just edit them later.

I've made a PR for this, but some changes are required and I haven't had time for it. You can feel free to complete the changes so wes can do the merge, if you feel inclined about it.

@TheYuriG Sorry for that :) I have deleted it after I had found there's a PR addressing this topic.
Is it described in the PR what's remaining to be done? Or could you summarize it in bullet points?

@TheYuriG Sorry for that :)

It's fine, happens to all of us. I should have mentioned this issue when I made the PR so it would show up on the timeline, but I didn't.

Is it described in the PR what's remaining to be done? Or could you summarize it in bullet points?

Yeah, wes made a good summary of what needs to be updated, isn't much but I won't have time until the 17th. You can tackle that if you feel like it or you can tackle one of the other issues we have open and have the endpoints for.

#126 is a good candidate if you feel like doing one from scratch, I even already have the endpoint mapped on the Postman collection and the most recent PR already builds the fundamentals, like making the proper folders and mapping the base GraphQL URL.

Either option you choose, we will be grateful for your contribution, if you are willing to give us your time. :)

Thanks for the explanation! In this case maybe it'd be easier to start from scratch with a new task. Would that be fine for you? I assume you'll be quicker with finishing this one. And I'd need to spend a while just to familiarise myself with what's done and what's left. :)