Plugin: MP2Extended (1 Viewer)

FreakyJ

Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    What tool do you use to do this?
    My own source code :D

    Code:
    public ServiceHandlerTemplate()
        {
          foreach (var handler in MainRequestHandler.REQUEST_MODULE_HANDLERS)
          {
            Attribute[] attrs = Attribute.GetCustomAttributes(handler.Value.GetType());
            foreach (Attribute attr in attrs)
            {
              var description = attr as ApiHandlerDescription;
              if (description != null)
              {
                ApiHandlerDescription apiHandlerDescription = description;
                _serviceHandler.Add(handler.Key, apiHandlerDescription);
              }
            }
          }
        }

    And:
    Code:
    public ServiceHandlerFunctionsTemplate(string serviceHandler)
        {
          IRequestModuleHandler module;
          if (MainRequestHandler.REQUEST_MODULE_HANDLERS.TryGetValue(serviceHandler, out module))
          {
            Attribute[] attrs = Attribute.GetCustomAttributes(module.GetType());
            foreach (Attribute attr in attrs)
            {
              var description = attr as ApiHandlerDescription;
              if (description != null)
              {
                ApiHandlerDescription apiHandlerDescription = description;
    
                subHeadLine = apiHandlerDescription.FriendlyName;
              }
            }
    
            var handlerFunctions = module.GetRequestMicroModuleHandlers();
            foreach (var handlerFunction in handlerFunctions)
            {
              var type = handlerFunction.Value.GetType();
    
              FunctionDescription functionDescription = new FunctionDescription
              {
                Name = handlerFunction.Key,
                FriendlyName = handlerFunction.Key,
                Category = type.Namespace.Split('.').Last(),
              };
              Attribute[] attrsFunc = Attribute.GetCustomAttributes(type);
              foreach (Attribute attr in attrsFunc)
              {
                var description = attr as ApiFunctionDescription;
                var param = attr as ApiFunctionParam;
    
                if (description != null)
                {
                  ApiFunctionDescription apiFunctionDescription = description;
    
                  functionDescription.Summary = apiFunctionDescription.Summary;
                  functionDescription.Type = apiFunctionDescription.Type.ToString().ToLower();
                  //functionDescription.ReturnType = apiFunctionDescription.ReturnType.ToString();
                }
               
                if (param != null)
                {
                  functionDescription.Parameters.Add(param);
                }
              }
              if (!_serviceHandlerFunctions.ContainsKey(functionDescription.Category))
                _serviceHandlerFunctions.Add(functionDescription.Category, new List<FunctionDescription>());
              _serviceHandlerFunctions[functionDescription.Category].Add(functionDescription);
            }
          }
        }
     

    MrTechno

    Retired Team Member
  • Premium Supporter
  • February 27, 2011
    1,256
    511
    London
    Home Country
    United Kingdom United Kingdom
    Does it run when MP2 Server starts? As a separate program? Can you check it into the branch?
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    Does it run when MP2 Server starts? As a separate program? Can you check it into the branch?
    It runs on the fly if you call e.g. http://192.168.178.26:26405/MPExtended/DebugAccessService/html/GetApi
    There you can select your service handler, which will bring you to the screenshot shown above. There you can than click on a function and it will expand to give you more information (css for hand courser is still missing^^).

    In the source you will find it under ResourceAccess/Das/Api
    There is GetApi.cs and a folder "Pages" which contain the two pages described above.

    I will commit my wip changes so that you can have a look. Should be pushed within the next 5 min
     

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    @FreakyJ I've pushed some changes to https://github.com/MrTechno/MediaPortal-2/tree/MIA_DLNA_MPExtended it doesn't compile yet but if you diff it against your branch you get an idea of where I'm going with it.
    Hmm, you use VideoAspect.Metadata instead of VideoAspect.ASPECT_ID now. Any reason for that?
    Another change is that you use GetAttributeValue to get the values. Is there a reason for that? I mean it was basically a Dictionary before and it was less writing to just access the dictionary.
    I mean:
    item.Aspects[MediaAspect.ASPECT_ID].GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME)).Year
    vs:
    item[MediaAspect.Metadata].GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME)).Year

    I don't really understand the reason of these changes. Sorry for that. I just would like to understand that :)

    Also this:
    var ImdbId = movieAspects[MovieAspect.ATTR_IMDB_ID];
    vs:
    var ImdbId = MediaItemAspect.GetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_MOVIE);

    Any reason for the change? I gues probably the MIA rework, but there must be some fundamental differences?

    Otherwise you run a resharper code cleanup to remove all the unused references^^

    But the changes to MP2Ext are pretty straight forward, right? Because I moved most Media Library related things to a base class which get accessed over and over again.

    I hope you don't have too much compile errors left :D
     

    MrTechno

    Retired Team Member
  • Premium Supporter
  • February 27, 2011
    1,256
    511
    London
    Home Country
    United Kingdom United Kingdom
    Any reason for the change? I gues probably the MIA rework, but there must be some fundamental differences?
    You guess correctly. The Aspects property of MediaItem has gone from IDictionary<Guid, MediaItemAspect> to IDictionary<Guid, IList<MediaItemAspect>>
    You can still access the dictionary but it's not a MediaItemAspect any more so you'd have to work on the list instead using .First() or some other method to get the object you want.

    VideoAspect.Metadata instead of VideoAspect.ASPECT_ID
    Having a [] operator that returned a MediaItemAspect or null meant writing it in a way that it couldn't accidentally be used to get multiple MIAs. What would you do if there was more than one MIA (runtime exception, return null, return the first and hide the others)? The solution was to use SingleMediaItemAspectMetadata as the parameter type.

    But the changes to MP2Ext are pretty straight forward, right?
    Some of the code is now easier e.g. the Count functions. Some is more difficult e.g. getting episodes for a series is a two level operation (series -> season -> episode).

    I hope you don't have too much compile errors left :D
    107 to go.
     
    Last edited:

    FreakyJ

    Retired Team Member
  • Premium Supporter
  • July 25, 2010
    4,024
    1,420
    Home Country
    Germany Germany
    107 to go.
    Okay still some work to do oO
    Once it is compiling again I will start to implement the missing functions for Pictures and Music :) MP2Ext is on a pretty good way^^

    Great! If you provide a binary, i can test it [emoji1]
    Just saw that TeamCity is failing need to look into the client errors first :whistle:
     

    Users who are viewing this thread


    Write your reply...
    Top Bottom