cpp help please

Discussion of XBMC4XBOX development.
Post Reply
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

cpp help please

Post by byron »

I am attempting to update our music scrapers by dividing music into the appropriate categories, ie albums and artists (until this point one scraper was used for both...mainline uses one for each). So far I've made good progress splitting them but am stuck now.

Here's the original code for filling the scrapers properly (made for one music scraper)

Code: Select all

void CGUIWindowSettingsCategory::FillInScrapers(CGUISpinControlEx *pControl, const CStdString& strSelected, const CStdString& strContent)
{
  CFileItemList items;
  if (strContent.Equals("music"))
    CDirectory::GetDirectory("special://xbmc/system/scrapers/music",items,".xml",false);
  else
    CDirectory::GetDirectory("special://xbmc/system/scrapers/video",items,".xml",false);
  int j=0;
  int k=0;
  pControl->Clear();
  for ( int i=0;i<items.Size();++i)
  {
    if (items[i]->m_bIsFolder)
      continue;

    CScraperParser parser;
    if (parser.Load(items[i]->GetPath()))
    {
      if (parser.GetContent() != strContent && !strContent.Equals("music"))
        continue;

      if (parser.GetName().Equals(strSelected) || URIUtils::GetFileName(items[i]->GetPath()).Equals(strSelected))
      {
        if (strContent.Equals("music")) // native strContent would be albums or artists but we're using the same scraper for both
        {
          if (g_guiSettings.GetString("musiclibrary.scraper") != strSelected)
          {
            g_guiSettings.SetString("musiclibrary.scraper", URIUtils::GetFileName(items[i]->GetPath()));

            SScraperInfo info;
            CMusicDatabase database;

            info.strPath = g_guiSettings.GetString("musiclibrary.scraper");
            info.strContent = "albums";
            info.strTitle = parser.GetName();

            database.Open();
            database.SetScraperForPath("musicdb://",info);
            database.Close();
          }
        }
        else if (strContent.Equals("movies"))
          g_guiSettings.SetString("scrapers.moviedefault", URIUtils::GetFileName(items[i]->GetPath()));
        else if (strContent.Equals("tvshows"))
          g_guiSettings.SetString("scrapers.tvshowdefault", URIUtils::GetFileName(items[i]->GetPath()));
        else if (strContent.Equals("musicvideos"))
          g_guiSettings.SetString("scrapers.musicvideodefault", URIUtils::GetFileName(items[i]->GetPath()));
        k = j;
      }
      pControl->AddLabel(parser.GetName(),j++);
    }
  }
  pControl->SetValue(k);
}
It's a loop which I don't understand as I'm new to cpp, and wondering If the loop is necessary at this point since I've got music split up...here's what I've done which is only grabbing the album scraper and leaving the other scrapers f.u.b.a.r. (here's the diff of everything I've done)

Here's the specific code that I came up with which is clearly not working

Code: Select all

void CGUIWindowSettingsCategory::FillInScrapers(CGUISpinControlEx *pControl, const CStdString& strSelected, const CStdString& strContent)
{
  CFileItemList items;
  if (strContent.Equals("albums"))
    CDirectory::GetDirectory("special://xbmc/system/scrapers/music/albums",items,".xml",false);
  else if (strContent.Equals("artists"))
    CDirectory::GetDirectory("special://xbmc/system/scrapers/music/artists",items,".xml",false);
  else
    CDirectory::GetDirectory("special://xbmc/system/scrapers/video",items,".xml",false);
  int j=0;
  int k=0;
  pControl->Clear();
  for ( int i=0;i<items.Size();++i)
  {
    if (items[i]->m_bIsFolder)
      continue;

    CScraperParser parser;
    if (parser.Load(items[i]->GetPath()))
    {
      if (strContent.Equals("albums"))
        g_guiSettings.SetString("musiclibrary.albumscraper", URIUtils::GetFileName(items[i]->GetPath()));
	  else if (strContent.Equals("artists"))
        g_guiSettings.SetString("musiclibrary.artistscraper", URIUtils::GetFileName(items[i]->GetPath()));
      

	  else if (strContent.Equals("movies"))
	 	g_guiSettings.SetString("scrapers.moviedefault", URIUtils::GetFileName(items[i]->GetPath()));
	  else if (strContent.Equals("tvshows"))
		g_guiSettings.SetString("scrapers.tvshowdefault", URIUtils::GetFileName(items[i]->GetPath()));
	  else if (strContent.Equals("musicvideos"))
		g_guiSettings.SetString("scrapers.musicvideodefault", URIUtils::GetFileName(items[i]->GetPath()));
	  k = j;
    }

    pControl->AddLabel(parser.GetName(),j++);
    
  }
  pControl->SetValue(k);
} 
I have a couple of other questions but will start here for now, tia for any help...
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: cpp help please

Post by byron »

Not a lot of replies :) I'm still working on this, but have thought up a better way to separate the scrapers (mainline is using one for each, so perhaps it should be done this way for us as well imo). But before I continue with that effort, I have another c++ question regarding grabbing the scrapers from a sub-directory of a root folder ("recursive" is the word for the function I believe).

So here's what I've done, and it shouldn't take too long to finish with a little help (quick fix until we are more congruent with upstream). All of the scrapers for mainline are in metadata."whatever".folders, and I think I've come up with a way to access them by writing a very simple script (default.py) which imports xbmcaddon.module for the settings (just needs a function to start it from SettingsCategory.cpp and ContentSettings.cpp afaik), and I've changed all of the scraper.xml's to default.xml in hopes that I could call them individually from their sub-directories with one function for the spin controlex in music settings. What I have so far is:

ROOT:
xbmc/system/scrapers/music/...


SUBS:
  • common (contains the metadata.common.xmls and should be accessible via <includes>music/common....</includes>)
  • allmusic
    • resources (settings and language are accessible from default.py...not sure yet if settings can be saved)
    • addon.xml
    • default.py
    • default.png
    • default.xml (this is what I'm trying to access)
  • universal music
    • resources
    • addon.xml
    • default.py
    • default.png
    • default.xml (this is musicuniversal.xml renamed for string parsing of sub-directories)
What I would really like to know right now is how to access them by altering this code to grab the default.xml's from each respective folder:

Code: Select all

void CGUIWindowSettingsCategory::FillInScrapers(CGUISpinControlEx *pControl, const CStdString& strSelected, const CStdString& strContent)
{
  CFileItemList items;
  if (strContent.Equals("music"))
    CDirectory::GetDirectory("special://xbmc/system/scrapers/music",items,".xml",false);
I came up with something like

CDirectory::GetDirectory("special://xbmc/system/scrapers/music/",items,"/default.xml",false);

which did pull up Allmusic, but it wouldn't pull up the other one...I'm trying, but it's slow going and could use a little bump in the right direction ;)
User avatar
Dan Dar3
Posts: 1176
Joined: Sun Jul 08, 2012 4:09 pm
Has thanked: 273 times
Been thanked: 257 times
Contact:

Re: cpp help please

Post by Dan Dar3 »

@Byron
I believe Buzz is in holidays and he's probably more focused on doing the whole new infracture from XBMC mainline - I would be interesting in this, but I'm still away in holidays for the next couple of weeks. I'll have a look when I come back if you can continue digging away, it's a slow and painful process, I know :-)
Post Reply