Trakt for MP2 (3 Viewers)

ge2301

Lead Design MP2
  • Team MediaPortal
  • January 11, 2014
    8,708
    3,491
    Stuttgart
    Home Country
    Germany Germany
    I also have not to add anything, full agreement. Such plugin would be a great feature and because the backup files are stored in program data there is also not risk they are lost in case of uninstall or reinstall of MP2 (y) And my biggest concern would be solved, the user friendly and safe migration from MP2.1.x to MP2.2. I propose to open a new thread for this.
     

    Alberto83

    Portal Pro
    August 7, 2012
    336
    108
    Home Country
    Italy Italy
    And i support this too. The only way i found to transfer watched statuses before this was to start a full trakt sync, but it's not always convenient.
     

    Alberto83

    Portal Pro
    August 7, 2012
    336
    108
    Home Country
    Italy Italy
    Hi @aspik, I made some other tests with your plugin. There's something really wrong either in my watched flags in MePo database or with the plugin. I deleted my MePo profile, and created a new one. All the watch flags were thus gone, i had a complete empty watched flags database. I reauthorized trakt on this profile, and started a full library with my profile on trakt, and it again synced every episode as watched (on trakt), as of today, at 13:13, the time of the initial sync.

    However, i have no watched flags synced back on my collection on MePo. I don't know if it might help you. :)

    PS: i don't know if this might help either, but my entire environment is in EN-US, meaning my dates are mm-dd-yyyy
     
    Last edited:

    Alberto83

    Portal Pro
    August 7, 2012
    336
    108
    Home Country
    Italy Italy
    EDIT: many movies instead have duplicated watch flags.
    (see picture)

    For now I'm gonna disable the plugin, looking forward to test a new version. :)
     

    Attachments

    • Untitled.png
      Untitled.png
      381.3 KB

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    Hi @Alberto83
    thanks for the tests and sorry for the delay, didn't have much time this week...
    There is indeed something wrong with the watched states.

    @henso
    I remember reading you changed something in 2.2 in regard watched states, if not then you probably familiar with this part and maybe you can help.

    To check if a MI is watched I'm reading the ATTR_PLAYCOUNT aspect. To mark a MI as watched I'm doing this and as unwatched this. Now, the problem is that marking the MI as watched increases the playcount. Marking it as unwatched changes only the state in the UI, but the playcount is still as it was before which returns true in the IsWatched method.

    Is this the correct way to retrieve/manipulate the watched states of a MI from within the client?
     

    henso

    Development Group
  • Team MediaPortal
  • February 16, 2012
    2,341
    829
    Home Country
    Denmark Denmark
    ATTR_PLAYCOUNT
    That property is used as a global play count across users.

    You need to use the users play count. It is found in the user data for the media item. Look for usage of the UserDataKeysKnown.KEY_PLAY_COUNT key. If the key does not exist then the user hasn’t played the media yet.
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    Look for usage of the UserDataKeysKnown.KEY_PLAY_COUNT key.
    Understood. Thanks for this. Unfortunately this still doesn't solve my problem with marking an MI as unwatched. The KEY_PLAY_COUNT is still the same after processing an MI with my unwatched Method.
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    Debug the SetUnwatchedAction and check if it gets to the SetUserMediaItemData part.
    I did this and the SetUnwatchedAction gets the UserMedia data, but I'm still not sure if this helps me to determine if a MI was watched or not.

    This ProcessAsync method gets called from my MarkAsWatched/MarkAsUnwatched methods, as well as when invoking the set played and set unplayed actions from the client UI. So, I tested it without trakt, just by applying the MP2 UI actions. The PlayCount from the UserData property is still unchanged when using the UI actions.

    Looking at the ProcessAsync method shows, that it can't change the play count, because it's missing in the argument list of the NotifyUserPlaybackAsync method:
    C#:
    if (userProfile.HasValue)
    {
      await cd.NotifyUserPlaybackAsync(userProfile.Value, mediaItem.MediaItemId, playPercentage, watched);
    }

    I think this method needs to be extended by a playCount, something like this:
    C#:
    public async Task NotifyUserPlaybackAsync(Guid userId, Guid mediaItemId, int percentage, int playCount, bool updatePlayDate = true)
    {
      CpAction action = GetAction("X_MediaPortal_NotifyUserPlayback");
      IList<object> inParameters = new List<object>
      {
        MarshallingHelper.SerializeGuid(userId),
        MarshallingHelper.SerializeGuid(mediaItemId),
        percentage,
        playCount,
        updatePlayDate
      };
      await action.InvokeAsync(inParameters);
    }
    and in the UPnPContentDirectoryServiceImpl
    C#:
    DvAction mpnp11NotifyUserPlaybackAction = new DvAction("X_MediaPortal_NotifyUserPlayback", OnMPnP11NotifyUserPlayback,
        new DvArgument[] {
          new DvArgument("UserProfile", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          new DvArgument("MediaItemId", A_ARG_TYPE_Uuid, ArgumentDirection.In),
          new DvArgument("Percentage", A_ARG_TYPE_Integer, ArgumentDirection.In),
          new DvArgument("PlayCount", A_ARG_TYPE_Integer, ArgumentDirection.In),
          new DvArgument("UpdatePlayDate", A_ARG_TYPE_Bool, ArgumentDirection.In),
    
        },
    What do you think?
     

    henso

    Development Group
  • Team MediaPortal
  • February 16, 2012
    2,341
    829
    Home Country
    Denmark Denmark
    What do you think?
    We can't presume that all clients always have an updated play count, so the play count is handled server side here. The same user could be logged in on multiple clients and then his play count could be updated incorrectly.
    My guess is you are not reloading the user data after changing the play count? If not then the user data on the client will not be changed before next time it is loaded.
    As you can see there is a little "cheat" for KEY_PLAY_PERCENTAGE to avoid reloading the user data by just changing the values in the already loaded user data. This will not be saved to the database though. The NotifyUserPlayback handles this. Could you not just add the following line:
    C#:
    mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT] = watched ? 1 : 0;
    If you need a more correct value you could also just increment the current value by 1 if watched. If you need the current "real" value, you need to reload the user data from the database.
     

    Users who are viewing this thread

    Top Bottom