OnlineVideos JSON parsing (1 Viewer)

doskabouter

Development Group
  • Team MediaPortal
  • September 27, 2009
    3,524
    1,724
    Nuenen
    Netherlands Netherlands
    Country flag
    this:
    Code:
    <Site name="DailyMotion" util="DailyMotion" agecheck="false" enabled="true" lang="en"> 
      <Description>Dailymotion is a video sharing service website, based in Paris (France).</Description> 
    </Site>
    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
     

    howudodat

    Portal Pro
    February 20, 2007
    75
    2
    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:
    namespace OnlineVideos.Sites.pcarlson
    {
        public class MYTV : OnlineVideos.Sites.GenericSiteUtil
        {
            public override int DiscoverDynamicCategories()
            {
                Settings.Categories.Clear();
                Settings.Categories.Add(new Category()
                {
                    Name = "Test1",
                    Description = "Test Description"
                });
                Settings.DynamicCategoriesDiscovered = Settings.Categories.Count > 0;
                return Settings.Categories.Count;
            }
    
        }
    }
    I added the site to OnlineVideoSites.xml
    Code:
    <Site name="MyTV Test" util="MYTV" agecheck="false" enabled="true" lang="en">
          <Description>Just testing</Description>
        </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.
     

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    3,524
    1,724
    Nuenen
    Netherlands Netherlands
    Country flag
    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
     

    howudodat

    Portal Pro
    February 20, 2007
    75
    2
    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.
     

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    3,524
    1,724
    Nuenen
    Netherlands Netherlands
    Country flag

    howudodat

    Portal Pro
    February 20, 2007
    75
    2
    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.
     

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    3,524
    1,724
    Nuenen
    Netherlands Netherlands
    Country flag
    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:
      static SiteSettings InitStuff(string name)
      {
      using (FileStream fs = new FileStream(@"C:\ProgramData\Team MediaPortal\MediaPortal\OnlineVideoSites.xml", FileMode.Open, FileAccess.Read))
      {
      XmlSerializer ser = new XmlSerializer(typeof(SerializableSettings));
      SerializableSettings s = (SerializableSettings)ser.Deserialize(fs);
      fs.Close();
    
      foreach (SiteSettings tmp in s.Sites)
      {
      if (tmp.Name == name)
      return tmp;
      }
      return null;
      }
      }
    
      static void testUitzendinggemist()
      {
    
      SiteSettings siteSettings = InitStuff("Uitzending Gemist");
      List<VideoInfo> v;
      UitzendingGemistUtil site = new UitzendingGemistUtil();
      site.Initialize(siteSettings);
      site.DiscoverDynamicCategories();
    }
     

    howudodat

    Portal Pro
    February 20, 2007
    75
    2
    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:
            public override int DiscoverDynamicCategories()
            {
                Settings.Categories.Clear();
    
                JObject jo = GetWebData<JObject>(sBaseUrl + sLanguage);
                JArray jo2 = (JArray)jo["categories"];
                foreach (JObject jEntry in jo2)
                {
                    JArray jTags = jEntry.Value<JArray>("tags");
                    bool bAdd = true;
                    foreach (string sEntry in jTags)
                    {
                        if (sEntry.Equals("WebExclude"))
                        {
                            bAdd = false;
                            break;
                        }
                    }
                    if (bAdd)
                    {
                        Category cat = new Category();
                        cat.Name = jEntry.Value<string>("name");
                        cat.Description = jEntry.Value<string>("description");
                        cat.Other = jEntry.Value<string>("key");
                        Settings.Categories.Add(cat);
                    }
    
    
                }
                Settings.Categories.Add(new Category()
                {
                    Name = "Language",
                    Description = "Change Language"
                });
                Settings.DynamicCategoriesDiscovered = Settings.Categories.Count > 0;
                return Settings.Categories.Count;
            }
            public override int DiscoverSubCategories(Category parentCategory)
            {
                JObject jo = GetWebData<JObject>(sBaseUrl + sLanguage + "/" + parentCategory.Other + "?&detailed=1");
                JObject jo1 = (JObject)jo["category"];
                if (jo1["subcategories"].HasValues)
                {
                    List<Category> cats = new List<Category>();
                    JArray jEntries = (JArray)jo1["subcategories"];
                    foreach (JObject jEntry in jEntries)
                    {
                        bool bAdd = true;
                        if (bAdd)
                        {
                            Category cat = new Category();
                            cat.Name = jEntry.Value<string>("name");
                            cat.Description = jEntry.Value<string>("description");
                            cat.Other = jEntry.Value<string>("key");
                            cat.ParentCategory = parentCategory;
                            cats.Add(cat);
                        }
                    }
                    parentCategory.HasSubCategories = true;
                    parentCategory.SubCategories = cats;
                    parentCategory.SubCategoriesDiscovered = true;
                }
                return parentCategory.SubCategories.Count;
            }
        }
    PS. I know I have some superfluous code (unneeded variables, but they are there for debugging)
     

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    3,524
    1,724
    Nuenen
    Netherlands Netherlands
    Country flag
    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...
     

    howudodat

    Portal Pro
    February 20, 2007
    75
    2
    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:
    Films -> [Action / Drama] -> Film Name  ( this has only one level of sub category so Films.HasSubCategories == true, but Films.Action.HasSubCategories == false)
    Music Videos -> [Country / Pop] ->
         Country -> <list of videos>    (this has only one level of sub category so MV.Country.HasSubCategories == false)
         Pop ->  [Indy Pop / 80s Pop] -> List of videos  (this has a 2nd level of sub category so MV.Pop.HasSubCategories == true)
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    Top Bottom