Exemple #1
0
bool CDAVDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
  CCurlFile dav;
  CURL url(strPath);
  CStdString strRequest = "PROPFIND";

  dav.SetCustomRequest(strRequest);
  dav.SetMimeType("text/xml; charset=\"utf-8\"");
  dav.SetRequestHeader("depth", 1);
  dav.SetPostData(
    "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
    " <D:propfind xmlns:D=\"DAV:\">"
    "   <D:prop>"
    "     <D:resourcetype/>"
    "     <D:getcontentlength/>"
    "     <D:getlastmodified/>"
    "     <D:creationdate/>"
    "     <D:displayname/>"
    "    </D:prop>"
    "  </D:propfind>");

  if (!dav.Open(url))
  {
    CLog::Log(LOGERROR, "%s - Unable to get dav directory (%s)", __FUNCTION__, strPath.c_str());
    return false;
  }

  CStdString strResponse;
  dav.ReadData(strResponse);

  CXBMCTinyXML davResponse;
  davResponse.Parse(strResponse.c_str());

  if (!davResponse.Parse(strResponse))
  {
    CLog::Log(LOGERROR, "%s - Unable to process dav directory (%s)", __FUNCTION__, strPath.c_str());
    dav.Close();
    return false;
  }

  TiXmlNode *pChild;
  // Iterate over all responses
  for (pChild = davResponse.RootElement()->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
  {
    if (CDAVCommon::ValueWithoutNamespace(pChild, "response"))
    {
      CFileItem item;
      ParseResponse(pChild->ToElement(), item);
      CURL url2(strPath);
      CURL url3(item.GetPath());

      CStdString itemPath(URIUtils::AddFileToFolder(url2.GetWithoutFilename(), url3.GetFileName()));

      if (item.GetLabel().IsEmpty())
      {
        CStdString name(itemPath);
        URIUtils::RemoveSlashAtEnd(name);
        CURL::Decode(name);
        item.SetLabel(URIUtils::GetFileName(name));
      }

      if (item.m_bIsFolder)
        URIUtils::AddSlashAtEnd(itemPath);

      // Add back protocol options
      if (!url2.GetProtocolOptions().IsEmpty())
        itemPath += "|" + url2.GetProtocolOptions();
      item.SetPath(itemPath);

      if (!item.GetPath().Equals(strPath))
      {
        CFileItemPtr pItem(new CFileItem(item));
        items.Add(pItem);
      }
    }
  }

  dav.Close();

  return true;
}
Exemple #2
0
	CStdString *ThumbStore::getFanart(const char *artistName) {

		if (!Settings::getInstance()->getUseHTFanarts())
			return m_stdFanart;

		//Logger::printOut("Looking for fanart");

		//check if we got the fanart
		string artistNameString = artistName;
		stringMap::iterator it = m_fanarts.find(artistNameString);
		if (it == m_fanarts.end()) {
			//we dont have it so we need to to a search for it

			CCurlFile http;
			CStdString artistString = artistName;
			artistString.Replace(' ', '+');
			CStdString urlString;
			urlString.Format(
					"http://htbackdrops.org/api/afb0f6cdbd412a7888005de34f86e4a5/searchXML?keywords=%s&default_operator=and&aid=1&fields=title,keywords,caption,mb_name,mb_alias&inc=keywords,caption,mb_name,mb_aliases&limit=1",
					artistString);

			CURL url(urlString);

			if (http.Open(url)) {
				Logger::printOut("Looking for fanart, need to fetch a new address");
				Logger::printOut(artistNameString);
				//try to parse the resulting file for a fanart image
				CStdString data;
				http.ReadData(data);

				TiXmlDocument xmlDoc;
				xmlDoc.Parse(data);
				TiXmlNode* element = xmlDoc.RootElement();
				//get the images child
				element = element->FirstChild("images");
				if (element) {

					//get the first image child, (should only be one)
					element = element->FirstChild();
					if (element) {
						//get the id
						TiXmlNode* idElement = element->FirstChild("id");
						CStdString id = idElement->ToElement()->GetText();
						//get the filename
						TiXmlNode* fileNameElement = element->FirstChild("filename");
						CStdString name = fileNameElement->ToElement()->GetText();

						CStdString *fanartUrl = new CStdString();
						fanartUrl->Format(
								"http://htbackdrops.org/api/afb0f6cdbd412a7888005de34f86e4a5/download/%s/fullsize/%s",
								id, name);
						//Logger::printOut("Adding online fanart");

						m_fanarts.insert(
								stringMap::value_type(artistNameString, fanartUrl));

						//save the fanart url to the cachefile
						string path = Settings::getInstance()->getCachePath() + "fanarts.txt";
						Logger::printOut("saving fanart list");
						ofstream file(path.c_str(), ios::app);
						if (file.is_open()) {
							file << artistNameString << "\n" << *fanartUrl << "\n";
						}

						file.close();

						return fanartUrl;
					}
				}
			}
			//Logger::printOut("Adding standard fanart");
			m_fanarts.insert(stringMap::value_type(artistNameString, m_stdFanart));

			//save the fanart url to the cachefile
			string path = Settings::getInstance()->getCachePath() + "fanarts.txt";
			Logger::printOut("saving fanart list");
			ofstream file(path.c_str(), ios::app);
			if (file.is_open()) {
				file << artistNameString << "\n" << *m_stdFanart << "\n";
			}

			file.close();

			return m_stdFanart;
		}
		//Logger::printOut("Returning cached fanart");
		return it->second;
	}