Trakt for MP2 (20 Viewers)

aspik

Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    I have started to try to port the MP1 version to MP2. Don't know if I will be able to finish it, but at least I will try it:D As I don't really had any idea how to start, I simply replaced the current TraktAPI class in MP2 with the MP1 version from ltfearme. From there I go on every error (missing DataStructures, missing URIs, etc..) and fix it (read: copy from MP1 version) with adding/adjusting the missing/changed classes/methods...
    @morpheus_xx
    Do you think it is the right approach? Maybe you have a better idea, besides creating a Nuget package. If you still want to create a Nuget package, then I think we will have to wait until ltfearme find some time to do it. In this case, I'll stop with my attempt to port Trakt to MP2.
     

    ltfearme

    Community Plugin Dev
  • Premium Supporter
  • June 10, 2007
    6,760
    7,224
    Sydney
    Home Country
    Australia Australia
    Sorry I haven't had much time to allocate to this guys.

    One thing I haven't added in the MP1 project is the new authentication method needed for new projects connecting to the trakt API, however I did implement this for TraktRater which is another application I wrote.

    The plan is to port the new authentication method to MP1 as well at some point, the workflow in the GUI (MP1/MP2) would be to show a dialog with the QR Code picture, the user can then get their mobile device out, scan the picture and permit the application to use the API, then user will input code in MP GUI (that's a one time deal).
     
    Last edited:

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,070
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #73
    I have started to try to port the MP1 version to MP2. Don't know if I will be able to finish it, but at least I will try it:D As I don't really had any idea how to start, I simply replaced the current TraktAPI class in MP2 with the MP1 version from ltfearme. From there I go on every error (missing DataStructures, missing URIs, etc..) and fix it (read: copy from MP1 version) with adding/adjusting the missing/changed classes/methods...
    First things to notice are the existings code parts in MP2:
    I remember that I modified the sources of the copy in MP2 a bit, mainly cleanups for code guidelines and small refactorings: https://github.com/MediaPortal/Medi...ataExtractors/OnlineLibraries/Libraries/Trakt.

    I'm not sure how to proceed with this. If we now copy over the changes from MP1 based project again, we will end with two different versions (like we already have). That's why I'd prefer to have a nuget package which contains a common API library, that we could include in the MP2 specific client plugin.
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    First things to notice are the existings code parts in MP2:
    Yes, I know the places; I already spent few hours by trying to figure out how Trakt is integrated in MP2.
    I'm not sure how to proceed with this. If we now copy over the changes from MP1 based project again, we will end with two different versions (like we already have). That's why I'd prefer to have a nuget package which contains a common API library, that we could include in the MP2 specific client plugin.

    I completely agree with you, that a common API library would be the best solution. But I think building a nuget package from the current Trakt version for MP1 would be not the cleanest way, as it includes i.e. GUI parts for MP1. I think the best way, would be to create a generic library (nuget package) without any specific logic for MP1 or MP2. This nuget package can be then included in MP1 and MP2 in where the specific logic (like from where scrobble the data), GUI, etc. can be added.

    But, this would mean, that the current version for MP1 had to be adjusted too… I’m not sure if ltfearme is up for it…
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    So, how do we proceed here? Should I continue with my attempt to port it to MP2? Where we, as you said, end up with two different version.
    @ltfearme
    Can you imagine to remove the MP1 stuff from the current version, so that in the official trakt repo only the common logic is placed? I think, this would be a good step in the future of Trakt for MP :) Unless you are in a switch to MP2 (someday) not interested and plan to stay only with MP1?
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    As I don't know, if I'm on the right path, I'll post what I've done so far.
    After replacing the whole content of the MP2 TraktAPI class with the Trakt for MP1 content, I've copied/fixed the new/existing DataStructures, so that the MP2 TraktAPI class doesn’t contained any errors.

    Next I've started to fix syncing of movies. In the SyncMovies method:
    https://github.com/MediaPortal/Medi...ncubator/Trakt/Models/TraktSetupModel.cs#L211
    I've adjusted the sync logic according to the new API (this was taken from MovingPictures class). As a next step I wanted to go to the SyncSeries method:
    https://github.com/MediaPortal/Medi...ncubator/Trakt/Models/TraktSetupModel.cs#L250
    and do the same for series. But, before I'll try this, I have couple questions.

    I think that to get the current version of Trakt working is not a matter of changing the login process, but the whole API has to be adjusted, as it changed since the first implementation.

    First, there is now cache, which I suppose has to be done before do i.e syncing to Trakt? The cache in Trakt for MP1:
    https://github.com/trakt/Trakt-for-...1838ed28d4dcdc0a276/TraktPlugin/TraktCache.cs
    The logic can be ported, but the paths to the files, need to be adjusted as this is MP1 specific. How should these paths look in MP2?

    Logging in Trakt for MP1 is in a separate class TraktLogger. Is this class needed in MP2, or should the logging be done with the internal logger: ServiceRegistration.Get<ILogger>().Info… ?

    Trakt settings changed. MP1 version:
    https://github.com/trakt/Trakt-for-...438a1cea397e36b4/TraktPlugin/TraktSettings.cs
    MP2 version:
    https://github.com/MediaPortal/Medi...ineLibraries/Libraries/Trakt/TraktSettings.cs
    Additional the place where it is currently placed in MP2 interfere with MP2 Trakt settings:
    https://github.com/MediaPortal/Medi...tal/Incubator/Trakt/Settings/TraktSettings.cs
    I.e. to reach the Methods from Trakt settings (not MP2 Trakt settings), I have to wrote the whole namespace path:
    Extensions.OnlineLibraries.Libraries.Trakt.TraktSettings.SyncBatchSize;

    I suppose the method TestAccount:
    https://github.com/MediaPortal/Medi...ncubator/Trakt/Models/TraktSetupModel.cs#L171
    is the old log-in method as the new API doesn’t contains the TestAccount() method? So, to new log-in process has to be done here?

    The last thing is scrobbling, which in MP2 is in the TraktHandler class:
    https://github.com/MediaPortal/Medi...ortal/Incubator/Trakt/Service/TraktHandler.cs
    right?

    @morpheus_xx
    Can you please take a look at the attached 'patch' and review the changes I've made so far? Especially at the TraktCache, TraktSettings classes and check if they are in the right place, if not the correct this?

    Obviously the project doesn’t build, because syncing series (TraktSetupModel) and scrobbling (TraktHandler) has to be fixed.
    Additionally I've errors in the LoginModel class:
    https://github.com/MediaPortal/Medi...87f/MediaPortal/Incubator/Login/LoginModel.cs
    because of missing the MediaPortal.UI.UserManagement namesapce. I don't know how this has something to do with Trakt?

    Thank you!
     

    Attachments

    • trakt_for_MP2.diff
      272.9 KB

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,070
    7,459
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #77
    Thanks @aspik (y)

    A full answer will require more time, but I want to let you know that I've read it.

    I have some small requests:
    • Can you please install the VS extension "EditorConfig". It should take care to apply the MP rules for spaces. This will save a lot of differences due to 4/2 space indentation
    • Then please create a new patch

    Additionally I've errors in the LoginModel class
    This project is out of date and does not compile. Usually it is disabled for build in both DEBUG and RELEASE configs. No need to worry about errors there.

    Logging in Trakt for MP1 is in a separate class TraktLogger. Is this class needed in MP2, or should the logging be done with the internal logger: ServiceRegistration.Get<ILogger>().Info… ?
    To keep the changes inside all other classes at a minimum, we could have an "own" implementation of TraktLogger with same public interface, but forwarding logging to the ILogger from ServiceRegistration.

    The other points need some more time to check...
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    Sorry for the space indentation difference, I’ve changed the settings (from 4 to 2 spaces) in VS to late… When I get home I will install the editorconfig extension and generate a new patch. Should I have set something else in TortoiseGIT, so that you later don’t have problems while importing the patch (like in my previous patch:D)?
     

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    I've allowed myself to install ReSharper and apply the team license, hopefully you don't mind..? :rolleyes: After that I've imported the TeamMediaPortal .DotSettings and run cleanup code with this profile.
    EditorConfig also installed. Attached patch created with TortoiseGit. If you need something else, please let me know!
     

    Attachments

    • trakt_for_MP2_v2.diff
      254.8 KB

    aspik

    Retired Team Member
  • Team MediaPortal
  • April 14, 2008
    1,322
    586
    Hello everyone,

    I've just pushed to my repo a first working version:
    https://github.com/aspik/MediaPortal-2/commit/334f8ad0be3a48aeedaa511715acb7cf80e470f5
    It is now possible to sync the movie and series library. Scrobbling for movies and series is working too.
    @morpheus_xx
    Can you please review it? Thanks! :)

    What is working:
    TraktLogger:
    as morpheus_xx suggested I've modified it, so that it uses the MP2 Logger.

    TraktSettings:
    the plugin uses now the MP2 settings located in:
    c:\ProgramData\Team MediaPortal\MP2-Client\Config\user\MediaPortal.UiComponents.Trakt.Settings.TraktSettings.xml

    TraktCache:
    is saved in the MP2-Client user data directory:
    c:\ProgramData\Team MediaPortal\MP2-Client\Trakt\user\Library\

    Need to be fixed:

    Audio Channels:
    I was not able to get the audio channels from the Transcoding Service. Here I need some help how can I do it. But, as all the needed information is already provided by the MediaInfo.dll, maybe can the VideoAspect be extended by my patch? Unless the transcoding service gets into the MP2 core?

    Password:
    The password is saved in the settings XML as plain text In the MP1 Trakt version there is an encrypt and decrypt method:
    https://github.com/trakt/Trakt-for-...ktPlugin/Extensions/SecurityExtensions.cs#L14
    @morpheus_xx
    Should I use it, or maybe is something similar already available in MP2?

    API Key:
    The API key I received from Trakt is not working. The plugin is only working with the API key from MP1 Trakt.
    @ltfearme
    Can you please give me a hint what I'm doing wrong? I've created an app at trakt.tv (see screenshot). Unfortunately I can't use it, every time I try to sync to trakt, I get the following error:
    Code:
    Trakt.tv: Protocol Error, Code = '401', Description = 'Unauthorized', Url = 'http://api-v2launch.trakt.tv/sync/last_activities', Headers = 'Transfer-Encoding: chunked, Connection: keep-alive, Pragma: no-cache, Vary: Accept-Encoding, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-Request-Id: 2895a406-41e6-4d62-8946-e21b95a5256b, X-Runtime: 0.005330, X-XSS-Protection: 1; mode=block, CF-RAY: 2495bf8dac7f2d65-TXL, Cache-Control: max-age=0, private, no-cache, no-store, must-revalidate, Content-Type: text/html, Date: Sun, 22 Nov 2015 15:43:08 GMT, Set-Cookie: __cfduid=d41c58ff3f23283ba29aafe397de8b0fb1448206988; expires=Mon, 21-Nov-16 15:43:08 GMT; path=/; domain=.trakt.tv; HttpOnly, Server: cloudflare-nginx, WWW-Authenticate: Bearer realm="Doorkeeper", error="invalid_token", error_description="The access token is invalid"'
    If I changed it to your API, everything is working fine.

    What's next:
    I would like to port the rest features of the MP1 version to MP2.

    Sync Progress:
    @morpheus_xx
    Is it possible to write back the watched progress in MP2 ML? For example, I've started watching a movie on MP1 (or any other device where it is possible to log into trakt), but I didn't watch it till the end. After stopping the movie MP1 syncs the watched progress to trakt. Then, when I start watching the movie on MP2 it would sync back from trakt the watched status and play it from that position.

    Ratings:
    Does MP2 have the ability to store user ratings? If not, can it be maybe added in future?

    GUI screens:
    Trakt for MP1 has a lot of GUI screens like trendig movies, calendar, etc:
    https://forum.team-mediaportal.com/threads/5-6-1-trakt-for-mediaportal-2015-11-07.97807/
    I would like to port/add as much as possible of those screens in MP2. To provide the same set of Trakt features in MP2 as it already is in MP1.
    @ge2301
    Are you interested in designing those screens? :)
     

    Attachments

    • API.JPG
      API.JPG
      80.9 KB

    Users who are viewing this thread

    Top Bottom