OnlineVideos JSON parsing | Page 3

Discussion in 'OnlineVideos' started by howudodat, December 6, 2015.

  1. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,803
    Likes Received:
    757
    Location:
    Nuenen
    Ratings:
    +1,122 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
    this:
    Code (Text):
    1.  
    2. <Site name="DailyMotion" util="DailyMotion" agecheck="false" enabled="true" lang="en">
    3.   <Description>Dailymotion is a video sharing service website, based in Paris (France).</Description>
    4. </Site>
    5.  
    is an example of the bare minimum.
    Of course you can add as many (predefined like baseUrl) properties you like if you don't want to hardcode them


     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. howudodat

    howudodat Portal Pro

    Joined:
    February 20, 2007
    Messages:
    75
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    United States of America United States of America
    ok I must be missing a few more pieces of glue.
    I have created my project and it has a single function for the moment: DiscoverDynamicCategories. It is in the path: OnlineVideos.Sites.pcarlson.mytv
    Code (Text):
    1. namespace OnlineVideos.Sites.pcarlson
    2. {
    3.     public class MYTV : OnlineVideos.Sites.GenericSiteUtil
    4.     {
    5.         public override int DiscoverDynamicCategories()
    6.         {
    7.             Settings.Categories.Clear();
    8.             Settings.Categories.Add(new Category()
    9.             {
    10.                 Name = "Test1",
    11.                 Description = "Test Description"
    12.             });
    13.             Settings.DynamicCategoriesDiscovered = Settings.Categories.Count > 0;
    14.             return Settings.Categories.Count;
    15.         }
    16.  
    17.     }
    18. }
    I added the site to OnlineVideoSites.xml
    Code (Text):
    1. <Site name="MyTV Test" util="MYTV" agecheck="false" enabled="true" lang="en">
    2.       <Description>Just testing</Description>
    3.     </Site>
    When I debug the dll (launch external program mediaportal.exe) my site doesn't show up anywhere. So I launch MP config, and config the plugin and add the site manually. I'm sure that's not the right way. The site shows up in MP when I go to manage sites, but doesn't show up under category English.

    I'm sure I'm just missing a simple step.
     
  4. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,803
    Likes Received:
    757
    Location:
    Nuenen
    Ratings:
    +1,122 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
    The name of the class should be MYTVUtil, then it should work.
    This should be present somewhere in the logfiles (perhaps not as clear as to give the solution) though
     
  5. howudodat

    howudodat Portal Pro

    Joined:
    February 20, 2007
    Messages:
    75
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    United States of America United States of America
    And what's the purpose of the entry in the xml? I dont find this xml file in the MP installation folders anywhere.
     
  6. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,803
    Likes Received:
    757
    Location:
    Nuenen
    Ratings:
    +1,122 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
  7. howudodat

    howudodat Portal Pro

    Joined:
    February 20, 2007
    Messages:
    75
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    United States of America United States of America
    ok, this is really painful. The only way I can get this to work is: build the dll, rename the dll prefixing the built dll with OnlineVideos.Sites.pcarlson, and then copy the dll to the installed MP folder. Then switch back to visual studio and debug. There has got to be an easier way (using MP).

    I also built a simple test console application, but I must be missing calling some initialize functions as Settings is null.

    BTW it appears that the XML is not used in a running MP installation. Even after adding my site manually in MP, there is no XML file. It probably stores that in one of the DBs.
     
  8. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,803
    Likes Received:
    757
    Location:
    Nuenen
    Ratings:
    +1,122 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
    It definitely should be present (the xml, it's located in the C:\ProgramData\Team MediaPortal\MediaPortal folder).

    Did you add your project to the onlinevideos solution? That should do the copying (and probably some other magic).

    Here's a sample from my standalone test-program:
    Code (Text):
    1.  
    2.   static SiteSettings InitStuff(string name)
    3.   {
    4.   using (FileStream fs = new FileStream(@"C:\ProgramData\Team MediaPortal\MediaPortal\OnlineVideoSites.xml", FileMode.Open, FileAccess.Read))
    5.   {
    6.   XmlSerializer ser = new XmlSerializer(typeof(SerializableSettings));
    7.   SerializableSettings s = (SerializableSettings)ser.Deserialize(fs);
    8.   fs.Close();
    9.  
    10.   foreach (SiteSettings tmp in s.Sites)
    11.   {
    12.   if (tmp.Name == name)
    13.   return tmp;
    14.   }
    15.   return null;
    16.   }
    17.   }
    18.  
    19.   static void testUitzendinggemist()
    20.   {
    21.  
    22.   SiteSettings siteSettings = InitStuff("Uitzending Gemist");
    23.   List<VideoInfo> v;
    24.   UitzendingGemistUtil site = new UitzendingGemistUtil();
    25.   site.Initialize(siteSettings);
    26.   site.DiscoverDynamicCategories();
    27. }
    28.  
    29.  
     
  9. howudodat

    howudodat Portal Pro

    Joined:
    February 20, 2007
    Messages:
    75
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    United States of America United States of America
    ok, I am getting further along. I can get the main categories (and add my static category for language) but when I select one of the categories, I get "No videos" error message in MP.
    I have confirmed that Settings.Categories[category].SubCategories contains the sub categories (12 are found) and that HasSubCategories is true
    Code (Text):
    1.         public override int DiscoverDynamicCategories()
    2.         {
    3.             Settings.Categories.Clear();
    4.  
    5.             JObject jo = GetWebData<JObject>(sBaseUrl + sLanguage);
    6.             JArray jo2 = (JArray)jo["categories"];
    7.             foreach (JObject jEntry in jo2)
    8.             {
    9.                 JArray jTags = jEntry.Value<JArray>("tags");
    10.                 bool bAdd = true;
    11.                 foreach (string sEntry in jTags)
    12.                 {
    13.                     if (sEntry.Equals("WebExclude"))
    14.                     {
    15.                         bAdd = false;
    16.                         break;
    17.                     }
    18.                 }
    19.                 if (bAdd)
    20.                 {
    21.                     Category cat = new Category();
    22.                     cat.Name = jEntry.Value<string>("name");
    23.                     cat.Description = jEntry.Value<string>("description");
    24.                     cat.Other = jEntry.Value<string>("key");
    25.                     Settings.Categories.Add(cat);
    26.                 }
    27.  
    28.  
    29.             }
    30.             Settings.Categories.Add(new Category()
    31.             {
    32.                 Name = "Language",
    33.                 Description = "Change Language"
    34.             });
    35.             Settings.DynamicCategoriesDiscovered = Settings.Categories.Count > 0;
    36.             return Settings.Categories.Count;
    37.         }
    38.         public override int DiscoverSubCategories(Category parentCategory)
    39.         {
    40.             JObject jo = GetWebData<JObject>(sBaseUrl + sLanguage + "/" + parentCategory.Other + "?&detailed=1");
    41.             JObject jo1 = (JObject)jo["category"];
    42.             if (jo1["subcategories"].HasValues)
    43.             {
    44.                 List<Category> cats = new List<Category>();
    45.                 JArray jEntries = (JArray)jo1["subcategories"];
    46.                 foreach (JObject jEntry in jEntries)
    47.                 {
    48.                     bool bAdd = true;
    49.                     if (bAdd)
    50.                     {
    51.                         Category cat = new Category();
    52.                         cat.Name = jEntry.Value<string>("name");
    53.                         cat.Description = jEntry.Value<string>("description");
    54.                         cat.Other = jEntry.Value<string>("key");
    55.                         cat.ParentCategory = parentCategory;
    56.                         cats.Add(cat);
    57.                     }
    58.                 }
    59.                 parentCategory.HasSubCategories = true;
    60.                 parentCategory.SubCategories = cats;
    61.                 parentCategory.SubCategoriesDiscovered = true;
    62.             }
    63.             return parentCategory.SubCategories.Count;
    64.         }
    65.     }
    PS. I know I have some superfluous code (unneeded variables, but they are there for debugging)
     
  10. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,803
    Likes Received:
    757
    Location:
    Nuenen
    Ratings:
    +1,122 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
    Nice to hear your getting further (albeit slow/small steps...)
    The thing you have to do is set HasSubcategories to true for (sub)categories which have subs...
     
  11. howudodat

    howudodat Portal Pro

    Joined:
    February 20, 2007
    Messages:
    75
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    United States of America United States of America
    For the first level, I do set HasSubCategories (not shown in the code above), however if I dont know if a category has sub categories until it is parsed how do I handle that? ie:
    Code (Text):
    1. Films -> [Action / Drama] -> Film Name  ( this has only one level of sub category so Films.HasSubCategories == true, but Films.Action.HasSubCategories == false)
    2. Music Videos -> [Country / Pop] ->
    3.      Country -> <list of videos>    (this has only one level of sub category so MV.Country.HasSubCategories == false)
    4.      Pop ->  [Indy Pop / 80s Pop] -> List of videos  (this has a 2nd level of sub category so MV.Pop.HasSubCategories == true)
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!