bool OfflineDataStore::GetRegKeyForDocNum(const CStdString& sDocID, CRegKey& rkResult) { CStdString sNoVersionDocID = RemoveVersionLabel(sDocID); sNoVersionDocID.MakeLower(); CRegKey rk; long lResult = rk.Open(HKEY_CURRENT_USER, GetRegistryKeyName()); DWORD dwIndex = 0; while(lResult == ERROR_SUCCESS) { CStdString sResult; DWORD dwLength = MAX_PATH; lResult = rk.EnumKey(dwIndex, sResult.GetBuffer(MAX_PATH), &dwLength); sResult.ReleaseBuffer(); sResult.MakeLower(); dwIndex++; if(sResult.Find(sNoVersionDocID) != -1) { return (rkResult.Open(HKEY_CURRENT_USER, GetKeyNameForDocID(sResult)) == ERROR_SUCCESS); } } return false; }
CStdString OfflineDocIDResolver::GetOnlineLibrary( const CStdString& sDocID, const CStdString &sOfflineLibrary) const { CStdString sOfflineLib = _T("_") + sOfflineLibrary; CStdString sLib = GetLibrary(sDocID); sLib.MakeLower(); sOfflineLib.MakeLower(); sLib.Replace(sOfflineLib, _T("")); return sLib; }
bool ASAPCodec::Init(const CStdString &strFile, unsigned int filecache) { if (!m_dll.Load()) return false; CStdString strFileToLoad = strFile; int song = -1; CStdString strExtension; CUtil::GetExtension(strFile, strExtension); strExtension.MakeLower(); if (strExtension == ".asapstream") { CStdString strFileName = CUtil::GetFileName(strFile); int iStart = strFileName.ReverseFind('-') + 1; song = atoi(strFileName.substr(iStart, strFileName.size() - iStart - 11).c_str()) - 1; CStdString strPath = strFile; CUtil::GetDirectory(strPath, strFileToLoad); CUtil::RemoveSlashAtEnd(strFileToLoad); } int duration; if (!m_dll.asapLoad(strFileToLoad.c_str(), song, &m_Channels, &duration)) return false; m_TotalTime = duration; m_SampleRate = 44100; m_BitsPerSample = 16; return true; }
bool CFileCDDA::IsValidFile(const CURL& url) { // Only .cdda files are supported CStdString strExtension; CUtil::GetExtension(url.Get(), strExtension); strExtension.MakeLower(); return (strExtension == ".cdda"); }
BOOL CPermissions::Convert(CMarkupSTL *pXML) { if (!m_UsersList.size()) return FALSE; if (!pXML->FindChildElem(_T("Users"))) pXML->AddChildElem(_T("Users")); pXML->IntoElem(); //Save the changed user details for (t_UsersList::const_iterator iter=m_UsersList.begin(); iter!=m_UsersList.end(); iter++) { pXML->ResetChildPos(); CStdString newname = iter->user; newname.MakeLower(); while (pXML->FindChildElem("User")) { CStdString name = pXML->GetChildAttrib(_T("Name")); name.MakeLower(); if (name == newname) pXML->RemoveChildElem(); } pXML->AddChildElem(_T("User")); pXML->AddChildAttrib(_T("Name"), iter->user); pXML->IntoElem(); SetKey(pXML, "Pass", iter->password); SetKey(pXML, "Resolve Shortcuts", iter->bLnk?"1":"0"); SetKey(pXML, "Relative", iter->bRelative?"1":"0"); SetKey(pXML, "Bypass server userlimit", iter->bBypassUserLimit?"1":"0"); CStdString str; str.Format(_T("%d"), iter->nUserLimit); SetKey(pXML, "User Limit", str); str.Format(_T("%d"), iter->nIpLimit); SetKey(pXML, "IP Limit", str); SavePermissions(pXML, *iter); pXML->OutOfElem(); } return TRUE; }
CStdString OMXReader::GetStreamCodecName(AVStream *stream) { CStdString strStreamName = ""; if(!stream) return strStreamName; unsigned int in = stream->codec->codec_tag; // FourCC codes are only valid on video streams, audio codecs in AVI/WAV // are 2 bytes and audio codecs in transport streams have subtle variation // e.g AC-3 instead of ac3 if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO && in != 0) { char fourcc[5]; memcpy(fourcc, &in, 4); fourcc[4] = 0; // fourccs have to be 4 characters if (strlen(fourcc) == 4) { strStreamName = fourcc; strStreamName.MakeLower(); return strStreamName; } } #ifdef FF_PROFILE_DTS_HD_MA /* use profile to determine the DTS type */ if (stream->codec->codec_id == CODEC_ID_DTS) { if (stream->codec->profile == FF_PROFILE_DTS_HD_MA) strStreamName = "dtshd_ma"; else if (stream->codec->profile == FF_PROFILE_DTS_HD_HRA) strStreamName = "dtshd_hra"; else strStreamName = "dca"; return strStreamName; } #endif AVCodec *codec = m_dllAvCodec.avcodec_find_decoder(stream->codec->codec_id); if (codec) strStreamName = codec->name; return strStreamName; }
bool CMusicInfoTagLoaderASAP::Load(const CStdString &strFile, CMusicInfoTag &tag, EmbeddedArt *art) { tag.SetLoaded(false); if (!m_dll.Load()) return false; CStdString strFileToLoad = strFile; int song = -1; CStdString strExtension; URIUtils::GetExtension(strFile, strExtension); strExtension.MakeLower(); if (strExtension == ".asapstream") { CStdString strFileName = URIUtils::GetFileName(strFile); int iStart = strFileName.ReverseFind('-') + 1; song = atoi(strFileName.substr(iStart, strFileName.size() - iStart - 11).c_str()) - 1; CStdString strPath = strFile; URIUtils::GetDirectory(strPath, strFileToLoad); URIUtils::RemoveSlashAtEnd(strFileToLoad); } ASAP_SongInfo songInfo; if (!m_dll.asapGetInfo(strFileToLoad.c_str(), song, &songInfo)) return false; tag.SetURL(strFileToLoad); if (songInfo.name[0] != '\0') tag.SetTitle(songInfo.name); if (songInfo.author[0] != '\0') tag.SetArtist(songInfo.author); if (song >= 0) tag.SetTrackNumber(song + 1); if (songInfo.duration >= 0) tag.SetDuration(songInfo.duration / 1000); if (songInfo.year > 0) { SYSTEMTIME dateTime = { (WORD)songInfo.year, (WORD)songInfo.month, 0, (WORD)songInfo.day, 0, 0, 0, 0 }; tag.SetReleaseDate(dateTime); } tag.SetLoaded(true); return true; }
bool URIUtils::IsDVD(const CStdString& strFile) { #if defined(_WIN32) if(strFile.Mid(1) != ":\\" && strFile.Mid(1) != ":") return false; if((GetDriveType(strFile.c_str()) == DRIVE_CDROM) || strFile.Left(6).Equals("dvd://")) return true; #else CStdString strFileLow = strFile; strFileLow.MakeLower(); if (strFileLow == "d:/" || strFileLow == "d:\\" || strFileLow == "d:" || strFileLow == "iso9660://" || strFileLow == "udf://" || strFileLow == "dvd://1" ) return true; #endif return false; }
void CAdvancedSettings::GetCustomTVRegexps(TiXmlElement *pRootElement, SETTINGS_TVSHOWLIST& settings) { int iAction = 0; // overwrite // for backward compatibility const char* szAppend = pRootElement->Attribute("append"); if ((szAppend && stricmp(szAppend, "yes") == 0)) iAction = 1; // action takes precedence if both attributes exist const char* szAction = pRootElement->Attribute("action"); if (szAction) { iAction = 0; // overwrite if (stricmp(szAction, "append") == 0) iAction = 1; // append else if (stricmp(szAction, "prepend") == 0) iAction = 2; // prepend } if (iAction == 0) settings.clear(); TiXmlNode* pRegExp = pRootElement->FirstChild("regexp"); int i = 0; while (pRegExp) { if (pRegExp->FirstChild()) { bool bByDate = false; if (pRegExp->ToElement()) { CStdString byDate = pRegExp->ToElement()->Attribute("bydate"); if(byDate && stricmp(byDate, "true") == 0) { bByDate = true; } } CStdString regExp = pRegExp->FirstChild()->Value(); regExp.MakeLower(); if (iAction == 2) settings.insert(settings.begin() + i++, 1, TVShowRegexp(bByDate,regExp)); else settings.push_back(TVShowRegexp(bByDate,regExp)); } pRegExp = pRegExp->NextSibling("regexp"); } }
bool CPlayListFactory::IsPlaylist(const CFileItem& item, bool bAllowQuery) { CStdString extension = CUtil::GetExtension(item.m_strPath); extension.ToLower(); if (extension == ".m3u") return true; if (extension == ".m3u8") return true; if (extension == ".b4s") return true; if (extension == ".pls") return true; if (extension == ".strm") return true; if (extension == ".wpl") return true; if (extension == ".asx") return true; if (extension == ".ram") return true; if (item.IsLastFM()) return false; if (extension == ".url") return true; if (extension == ".pxml") return true; if (item.IsShoutCast()) return false; if( item.IsInternetStream() ) { CStdString strContentType = item.GetContentType(bAllowQuery); strContentType.MakeLower(); if (strContentType == "video/x-ms-asf" || strContentType == "video/x-ms-asx" || strContentType == "video/x-ms-wfs" || strContentType == "video/x-ms-wvx" || strContentType == "video/x-ms-wax" || strContentType == "audio/x-pn-realaudio" || strContentType == "audio/x-scpls" || strContentType == "playlist" || strContentType == "audio/x-mpegurl" || strContentType == "application/vnd.ms-wpl") return true; } return false; }
BOOL CObjectEntry::GetAccessType(CStdString& strAccessType, bool p_oLowerCase) { BOOL oResult(FALSE); switch(m_AccessType) { case AT_READ_WRITE: strAccessType = "RW"; oResult = TRUE; break; case AT_READ_WRITE_READ: strAccessType = "RW"; oResult = TRUE; break; case AT_READ_WRITE_WRITE: strAccessType = "RW"; oResult = TRUE; break; case AT_WRITE_ONLY: strAccessType = "WO"; oResult = TRUE; break; case AT_READ_ONLY: strAccessType = "RO"; oResult = TRUE; break; case AT_READ_ONLY_CONST: strAccessType = "Const"; oResult = TRUE; break; default: strAccessType = ""; oResult = FALSE; break; } if(p_oLowerCase) { strAccessType.MakeLower(); } return oResult; }
void CAdvancedSettings::GetCustomRegexps(TiXmlElement *pRootElement, CStdStringArray& settings) { TiXmlElement *pElement = pRootElement; while (pElement) { int iAction = 0; // overwrite // for backward compatibility const char* szAppend = pElement->Attribute("append"); if ((szAppend && stricmp(szAppend, "yes") == 0)) iAction = 1; // action takes precedence if both attributes exist const char* szAction = pElement->Attribute("action"); if (szAction) { iAction = 0; // overwrite if (stricmp(szAction, "append") == 0) iAction = 1; // append else if (stricmp(szAction, "prepend") == 0) iAction = 2; // prepend } if (iAction == 0) settings.clear(); TiXmlNode* pRegExp = pElement->FirstChild("regexp"); int i = 0; while (pRegExp) { if (pRegExp->FirstChild()) { CStdString regExp = pRegExp->FirstChild()->Value(); regExp.MakeLower(); if (iAction == 2) settings.insert(settings.begin() + i++, 1, regExp); else settings.push_back(regExp); } pRegExp = pRegExp->NextSibling("regexp"); } pElement = pElement->NextSiblingElement(pRootElement->Value()); } }
bool NSFCodec::Init(const CStdString &strFile, unsigned int filecache) { DeInit(); if (!m_dll.Load()) return false; // error logged previously CStdString strFileToLoad = strFile; m_iTrack = 0; CStdString strExtension; URIUtils::GetExtension(strFile,strExtension); strExtension.MakeLower(); if (strExtension==".nsfstream") { // Extract the track to play CStdString strFileName=URIUtils::GetFileName(strFile); int iStart=strFileName.ReverseFind('-')+1; m_iTrack = atoi(strFileName.substr(iStart, strFileName.size()-iStart-10).c_str()); // The directory we are in, is the file // that contains the bitstream to play, // so extract it CStdString strPath=strFile; URIUtils::GetDirectory(strPath, strFileToLoad); URIUtils::RemoveSlashAtEnd(strFileToLoad); // we want the filename } m_nsf = m_dll.LoadNSF(strFileToLoad.c_str()); if (!m_nsf) { CLog::Log(LOGERROR,"NSFCodec: error opening file %s!",strFile.c_str()); return false; } m_Channels = 1; m_SampleRate = 48000; m_BitsPerSample = 16; m_DataFormat = AE_FMT_S16NE; m_TotalTime = 4*60*1000; // fixme? m_iDataPos = 0; return true; }
bool URIUtils::IsDVD(const CStdString& strFile) { CStdString strFileLow = strFile; strFileLow.MakeLower(); if (strFileLow.Find("video_ts.ifo") != -1 && IsOnDVD(strFile)) return true; #if defined(TARGET_WINDOWS) if (StringUtils::StartsWithNoCase(strFile, "dvd://")) return true; if(strFile.Mid(1) != ":\\" && strFile.Mid(1) != ":") return false; if(GetDriveType(strFile.c_str()) == DRIVE_CDROM) return true; #else if (strFileLow == "iso9660://" || strFileLow == "udf://" || strFileLow == "dvd://1" ) return true; #endif return false; }
CPlayList* CPlayListFactory::Create(const CFileItem& item) { if(item.IsLastFM()) //lastfm is always a stream, and just silly to check content return NULL; if( item.IsInternetStream() ) { CStdString strContentType = item.GetContentType(); strContentType.MakeLower(); if (strContentType == "video/x-ms-asf" || strContentType == "video/x-ms-asx" || strContentType == "video/x-ms-wmv" || strContentType == "video/x-ms-wma" || strContentType == "video/x-ms-wfs" || strContentType == "video/x-ms-wvx" || strContentType == "video/x-ms-wax" ) return new CPlayListASX(); if (strContentType == "audio/x-pn-realaudio") return new CPlayListRAM(); if (strContentType == "audio/x-scpls" || strContentType == "playlist") return new CPlayListPLS(); if (strContentType == "audio/x-mpegurl" || strContentType == "application/vnd.apple.mpegurl") return new CPlayListM3U(); if (strContentType == "application/vnd.ms-wpl") return new CPlayListWPL(); } CStdString extension = CUtil::GetExtension(item.m_strPath); extension.MakeLower(); if (extension == ".m3u" || extension == ".m3u8" || extension == ".strm") return new CPlayListM3U(); if (extension == ".pls") return new CPlayListPLS(); if (extension == ".b4s") return new CPlayListB4S(); if (extension == ".wpl") return new CPlayListWPL(); if (extension == ".asx") return new CPlayListASX(); if (extension == ".ram") return new CPlayListRAM(); if (extension == ".url") return new CPlayListURL(); if (extension == ".pxml") return new CPlayListXML(); return NULL; }
CStdString GG::htmlToMsg(CStdString msgIn , void * formats , int & length) { int max_len = length; length = 0; CStdString msg; SXML XML; RegEx preg; msgIn = preg.replace("#\\r|\\n#" , "" , msgIn); msgIn = preg.replace("#<br/?>#i" , "\n" , msgIn.c_str()); XML.loadSource(msgIn); SXML::NodeWalkInfo ni; size_t last = 0; void * formats_start = formats; gg_msg_richtext * rt = (gg_msg_richtext*) formats; formats = rt+1; void * formats_last = formats; memset(formats , 0 , sizeof(gg_msg_richtext_format)); /* bleeeee<b>bold<b><font color="#FF0000">gnie�<u>d�ony</u></font></b>i <i>jesz</i>cze</b>koniec */ FormatState state; stack <FormatState> spanStack; while (length < max_len - 20 && XML.nodeWalk(ni)) { XML.pos.start = XML.pos.end; XML.pos.start_end = XML.pos.end_end; msg += Stamina::decodeEntities(msgIn.substr(last , ni.start - last)); last = ni.end; CStdString token = ni.path.substr(ni.path.find_last_of('/')+1); token.MakeLower(); int oper = (ni.state == SXML::NodeWalkInfo::opened)? 1 : -1; if (token == "b" || token == "strong") { state.bold+=oper; } else if (token == "i") { state.italic+=oper; } else if (token == "u") { state.under+=oper; } else if (token == "font") { // Kolor musimy "zamkn��" if (oper > 0) state.color++; int c = chtoint(XML.getAttrib("color").c_str() , -1); state.rgb[0] = (c & 0xFF0000) >> 16; state.rgb[1] = (c & 0xFF00) >> 8; state.rgb[2] = (c & 0xFF); } else if (token == "span") { if (oper > 0) { spanStack.push(state); using Stamina::RegEx; static RegEx::oCompiled rcWeight(new RegEx::Compiled("/font-weight:bold/i")); //static RegEx::oCompiled rcSize = new RegEx::Compiled("/font-size:(\\d+)/i"); static RegEx::oCompiled rcColor(new RegEx::Compiled("/color:([a-z]+|#[0-9A-F]+)/i")); static RegEx::oCompiled rcItalic(new RegEx::Compiled("/font-style:italic/i")); static RegEx::oCompiled rcUnderline(new RegEx::Compiled("/text-decoration:underline/i")); CStdString style = XML.getAttrib("style"); if (RegEx::doMatch(rcWeight, style)) { state.bold += oper; } if (RegEx::doMatch(rcItalic, style)) { state.italic += oper; } if (RegEx::doMatch(rcUnderline, style)) { state.under += oper; } CStdString colorStr = RegEx::doGet(rcColor, style, 1); if (!colorStr.empty()) { int color = -1; if (colorStr[0] == '#') { color = Stamina::chtoint(colorStr , -1); } else if (colorStr == "red") { color = 0xFF0000; } else if (colorStr == "blue") { color = 0x0000FF; } else if (colorStr == "green") { color = 0x00FF00; } if (color > 0) { state.color++; state.rgb[0] = (color & 0xFF0000) >> 16; state.rgb[1] = (color & 0xFF00) >> 8; state.rgb[2] = (color & 0xFF); } }
CStdString IntelligentDocInfo::PrepareDocId(CStdString sDocId) { sDocId.Trim(); sDocId.MakeLower(); return sDocId; }
CPlayList* CPlayListFactory::Create(const CFileItem& item) { if( item.IsInternetStream() ) { // Ensure the MIME type has been retrieved for http:// and shout:// streams if (item.GetMimeType().empty()) const_cast<CFileItem&>(item).FillInMimeType(); CStdString strMimeType = item.GetMimeType(); strMimeType.MakeLower(); if (strMimeType == "video/x-ms-asf" || strMimeType == "video/x-ms-asx" || strMimeType == "video/x-ms-wmv" || strMimeType == "video/x-ms-wma" || strMimeType == "video/x-ms-wfs" || strMimeType == "video/x-ms-wvx" || strMimeType == "video/x-ms-wax") return new CPlayListASX(); if (strMimeType == "audio/x-pn-realaudio") return new CPlayListRAM(); if (strMimeType == "audio/x-scpls" || strMimeType == "playlist" || strMimeType == "text/html") return new CPlayListPLS(); // online m3u8 files are for hls streaming -- do not treat as playlist if (strMimeType == "audio/x-mpegurl" && !item.IsType(".m3u8")) return new CPlayListM3U(); if (strMimeType == "application/vnd.ms-wpl") return new CPlayListWPL(); } CStdString extension = URIUtils::GetExtension(item.GetPath()); extension.MakeLower(); if (extension == ".m3u" || extension == ".strm") return new CPlayListM3U(); if (extension == ".pls") return new CPlayListPLS(); if (extension == ".b4s") return new CPlayListB4S(); if (extension == ".wpl") return new CPlayListWPL(); if (extension == ".asx") return new CPlayListASX(); if (extension == ".ram") return new CPlayListRAM(); if (extension == ".url") return new CPlayListURL(); if (extension == ".pxml") return new CPlayListXML(); return NULL; }
IFile* CFileFactory::CreateLoader(const CURL& url) { CStdString strProtocol = url.GetProtocol(); strProtocol.MakeLower(); if (strProtocol == "zip") return new CFileZip(); #ifdef HAS_FILESYSTEM_RAR else if (strProtocol == "rar") return new CFileRar(); #endif else if (strProtocol == "musicdb") return new CFileMusicDatabase(); else if (strProtocol == "videodb") return NULL; else if (strProtocol == "special") return new CFileSpecialProtocol(); else if (strProtocol == "multipath") return new CMultiPathFile(); else if (strProtocol == "file" || strProtocol.IsEmpty()) return new CFileHD(); else if (strProtocol == "filereader") return new CFileFileReader(); #if defined(HAS_FILESYSTEM_CDDA) && defined(HAS_DVD_DRIVE) else if (strProtocol == "cdda") return new CFileCDDA(); #endif #ifdef HAS_FILESYSTEM else if (strProtocol == "iso9660") return new CFileISO(); #endif else if(strProtocol == "udf") return new CFileUDF(); if( g_application.getNetwork().IsAvailable() ) { if (strProtocol == "http" || strProtocol == "https" || strProtocol == "dav" || strProtocol == "davs" || strProtocol == "ftp" || strProtocol == "ftpx" || strProtocol == "ftps" || strProtocol == "rss") return new CFileCurl(); #ifdef HAS_FILESYSTEM_SFTP else if (strProtocol == "sftp" || strProtocol == "ssh") return new CFileSFTP(); #endif else if (strProtocol == "shout") return new CFileShoutcast(); else if (strProtocol == "lastfm") return new CFileLastFM(); else if (strProtocol == "tuxbox") return new CFileTuxBox(); else if (strProtocol == "hdhomerun") return new CFileHomeRun(); else if (strProtocol == "sling") return new CSlingboxFile(); else if (strProtocol == "myth") return new CMythFile(); else if (strProtocol == "cmyth") return new CMythFile(); #ifdef HAS_FILESYSTEM_SMB #ifdef _WIN32 else if (strProtocol == "smb") return new CWINFileSMB(); #else else if (strProtocol == "smb") return new CFileSMB(); #endif #endif #ifdef HAS_FILESYSTEM #ifdef HAS_FILESYSTEM_RTV else if (strProtocol == "rtv") return new CFileRTV(); #endif #ifdef HAS_FILESYSTEM_DAAP else if (strProtocol == "daap") return new CFileDAAP(); #endif #endif #ifdef HAS_FILESYSTEM_SAP else if (strProtocol == "sap") return new CSAPFile(); #endif #ifdef HAS_FILESYSTEM_VTP else if (strProtocol == "vtp") return new CVTPFile(); #endif #ifdef HAS_PVRCLIENTS else if (strProtocol == "pvr") return new CPVRFile(); #endif #ifdef HAS_FILESYSTEM_NFS else if (strProtocol == "nfs") return new CFileNFS(); #endif #ifdef HAS_FILESYSTEM_AFP else if (strProtocol == "afp") return new CFileAFP(); #endif } CLog::Log(LOGWARNING, "%s - Unsupported protocol(%s) in %s", __FUNCTION__, strProtocol.c_str(), url.Get().c_str() ); return NULL; }
CPlayList* CPlayListFactory::Create(const CFileItem& item) { if(item.IsLastFM()) //lastfm is always a stream, and just silly to check content return NULL; if( item.IsInternetStream() ) { CStdString strMimeType = item.GetMimeType(); strMimeType.MakeLower(); if (strMimeType == "video/x-ms-asf" || strMimeType == "video/x-ms-asx" || strMimeType == "video/x-ms-wmv" || strMimeType == "video/x-ms-wma" || strMimeType == "video/x-ms-wfs" || strMimeType == "video/x-ms-wvx" || strMimeType == "video/x-ms-wax") return new CPlayListASX(); if (strMimeType == "audio/x-pn-realaudio") return new CPlayListRAM(); if (strMimeType == "audio/x-scpls" || strMimeType == "playlist" || strMimeType == "text/html") return new CPlayListPLS(); // online m3u8 files are for hls streaming -- do not treat as playlist if (strMimeType == "audio/x-mpegurl" && !item.IsType(".m3u8")) return new CPlayListM3U(); if (strMimeType == "application/vnd.ms-wpl") return new CPlayListWPL(); } CStdString extension = URIUtils::GetExtension(item.GetPath()); extension.MakeLower(); if (extension == ".m3u" || extension == ".strm") return new CPlayListM3U(); if (extension == ".pls") return new CPlayListPLS(); if (extension == ".b4s") return new CPlayListB4S(); if (extension == ".wpl") return new CPlayListWPL(); if (extension == ".asx") return new CPlayListASX(); if (extension == ".ram") return new CPlayListRAM(); if (extension == ".url") return new CPlayListURL(); if (extension == ".pxml") return new CPlayListXML(); return NULL; }
IFile* CFileFactory::CreateLoader(const CURL& url) { CStdString strProtocol = url.GetProtocol(); strProtocol.MakeLower(); if (strProtocol == "zip") return new CFileZip(); else if (strProtocol == "rar") return new CFileRar(); else if (strProtocol == "musicdb") return new CFileMusicDatabase(); else if (strProtocol == "file" || strProtocol.IsEmpty()) return new CFileHD(); else if (strProtocol == "filereader") return new CFileFileReader(); #ifdef HAS_FILESYSTEM_CDDA else if (strProtocol == "cdda") return new CFileCDDA(); #endif #ifdef HAS_FILESYSTEM else if (strProtocol == "iso9660") return new CFileISO(); #ifdef HAS_XBOX_HARDWARE else if (strProtocol == "soundtrack") return new CFileSndtrk(); #endif #endif #ifdef HAS_XBOX_HARDWARE else if (strProtocol.Left(3) == "mem") return new CFileMemUnit(); #endif if( g_application.getNetwork().IsAvailable() ) { if (strProtocol == "http" || strProtocol == "https") return new CFileCurl(); else if (strProtocol == "ftp" || strProtocol == "ftpx" || strProtocol == "ftps") return new CFileCurl(); else if (strProtocol == "upnp") return new CFileCurl(); else if (strProtocol == "mms") return new CFileMMS(); else if (strProtocol == "shout") return new CFileShoutcast(); else if (strProtocol == "lastfm") return new CFileLastFM(); else if (strProtocol == "tuxbox") return new CFileTuxBox(); else if (strProtocol == "hdhomerun") return new CFileHomeRun(); else if (strProtocol == "myth") return new CCMythFile(); else if (strProtocol == "cmyth") return new CCMythFile(); #ifdef HAS_FILESYSTEM_SMB else if (strProtocol == "smb") return new CFileSMB(); #endif #ifdef HAS_CCXSTREAM else if (strProtocol == "xbms") return new CFileXBMSP(); #endif #ifdef HAS_FILESYSTEM #ifdef HAS_FILESYSTEM_RTV else if (strProtocol == "rtv") return new CFileRTV(); #endif #ifdef HAS_FILESYSTEM_DAAP else if (strProtocol == "daap") return new CFileDAAP(); #endif #endif else if (strProtocol == "myth") return new CCMythFile(); else if (strProtocol == "cmyth") return new CCMythFile(); else if (strProtocol == "eyetv") { return new CFileEyeTVSocket(); } } return NULL; }
IFile* CFileFactory::CreateLoader(const CURL& url) { CStdString strProtocol = url.GetProtocol(); strProtocol.MakeLower(); #if defined(TARGET_ANDROID) if (strProtocol == "apk") return new CAPKFile(); #endif if (strProtocol == "zip") return new CZipFile(); else if (strProtocol == "rar") { #ifdef HAS_FILESYSTEM_RAR return new CRarFile(); #else CLog::Log(LOGWARNING, "%s - Compiled without non-free, rar support is disabled", __FUNCTION__); #endif } else if (strProtocol == "musicdb") return new CMusicDatabaseFile(); else if (strProtocol == "videodb") return NULL; else if (strProtocol == "special") return new CSpecialProtocolFile(); else if (strProtocol == "multipath") return new CMultiPathFile(); else if (strProtocol == "image") return new CImageFile(); else if (strProtocol == "file" || strProtocol.IsEmpty()) return new CHDFile(); else if (strProtocol == "filereader") return new CFileReaderFile(); #if defined(HAS_FILESYSTEM_CDDA) && defined(HAS_DVD_DRIVE) else if (strProtocol == "cdda") return new CFileCDDA(); #endif #ifdef HAS_FILESYSTEM else if (strProtocol == "iso9660") return new CISOFile(); #endif else if(strProtocol == "udf") return new CUDFFile(); if( g_application.getNetwork().IsAvailable() ) { if (strProtocol == "ftp" || strProtocol == "ftps" || strProtocol == "rss") return new CCurlFile(); else if (strProtocol == "http" || strProtocol == "https") return new CHTTPFile(); else if (strProtocol == "dav" || strProtocol == "davs") return new CDAVFile(); #ifdef HAS_FILESYSTEM_SFTP else if (strProtocol == "sftp" || strProtocol == "ssh") return new CSFTPFile(); #endif else if (strProtocol == "shout") return new CShoutcastFile(); else if (strProtocol == "lastfm") return new CLastFMFile(); else if (strProtocol == "tuxbox") return new CTuxBoxFile(); else if (strProtocol == "hdhomerun") return new CHomeRunFile(); else if (strProtocol == "sling") return new CSlingboxFile(); else if (strProtocol == "myth") return new CMythFile(); else if (strProtocol == "cmyth") return new CMythFile(); #ifdef HAS_FILESYSTEM_SMB #ifdef _WIN32 else if (strProtocol == "smb") return new CWINFileSMB(); #else else if (strProtocol == "smb") return new CSmbFile(); #endif #endif #ifdef HAS_FILESYSTEM #ifdef HAS_FILESYSTEM_RTV else if (strProtocol == "rtv") return new CRTVFile(); #endif #ifdef HAS_FILESYSTEM_DAAP else if (strProtocol == "daap") return new CDAAPFile(); #endif #endif #ifdef HAS_FILESYSTEM_SAP else if (strProtocol == "sap") return new CSAPFile(); #endif #ifdef HAS_FILESYSTEM_VTP else if (strProtocol == "vtp") return new CVTPFile(); #endif #ifdef HAS_PVRCLIENTS else if (strProtocol == "pvr") return new CPVRFile(); #endif #ifdef HAS_FILESYSTEM_NFS else if (strProtocol == "nfs") return new CNFSFile(); #endif #ifdef HAS_FILESYSTEM_AFP else if (strProtocol == "afp") return new CAFPFile(); #endif else if (strProtocol == "pipe") return new CPipeFile(); #ifdef HAS_UPNP else if (strProtocol == "upnp") return new CUPnPFile(); #endif #if defined(TARGET_ANDROID) else if (strProtocol == "androidapp") return new CFileAndroidApp(); #endif } CLog::Log(LOGWARNING, "%s - Unsupported protocol(%s) in %s", __FUNCTION__, strProtocol.c_str(), url.Get().c_str() ); return NULL; }
bool CDVDVideoCodecVDA::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) { if (CSettings::Get().GetBool("videoplayer.usevda") && !hints.software) { CCocoaAutoPool pool; // int width = hints.width; int height = hints.height; int level = hints.level; int profile = hints.profile; switch(profile) { case FF_PROFILE_H264_HIGH_10: case FF_PROFILE_H264_HIGH_10_INTRA: case FF_PROFILE_H264_HIGH_422: case FF_PROFILE_H264_HIGH_422_INTRA: case FF_PROFILE_H264_HIGH_444_PREDICTIVE: case FF_PROFILE_H264_HIGH_444_INTRA: case FF_PROFILE_H264_CAVLC_444: CLog::Log(LOGNOTICE, "%s - unsupported h264 profile(%d)", __FUNCTION__, hints.profile); return false; break; } if (width <= 0 || height <= 0) { CLog::Log(LOGNOTICE, "%s - bailing with bogus hints, width(%d), height(%d)", __FUNCTION__, width, height); return false; } if (Cocoa_GPUForDisplayIsNvidiaPureVideo3() && !CDVDCodecUtils::IsVP3CompatibleWidth(width)) { CLog::Log(LOGNOTICE, "%s - Nvidia 9400 GPU hardware limitation, cannot decode a width of %d", __FUNCTION__, width); return false; } CFDataRef avcCData; switch (hints.codec) { case CODEC_ID_H264: m_bitstream = new CBitstreamConverter; if (!m_bitstream->Open(hints.codec, (uint8_t*)hints.extradata, hints.extrasize, false)) return false; avcCData = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)m_bitstream->GetExtraData(), m_bitstream->GetExtraSize()); m_format = 'avc1'; m_pFormatName = "vda-h264"; break; default: return false; break; } // check the avcC atom's sps for number of reference frames and // bail if interlaced, VDA does not handle interlaced h264. uint32_t avcc_len = CFDataGetLength(avcCData); if (avcc_len < 8) { // avcc atoms with length less than 8 are borked. CFRelease(avcCData); delete m_bitstream, m_bitstream = NULL; return false; } else { bool interlaced = true; uint8_t *spc = (uint8_t*)CFDataGetBytePtr(avcCData) + 6; uint32_t sps_size = BS_RB16(spc); if (sps_size) m_bitstream->parseh264_sps(spc+3, sps_size-1, &interlaced, &m_max_ref_frames); if (interlaced) { CLog::Log(LOGNOTICE, "%s - possible interlaced content.", __FUNCTION__); CFRelease(avcCData); return false; } } if (profile == FF_PROFILE_H264_MAIN && level == 32 && m_max_ref_frames > 4) { // [email protected], VDA cannot handle greater than 4 reference frames CLog::Log(LOGNOTICE, "%s - [email protected] detected, VDA cannot decode.", __FUNCTION__); CFRelease(avcCData); return false; } CStdString rendervendor = g_Windowing.GetRenderVendor(); rendervendor.MakeLower(); if (rendervendor.find("nvidia") != std::string::npos) { // Nvidia gpu's are all powerful and work the way god intended m_decode_async = true; m_use_cvBufferRef = true; } else if (rendervendor.find("intel") != std::string::npos) { // Intel gpu are borked when using cvBufferRef m_decode_async = true; m_use_cvBufferRef = false; } else { // ATI gpu's are borked when using async decode m_decode_async = false; m_use_cvBufferRef = true; } if (!m_use_cvBufferRef) { m_dllSwScale = new DllSwScale; if (!m_dllSwScale->Load()) { CFRelease(avcCData); return false; } // allocate a YV12 DVDVideoPicture buffer. // first make sure all properties are reset. memset(&m_videobuffer, 0, sizeof(DVDVideoPicture)); unsigned int iPixels = width * height; unsigned int iChromaPixels = iPixels/4; m_videobuffer.dts = DVD_NOPTS_VALUE; m_videobuffer.pts = DVD_NOPTS_VALUE; m_videobuffer.iFlags = DVP_FLAG_ALLOCATED; m_videobuffer.format = RENDER_FMT_YUV420P; m_videobuffer.color_range = 0; m_videobuffer.color_matrix = 4; m_videobuffer.iWidth = width; m_videobuffer.iHeight = height; m_videobuffer.iDisplayWidth = width; m_videobuffer.iDisplayHeight = height; m_videobuffer.iLineSize[0] = width; //Y m_videobuffer.iLineSize[1] = width/2; //U m_videobuffer.iLineSize[2] = width/2; //V m_videobuffer.iLineSize[3] = 0; m_videobuffer.data[0] = (uint8_t*)malloc(16 + iPixels); m_videobuffer.data[1] = (uint8_t*)malloc(16 + iChromaPixels); m_videobuffer.data[2] = (uint8_t*)malloc(16 + iChromaPixels); m_videobuffer.data[3] = NULL; // set all data to 0 for less artifacts.. hmm.. what is black in YUV?? memset(m_videobuffer.data[0], 0, iPixels); memset(m_videobuffer.data[1], 0, iChromaPixels); memset(m_videobuffer.data[2], 0, iChromaPixels); } // setup the decoder configuration dict CFMutableDictionaryRef decoderConfiguration = CFDictionaryCreateMutable( kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFNumberRef avcWidth = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &width); CFNumberRef avcHeight = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &height); CFNumberRef avcFormat = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &m_format); CFDictionarySetValue(decoderConfiguration, kVDADecoderConfiguration_Height, avcHeight); CFDictionarySetValue(decoderConfiguration, kVDADecoderConfiguration_Width, avcWidth); CFDictionarySetValue(decoderConfiguration, kVDADecoderConfiguration_SourceFormat, avcFormat); CFDictionarySetValue(decoderConfiguration, kVDADecoderConfiguration_avcCData, avcCData); // release the retained object refs, decoderConfiguration owns them now CFRelease(avcWidth); CFRelease(avcHeight); CFRelease(avcFormat); CFRelease(avcCData); // setup the destination image buffer dict, vda will output this pict format CFMutableDictionaryRef destinationImageBufferAttributes = CFDictionaryCreateMutable( kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); OSType cvPixelFormatType = kCVPixelFormatType_422YpCbCr8; CFNumberRef pixelFormat = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &cvPixelFormatType); // an IOSurface properties dictionary CFDictionaryRef iosurfaceDictionary = CFDictionaryCreate(kCFAllocatorDefault, NULL, NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(destinationImageBufferAttributes, kCVPixelBufferPixelFormatTypeKey, pixelFormat); CFDictionarySetValue(destinationImageBufferAttributes, kCVPixelBufferIOSurfacePropertiesKey, iosurfaceDictionary); // release the retained object refs, destinationImageBufferAttributes owns them now CFRelease(pixelFormat); CFRelease(iosurfaceDictionary); // create the VDADecoder object OSStatus status; try { status = VDADecoderCreate(decoderConfiguration, destinationImageBufferAttributes, (VDADecoderOutputCallback*)VDADecoderCallback, this, (VDADecoder*)&m_vda_decoder); } catch (...) { CLog::Log(LOGERROR, "%s - exception",__FUNCTION__); status = kVDADecoderDecoderFailedErr; } CFRelease(decoderConfiguration); CFRelease(destinationImageBufferAttributes); if (status != kVDADecoderNoErr) { if (status == kVDADecoderDecoderFailedErr) CLog::Log(LOGNOTICE, "%s - VDADecoder Codec failed to open, currently in use by another process", __FUNCTION__); else CLog::Log(LOGNOTICE, "%s - VDADecoder Codec failed to open, status(%d), profile(%d), level(%d)", __FUNCTION__, (int)status, profile, level); return false; } m_DropPictures = false; m_max_ref_frames = std::max(m_max_ref_frames + 1, 5); m_sort_time = 0; return true; } return false; }
bool CMusicInfoTagLoaderSid::Load(const CStdString& strFileName, CMusicInfoTag& tag) { CStdString strFileToLoad = strFileName; int iTrack = 0; CStdString strExtension; CUtil::GetExtension(strFileName,strExtension); strExtension.MakeLower(); if (strExtension==".sidstream") { // Extract the track to play CStdString strFile=CUtil::GetFileName(strFileName); int iStart=strFile.ReverseFind("-")+1; iTrack = atoi(strFile.substr(iStart, strFile.size()-iStart-10).c_str()); // The directory we are in, is the file // that contains the bitstream to play, // so extract it CStdString strPath=strFileName; CUtil::GetDirectory(strPath, strFileToLoad); CUtil::RemoveSlashAtEnd(strFileToLoad); // we want the filename } CStdString strFileNameLower(strFileToLoad); strFileNameLower.MakeLower(); int iHVSC = strFileNameLower.find("hvsc"); // need hvsc in path name since our lookupfile is based on hvsc paths if (iHVSC < 0) { iHVSC = strFileNameLower.find("c64music"); if (iHVSC >= 0) iHVSC += 8; } else iHVSC += 4; if( iHVSC < 0 ) { tag.SetLoaded(false); return( false ); } CStdString strHVSCpath = strFileToLoad.substr(iHVSC,strFileToLoad.length()-1); strHVSCpath.Replace('\\','/'); // unix paths strHVSCpath.MakeLower(); char temp[8192]; CRegExp reg; if (!reg.RegComp("TITLE: ([^\r\n]*)\r?\n[^A]*ARTIST: ([^\r\n]*)\r?\n")) { CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..): failed to compile regular expression"); tag.SetLoaded(false); return( false ); } sprintf(temp,"%s\\%s",g_settings.GetDatabaseFolder().c_str(),"stil.txt"); // changeme? std::ifstream f(temp); if( !f.good() ) { CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..) unable to locate stil.txt"); tag.SetLoaded(false); return( false ); } const char* szStart = NULL; const char* szEnd = NULL; char temp2[8191]; char* temp3 = temp2; while( !f.eof() && !szEnd ) { f.read(temp,8191); CStdString strLower = temp; strLower.MakeLower(); if (!szStart) szStart= (char *)strstr(strLower.c_str(),strHVSCpath.c_str()); if (szStart) { szEnd = strstr(szStart+strHVSCpath.size(),".sid"); if (szEnd) { memcpy(temp3,temp+(szStart-strLower.c_str()),szEnd-szStart); temp3 += szEnd-szStart; } else { memcpy(temp3,temp+(szStart-strLower.c_str()),strlen(szStart)); szStart = NULL; temp3 += strlen(szStart); } } } f.close(); if (!f.eof() && szEnd) { temp2[temp3-temp2] = '\0'; temp3 = strstr(temp2,"TITLE:"); } else temp3 = NULL; if (temp3) { for (int i=0;i<iTrack-1;++i) // skip tracks { int iStart = reg.RegFind(temp3); if (!iStart) { tag.SetLoaded(false); return false; } temp3 += iStart; } if(reg.RegFind(temp3) > -1) { char* szTitle = reg.GetReplaceString("\\1"); char* szArtist = reg.GetReplaceString("\\2"); char* szMins = NULL; char* szSecs = NULL; CRegExp reg2; reg2.RegComp("(.*) \\(([0-9]*):([0-9]*)\\)"); if (reg2.RegFind(szTitle) > -1) { szMins = reg2.GetReplaceString("\\2"); szSecs = reg2.GetReplaceString("\\3"); char* szTemp = reg2.GetReplaceString("\\1"); free(szTitle); szTitle = szTemp; } tag.SetLoaded(true); tag.SetURL(strFileToLoad); tag.SetTrackNumber(iTrack); if (szMins && szSecs) tag.SetDuration(atoi(szMins)*60+atoi(szSecs)); tag.SetTitle(szTitle); tag.SetArtist(szArtist); if( szTitle ) free(szTitle); if( szArtist ) free(szArtist); if( szMins ) free(szMins); if( szSecs ) free(szSecs); } } sprintf(temp,"%s\\%s",g_settings.GetDatabaseFolder().c_str(),"sidlist.csv"); // changeme? std::ifstream f2(temp); if( !f2.good() ) { CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..) unable to locate sidlist.csv"); tag.SetLoaded(false); return( false ); } while( !f2.eof() ) { f2.getline(temp,8191); CStdString strTemp(temp); strTemp.MakeLower(); unsigned int iFind = strTemp.find(strHVSCpath); if (iFind == string::npos) continue; char temp2[1024]; char temp3[1024]; strncpy(temp3,temp+iFind,strlen(strHVSCpath)); temp3[strlen(strHVSCpath)] = '\0'; sprintf(temp2,"\"%s\",\"[^\"]*\",\"[^\"]*\",\"([^\"]*)\",\"([^\"]*)\",\"([0-9]*)[^\"]*\",\"[0-9]*\",\"[0-9]*\",\"",temp3); for (int i=0;i<iTrack-1;++i) strcat(temp2,"[0-9]*:[0-9]* "); strcat(temp2,"([0-9]*):([0-9]*)"); if( !reg.RegComp(temp2) ) { CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..): failed to compile regular expression"); tag.SetLoaded(false); return( false ); } if( reg.RegFind(temp) >= 0 ) { char* szTitle = reg.GetReplaceString("\\1"); char* szArtist = reg.GetReplaceString("\\2"); char* szYear = reg.GetReplaceString("\\3"); char* szMins = reg.GetReplaceString("\\4"); char* szSecs = reg.GetReplaceString("\\5"); tag.SetLoaded(true); tag.SetTrackNumber(iTrack); if (tag.GetDuration() == 0) tag.SetDuration(atoi(szMins)*60+atoi(szSecs)); if (tag.GetTitle() == "") tag.SetTitle(szTitle); if (tag.GetArtist() == "") tag.SetArtist(szArtist); SYSTEMTIME dateTime; dateTime.wYear = atoi(szYear); tag.SetReleaseDate(dateTime); if( szTitle ) free(szTitle); if( szArtist ) free(szArtist); if( szYear ) free(szYear); if( szMins ) free(szMins); if( szSecs ) free(szSecs); f2.close(); return( true ); } } f2.close(); tag.SetLoaded(false); return( false ); }
CStdString GetIPV6LongForm(CStdString short_address) { if (short_address[0] == '[') { if (short_address[short_address.GetLength() - 1] != ']') return _T(""); short_address = short_address.Mid(1, short_address.GetLength() - 2); } short_address.MakeLower(); TCHAR buffer[40] = { '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', ':', '0', '0', '0', '0', 0 }; TCHAR* out = buffer; const unsigned int len = short_address.GetLength(); if (len > 39) return _T(""); // First part, before possible :: unsigned int i = 0; unsigned int grouplength = 0; for (i = 0; i < len + 1; i++) { const TCHAR& c = short_address[i]; if (c == ':' || !c) { if (!grouplength) { // Empty group length, not valid if (!c || short_address[i + 1] != ':') return _T(""); i++; break; } out += 4 - grouplength; for (unsigned int j = grouplength; j > 0; j--) *out++ = short_address[i - j]; // End of string... if (!c) { if (!*out) // ...on time return buffer; else // ...premature return _T(""); } else if (!*out) { // Too long return _T(""); } out++; grouplength = 0; if (short_address[i + 1] == ':') { i++; break; } continue; } else if ((c < '0' || c > '9') && (c < 'a' || c > 'f')) { // Invalid character return _T(""); } // Too long group if (++grouplength > 4) return _T(""); } // Second half after :: TCHAR* end_first = out; out = &buffer[38]; unsigned int stop = i; for (i = len - 1; i > stop; i--) { if (out < end_first) { // Too long return _T(""); } const TCHAR& c = short_address[i]; if (c == ':') { if (!grouplength) { // Empty group length, not valid return _T(""); } out -= 5 - grouplength; grouplength = 0; continue; } else if ((c < '0' || c > '9') && (c < 'a' || c > 'f')) { // Invalid character return _T(""); } // Too long group if (++grouplength > 4) return _T(""); *out-- = c; } if (!grouplength && stop + 1 < len) { // Empty group length, not valid return _T(""); } out -= 5 - grouplength; out += 2; int diff = out - end_first; if (diff < 0 || diff % 5) return _T(""); return buffer; }
HANDLE FindFirstFile(LPCSTR szPath,LPWIN32_FIND_DATA lpFindData) { if (lpFindData == NULL || szPath == NULL) return NULL; CStdString strPath(szPath); if (strPath.empty()) return INVALID_HANDLE_VALUE; strPath.Replace("\\","/"); // if the file name is a directory then we add a * to look for all files in this directory DIR *testDir = opendir(szPath); if (testDir) { strPath += "/*"; closedir(testDir); } int nFilePos = strPath.ReverseFind(XBMC_FILE_SEP); CStdString strDir = "."; CStdString strFiles = strPath; if (nFilePos > 0) { strDir = strPath.substr(0,nFilePos); strFiles = strPath.substr(nFilePos + 1); } if (strFiles == "*.*") strFiles = "*"; strFiles = CStdString("^") + strFiles + "$"; strFiles.Replace(".","\\."); strFiles.Replace("*",".*"); strFiles.Replace("?","."); strFiles.MakeLower(); int status; regex_t re; if (regcomp(&re, strFiles, REG_EXTENDED|REG_NOSUB) != 0) { return(INVALID_HANDLE_VALUE); } struct dirent **namelist = NULL; int n = scandir(strDir, &namelist, 0, alphasort); CXHandle *pHandle = new CXHandle(CXHandle::HND_FIND_FILE); pHandle->m_FindFileDir = strDir; while (n-- > 0) { CStdString strComp(namelist[n]->d_name); strComp.MakeLower(); status = regexec(&re, strComp.c_str(), (size_t) 0, NULL, 0); if (status == 0) { pHandle->m_FindFileResults.push_back(namelist[n]->d_name); } free(namelist[n]); } if (namelist) free(namelist); regfree(&re); if (pHandle->m_FindFileResults.size() == 0) { delete pHandle; return INVALID_HANDLE_VALUE; } FindNextFile(pHandle, lpFindData); return pHandle; }
HANDLE FindFirstFile(LPCSTR szPath,LPWIN32_FIND_DATA lpFindData) { if (lpFindData == NULL || szPath == NULL) return NULL; CStdString strPath(szPath); if (IsAliasShortcut(strPath)) TranslateAliasShortcut(strPath); if (strPath.empty()) return INVALID_HANDLE_VALUE; strPath.Replace("\\","/"); // if the file name is a directory then we add a * to look for all files in this directory #if defined(__APPLE__) || defined(__FreeBSD__) DIR *testDir = opendir(strPath.c_str()); #else DIR *testDir = opendir(szPath); #endif if (testDir) { strPath += "/*"; closedir(testDir); } int nFilePos = strPath.ReverseFind(XBMC_FILE_SEP); CStdString strDir = "."; CStdString strFiles = strPath; if (nFilePos > 0) { strDir = strPath.substr(0,nFilePos); strFiles = strPath.substr(nFilePos + 1); } if (strFiles == "*.*") strFiles = "*"; strFiles = CStdString("^") + strFiles + "$"; strFiles.Replace(".","\\."); strFiles.Replace("*",".*"); strFiles.Replace("?","."); strFiles.MakeLower(); // Do we really want this case insensitive? CRegExp re(true); if (re.RegComp(strFiles.c_str()) == NULL) return(INVALID_HANDLE_VALUE); struct dirent **namelist = NULL; int n = scandir(strDir, &namelist, 0, alphasort); CXHandle *pHandle = new CXHandle(CXHandle::HND_FIND_FILE); pHandle->m_FindFileDir = strDir; while (n-- > 0) { CStdString strComp(namelist[n]->d_name); strComp.MakeLower(); if (re.RegFind(strComp.c_str()) >= 0) pHandle->m_FindFileResults.push_back(namelist[n]->d_name); free(namelist[n]); } free(namelist); if (pHandle->m_FindFileResults.size() == 0) { delete pHandle; return INVALID_HANDLE_VALUE; } FindNextFile(pHandle, lpFindData); return pHandle; }
bool CMetadataResolverMusic::GetMetadataFromAMG(const CStdString& _strAlbum, const CStdString& _strArtist,MUSIC_GRABBER::CMusicAlbumInfo& album) { CStdString strAlbum = _strAlbum; strAlbum = strAlbum.ToLower(); CStdString strArtist = _strArtist; strArtist = strArtist.ToLower(); // This function can resolve by album only, so we do not care about the artist at this point if (strAlbum.IsEmpty() || strArtist.IsEmpty()) return false; SScraperInfo info; info.strPath = "allmusic.xml"; info.strContent = "albums"; int iRetries = 2; while (iRetries-- > 0) { MUSIC_GRABBER::CMusicInfoScraper scraper(info); scraper.SetAlbum(strAlbum); scraper.SetArtist(strArtist); scraper.FindAlbuminfo(); scraper.LoadAlbuminfo(); int iSelectedAlbum = 0; while (!scraper.Completed() && !scraper.IsCanceled()) { if (m_bStopped) { if (!scraper.IsCanceled()) { //CLog::Log(LOGDEBUG, "LIBRARY: Boxee Metadata Resolver, Canceling scraper"); scraper.Cancel(); break; } } Sleep(200); } if (scraper.Successfull() && scraper.GetAlbumCount() > 0) { // did we found at least 1 album? int iAlbumCount = scraper.GetAlbumCount(); if (iAlbumCount >= 1) { if (iAlbumCount > 1) { int bestMatch = -1; double minRelevance; minRelevance = 0.7; double bestRelevance = 0; double secondBestRelevance = 0; for (int i = 0; i < iAlbumCount; ++i) { MUSIC_GRABBER::CMusicAlbumInfo& info = scraper.GetAlbum(i); CStdString strFoundAlbum = info.GetAlbum().strAlbum; strFoundAlbum.MakeLower(); CStdString strFoundArtist = info.GetAlbum().strArtist; strFoundArtist.MakeLower(); bool bFoundSoundtrack = false; if ((strFoundAlbum.Find("soundtrack") != -1) || (strFoundArtist.Find("soundtrack") != -1)) { bFoundSoundtrack = true; // reset found artist in order to avoid artist comparison strFoundArtist = ""; //strFoundAlbum = CleanAlbumName(strFoundAlbum); // check if we can remove the "[original soundtrack]" token int pos = strFoundAlbum.Find("[original soundtrack]"); if (pos != -1) { strFoundAlbum.erase(pos, 21); } else { // try to remove words separately int pos1 = strFoundAlbum.Find("soundtrack"); if (pos1 != -1) { strFoundAlbum.erase(pos1, 10); } int pos2 = strFoundAlbum.Find("original"); if (pos2 != -1) { strFoundAlbum.erase(pos2, 8); } } } // TODO: Check if originally we were looking for a soundtrack // Check if we need a sound track // if (pContext->bIsSoundtrack && !bFoundSoundtrack) // { // continue; // } double relevance = CUtil::AlbumRelevance(strFoundAlbum, strAlbum, strFoundArtist, strArtist); // if we're doing auto-selection (ie querying all albums at once, then allow 95->100% for perfect matches) // otherwise, perfect matches only if (relevance >= std::max(minRelevance, bestRelevance)) { // we auto-select the best of these secondBestRelevance = bestRelevance; bestRelevance = relevance; bestMatch = i; } } if (bestMatch > -1 && bestRelevance != secondBestRelevance) { // autochoose the single best matching item iSelectedAlbum = bestMatch; } else { // nothing found, or two equal matches to choose from // perform additional checks return false; } } } else { return false; } MUSIC_GRABBER::CMusicAlbumInfo info = scraper.GetAlbum(iSelectedAlbum); // Save album and artist names as they get erased in the process CStdString strTempAlbumName = info.GetAlbum().strAlbum; CStdString strTempArtistName = info.GetAlbum().strArtist; scraper.LoadAlbuminfo(iSelectedAlbum); while (!scraper.Completed() && !scraper.IsCanceled()) { // if (m_bStopped) // { // if (!scraper.IsCanceled()) { // scraper.Cancel(); // } // } Sleep(200); } if (!scraper.IsCanceled() && scraper.Successfull()) { album = scraper.GetAlbum(iSelectedAlbum); // Restore erased fields album.GetAlbum().strAlbum = strTempAlbumName; album.GetAlbum().strArtist = strTempArtistName; return true; } else { if (scraper.HadNetworkProblems()) { Sleep(500); continue; } return false; } } else { if (scraper.HadNetworkProblems()) { Sleep(500); continue; } return false; } } // while retries return false; }