int CNfoFile::Scrape(ScraperPtr& scraper, const CStdString& strURL /* = "" */) { if (scraper->Type() != m_type) { return 1; } if (!scraper->Load()) return 0; // init and clear cache scraper->ClearCache(); vector<CStdString> extras; CScraperUrl url; CFileCurl http; if (strURL.IsEmpty()) { extras.push_back(m_doc); vector<CStdString> result; if (scraper->GetParser().HasFunction("NfoScrape")) result = scraper->Run("NfoScrape",url,http,&extras); if (!result.empty()) { TiXmlDocument doc; doc.Parse(m_strImDbUrl.c_str()); if (doc.RootElement() && doc.RootElement()->FirstChildElement()) { CVideoInfoTag details; if (GetDetails(details,m_strImDbUrl.c_str())) { Close(); m_size = m_strImDbUrl.size(); m_doc = new char[m_size+1]; m_headofdoc = m_doc; strcpy(m_doc,m_strImDbUrl.c_str()); return 0; } } } if (!DoScrape(scraper)) return 2; if (m_strImDbUrl.size() > 0) return 0; else return 1; } else // we check to identify the episodeguide url { extras.push_back(strURL); vector<CStdString> result = scraper->Run("EpisodeGuideUrl",url,http,&extras); if (result.empty() || result[0].IsEmpty()) return 1; return 0; } }
bool CNfoFile::DoScrape(ScraperPtr& scraper) { vector<CStdString> extras; extras.push_back(m_doc); CScraperUrl url; CFileCurl http; vector<CStdString> xml; if (scraper->GetParser().HasFunction("NfoUrl")) xml = scraper->Run("NfoUrl",url,http,&extras); for (vector<CStdString>::iterator it = xml.begin(); it != xml.end(); ++it) { TiXmlDocument doc; doc.Parse(it->c_str()); if (doc.RootElement()) { if (stricmp(doc.RootElement()->Value(),"error")==0) { CIMDB::ShowErrorDialog(doc.RootElement()); return false; } TiXmlElement* pId = doc.FirstChildElement("id"); if (pId && pId->FirstChild()) m_strImDbNr = pId->FirstChild()->Value(); TiXmlElement* url = doc.FirstChildElement("url"); if (url) { stringstream str; str << *url; m_strImDbUrl = str.str(); SetScraperInfo(scraper); } else if (strcmp(doc.RootElement()->Value(),"url")==0) { SetScraperInfo(scraper); m_strImDbUrl = *it; } } } return true; }