bool CGUIDialogContentSettings::OnMessage(CGUIMessage &message)
{
  switch (message.GetMessage())
  {
  case GUI_MSG_WINDOW_DEINIT:
    {
      m_scrapers.clear();
      m_vecItems->Clear();
      CGUIDialogSettings::OnMessage(message);
    }
    break;

  case GUI_MSG_ITEM_SELECT:
    {
      if (message.GetControlId() == CONTROL_SCRAPER_LIST)
      {
        if (!m_info.strContent.IsEmpty())
          m_info = m_scrapers[m_info.strContent][message.GetParam1()];
      }
    }
    break;

  case GUI_MSG_CLICKED:
    int iControl = message.GetSenderId();
    if (iControl == 500)
      Close();
    if (iControl == 501)
    {
      m_bNeedSave = false;
      Close();
    }

    if (iControl == CONTROL_CONTENT_TYPE)
    {
      CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_CONTENT_TYPE);
      m_gWindowManager.SendMessage(msg);
      int iSelected = msg.GetParam1();

      m_bNeedSave = true;
      CStdString strLabel;
      switch (iSelected)
      {
      case 0: m_info.strContent.Empty();
              m_info.strPath.Empty();
              m_info.strThumb.Empty();
              m_info.strTitle.Empty();
              OnSettingChanged(0);
              SetupPage();
              break;
      case 1: strLabel = g_localizeStrings.Get(20342);
              m_info = FindDefault("movies", g_guiSettings.GetString("scrapers.moviedefault"));
              CreateSettings();
              SetupPage();
              break;
      case 2: strLabel = g_localizeStrings.Get(20343);
              m_info = FindDefault("tvshows", g_guiSettings.GetString("scrapers.tvshowdefault"));
              CreateSettings();
              SetupPage();
              break;
      case 3: strLabel = g_localizeStrings.Get(20389);
              m_info = FindDefault("musicvideos", g_guiSettings.GetString("scrapers.musicvideodefault"));
              CreateSettings();
              SetupPage();
              break;
      case 4: strLabel = g_localizeStrings.Get(132);
              m_info = FindDefault("albums", g_guiSettings.GetString("musiclibrary.defaultscraper"));
              CreateSettings();
              SetupPage();
              break;
      }
    }
    if (iControl == CONTROL_SCRAPER_LIST)
    {
      CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_SCRAPER_LIST);
      m_gWindowManager.SendMessage(msg);
      int iSelected = msg.GetParam1();

      m_info = m_scrapers[m_info.strContent][iSelected];
      FillListControl();
      SET_CONTROL_FOCUS(30,0);
    }
    if (iControl == CONTROL_SCRAPER_SETTINGS)
    {
      if (m_info.settings.LoadSettingsXML("special://xbmc/system/scrapers/video/"+m_info.strPath))
      {
        CGUIDialogPluginSettings::ShowAndGetInput(m_info);
        m_bNeedSave = true;
        return true;
      }
      return false;
    }
    CScraperParser parser;
    CStdString strPath;
    if (!m_info.strContent.IsEmpty())
      strPath="special://xbmc/system/scrapers/video/"+m_info.strPath;
    if (!strPath.IsEmpty() && parser.Load(strPath) && parser.HasFunction("GetSettings"))
      CONTROL_ENABLE(CONTROL_SCRAPER_SETTINGS);
    else
      CONTROL_DISABLE(CONTROL_SCRAPER_SETTINGS);
    break;
  }
  return CGUIDialogSettings::OnMessage(message);
}
void CGUIDialogContentSettings::OnWindowLoaded()
{
  CGUIDialogSettings::OnWindowLoaded();

  CFileItemList items;
  if (m_info.strContent.Equals("albums"))
    CDirectory::GetDirectory("special://xbmc/system/scrapers/music/",items,".xml",false);
  else
    CDirectory::GetDirectory("special://xbmc/system/scrapers/video/",items,".xml",false);
  for (int i=0;i<items.Size();++i)
  {
    if (!items[i]->m_bIsFolder)
    {
      TiXmlDocument doc;
      doc.LoadFile(items[i]->m_strPath);
      if (doc.RootElement())
      {
        bool IsDefaultScraper = false;
        const char* content = doc.RootElement()->Attribute("content");
        const char* name = doc.RootElement()->Attribute("name");
        const char* thumb = doc.RootElement()->Attribute("thumb");
        if (content && name)
        {
          SScraperInfo info;
          info.strTitle = name;
          info.strPath = CUtil::GetFileName(items[i]->m_strPath);
          if (thumb)
            info.strThumb = thumb;
          info.strContent = content;
          info.settings = m_scraperSettings;

          if ( info.strPath == g_guiSettings.GetString("musiclibrary.defaultscraper")
            || info.strPath == g_guiSettings.GetString("scrapers.moviedefault")
            || info.strPath == g_guiSettings.GetString("scrapers.tvshowdefault")
            || info.strPath == g_guiSettings.GetString("scrapers.musicvideodefault"))
          {
             IsDefaultScraper = true;
          }

          map<CStdString,vector<SScraperInfo> >::iterator iter=m_scrapers.find(content);
          if (iter != m_scrapers.end())
          {
            if (IsDefaultScraper)
              iter->second.insert(iter->second.begin(),info);
            else
              iter->second.push_back(info);
          }
          else
          {
            vector<SScraperInfo> vec;
            vec.push_back(info);
            m_scrapers.insert(make_pair(content,vec));
          }
        }
      }
    }
  }

  // now select the correct scraper
  if (!m_info.strContent.IsEmpty())
  {
    map<CStdString,vector<SScraperInfo> >::iterator iter = m_scrapers.find(m_info.strContent);
    if (iter != m_scrapers.end())
    {
      for (vector<SScraperInfo>::iterator iter2 = iter->second.begin();iter2 != iter->second.end();++iter2)
      {
        if (iter2->strPath == m_info.strPath)
        {
          m_info = *iter2;
          break;
        }
      }
    }
  }

  CScraperParser parser;
  CStdString strPath;
  if (!m_info.strContent.IsEmpty())
    strPath="special://xbmc/system/scrapers/video/"+m_info.strPath;
  if (!strPath.IsEmpty() && parser.Load(strPath) && parser.HasFunction("GetSettings"))
    CONTROL_ENABLE(CONTROL_SCRAPER_SETTINGS);
  else
    CONTROL_DISABLE(CONTROL_SCRAPER_SETTINGS);
}
예제 #3
0
bool CMusicArtistInfo::Load(CHTTP& http, const SScraperInfo& info, const CStdString& strFunction, const CScraperUrl* url)
{
  // load our scraper xml
  CScraperParser parser;
  if (!parser.Load(_P("q:\\system\\scrapers\\music\\"+info.strPath)))
    return false;

  bool bChained=true;
  if (!url)
  {
    bChained=false;
    url = &GetArtistURL();
  }

  std::vector<CStdString> strHTML;
  for (unsigned int i=0;i<url->m_url.size();++i)
  {
    CStdString strCurrHTML;
    if (!CScraperUrl::Get(url->m_url[i],strCurrHTML,http) || strCurrHTML.size() == 0)
      return false;
    strHTML.push_back(strCurrHTML);
  }

  // now grab our details using the scraper
  for (unsigned int i=0;i<strHTML.size();++i)
    parser.m_param[i] = strHTML[i];

  CStdString strXML = parser.Parse(strFunction);
  if (strXML.IsEmpty())
  {
    CLog::Log(LOGERROR, "%s: Unable to parse web site",__FUNCTION__);
    return false;
  }

  // abit ugly, but should work. would have been better if parser
  // set the charset of the xml, and we made use of that
  if (strXML.Find("encoding=\"utf-8\"") < 0)
    g_charsetConverter.unknownToUTF8(strXML);

    // ok, now parse the xml file
  TiXmlBase::SetCondenseWhiteSpace(false);
  TiXmlDocument doc;
  doc.Parse(strXML.c_str(),0,TIXML_ENCODING_UTF8);
  if (!doc.RootElement())
  {
    CLog::Log(LOGERROR, "%s: Unable to parse xml",__FUNCTION__);
    return false;
  }

  bool ret = Parse(doc.RootElement(),bChained);
  TiXmlElement* pRoot = doc.RootElement();
  TiXmlElement* xurl = pRoot->FirstChildElement("url");
  while (xurl && xurl->FirstChild())
  {
    const char* szFunction = xurl->Attribute("function");
    if (szFunction)
    {      
      CScraperUrl scrURL(xurl);
      Load(http,info,szFunction,&scrURL);
    }
    xurl = xurl->NextSiblingElement("url");
  }
  TiXmlBase::SetCondenseWhiteSpace(true);
  
  return ret;
}
예제 #4
0
void CMusicInfoScraper::FindAlbuminfo()
{
  CStdString strAlbum=m_strAlbum;
  CStdString strHTML;
  m_vecAlbums.erase(m_vecAlbums.begin(), m_vecAlbums.end());

  CScraperParser parser;
  if (!parser.Load(_P("q:\\system\\scrapers\\music\\"+m_info.strPath)))
    return;

  if (!m_info.settings.GetPluginRoot() || m_info.settings.GetSettings().IsEmpty())
  {
    m_info.settings.LoadSettingsXML(_P("q:\\system\\scrapers\\music\\"+m_info.strPath));
    m_info.settings.SaveFromDefault();
  }

  parser.m_param[0] = strAlbum;
  parser.m_param[1] = m_strArtist;
  CUtil::URLEncode(parser.m_param[0]);
  CUtil::URLEncode(parser.m_param[1]);

  CScraperUrl scrURL;
  scrURL.ParseString(parser.Parse("CreateAlbumSearchUrl"));
  if (!CScraperUrl::Get(scrURL.m_url[0], strHTML, m_http) || strHTML.size() == 0)
  {
    CLog::Log(LOGERROR, "%s: Unable to retrieve web site",__FUNCTION__);
    return;
  }

  parser.m_param[0] = strHTML;
  CStdString strXML = parser.Parse("GetAlbumSearchResults",&m_info.settings);
  if (strXML.IsEmpty())
  {
    CLog::Log(LOGERROR, "%s: Unable to parse web site",__FUNCTION__);
    return;
  }

  if (strXML.Find("encoding=\"utf-8\"") < 0)
    g_charsetConverter.unknownToUTF8(strXML);

  // ok, now parse the xml file
  TiXmlDocument doc;
  doc.Parse(strXML.c_str(),0,TIXML_ENCODING_UTF8);
  if (!doc.RootElement())
  {
    CLog::Log(LOGERROR, "%s: Unable to parse xml",__FUNCTION__);
    return;
  }
  TiXmlHandle docHandle( &doc );
  TiXmlElement* album = docHandle.FirstChild( "results" ).FirstChild( "entity" ).Element();
  if (!album)
    return;

  while (album)
  {
    TiXmlNode* title = album->FirstChild("title");
    TiXmlElement* link = album->FirstChildElement("url");
    TiXmlNode* artist = album->FirstChild("artist");
    TiXmlNode* year = album->FirstChild("year");
    if (title && title->FirstChild())
    {
      CStdString strTitle = title->FirstChild()->Value();
      CStdString strArtist;
      CStdString strAlbumName;

      if (artist && artist->FirstChild())
      {
        strArtist = artist->FirstChild()->Value();
        strAlbumName.Format("%s - %s",strArtist.c_str(),strTitle.c_str());
      }
      else
        strAlbumName = strTitle;

      if (year && year->FirstChild())
        strAlbumName.Format("%s (%s)",strAlbumName.c_str(),year->FirstChild()->Value());

      CScraperUrl url;
      if (!link)
        url.ParseString(scrURL.m_xml);

      while (link && link->FirstChild())
      {
        url.ParseElement(link);
        link = link->NextSiblingElement("url");
      }
      CMusicAlbumInfo newAlbum(strTitle, strArtist, strAlbumName, url);
      m_vecAlbums.push_back(newAlbum);
    }
    album = album->NextSiblingElement();
  }
  
  if (m_vecAlbums.size()>0)
    m_bSuccessfull=true;

  return;
}
예제 #5
0
void CGUIDialogContentSettings::OnWindowLoaded()
{
    CGUIDialogSettings::OnWindowLoaded();

    CFileItemList items;
    if (m_info.strContent.Equals("albums"))
        CDirectory::GetDirectory(_P("q:\\system\\scrapers\\music"),items,".xml",false);
    else
        CDirectory::GetDirectory(_P("q:\\system\\scrapers\\video"),items,".xml",false);
    for (int i=0; i<items.Size(); ++i)
    {
        if (!items[i]->m_bIsFolder)
        {
            TiXmlDocument doc;
            doc.LoadFile(items[i]->m_strPath);
            if (doc.RootElement())
            {
                const char* content = doc.RootElement()->Attribute("content");
                const char* name = doc.RootElement()->Attribute("name");
                const char* thumb = doc.RootElement()->Attribute("thumb");
                if (content && name)
                {
                    SScraperInfo info;
                    info.strTitle = name;
                    info.strPath = CUtil::GetFileName(items[i]->m_strPath);
                    if (thumb)
                        info.strThumb = thumb;
                    info.strContent = content;
                    info.settings = m_scraperSettings;
                    std::map<CStdString,std::vector<SScraperInfo> >::iterator iter=m_scrapers.find(content);
                    if (iter != m_scrapers.end())
                        iter->second.push_back(info);
                    else
                    {
                        std::vector<SScraperInfo> vec;
                        vec.push_back(info);
                        m_scrapers.insert(std::make_pair<CStdString,std::vector<SScraperInfo> >(content,vec));
                    }
                }
            }
        }
    }

    // now select the correct scraper
    if (!m_info.strContent.IsEmpty())
    {
        std::map<CStdString,std::vector<SScraperInfo> >::iterator iter = m_scrapers.find(m_info.strContent);
        if (iter != m_scrapers.end())
        {
            for (std::vector<SScraperInfo>::iterator iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2)
            {
                if (iter2->strPath == m_info.strPath)
                {
                    m_info = *iter2;
                    break;
                }
            }
        }
    }

    CScraperParser parser;
    CStdString strPath;
    if (!m_info.strContent.IsEmpty())
        strPath="q:\\system\\scrapers\\video\\"+m_info.strPath;
    if (!strPath.IsEmpty() && parser.Load(strPath) && parser.HasFunction("GetSettings"))
    {
        CONTROL_ENABLE(CONTROL_SCRAPER_SETTINGS)
    }
    else
    {
        CONTROL_DISABLE(CONTROL_SCRAPER_SETTINGS)
    }
}