Repository: xbmc/xbmc
File: xbmc/FileItem.cpp (C++)

Code before:
* for CFileItem objects, or at least restricted to essentially be equivalent
* to construction. This would require re-formulating a bunch of CFileItem
* construction, and also allowing CFileItemList to have its own (public)
* SetURL() function, so for now we give direct access.
*/
const std::string& CFileItem::GetPath() const
{
  return m_strPath;
}

void CFileItem::SetPath(const std::string& path)
{
  m_strPath = path;
  m_curlPath.reset();
}

void CFileItem::SetURL(const CURL& url)
{
  m_strPath = url.Get();
  m_curlPath.reset();
}

const CURL CFileItem::GetURL() const
{
  if (!m_curlPath)
    const_cast<CFileItem*>(this)->m_curlPath = CURL(m_strPath);
  return *m_curlPath;
}

bool CFileItem::IsURL(const CURL& url) const
{
  return IsPath(url.Get());
}

bool CFileItem::IsPath(const std::string& path, bool ignoreURLOptions /* = false */) const
{
  return URIUtils::PathEquals(m_strPath, path, false, ignoreURLOptions);
}

void CFileItem::SetDynURL(const CURL& url)
{
  m_strDynPath = url.Get();
  m_curlDynPath.reset();
}

const CURL CFileItem::GetDynURL() const
{
  if (!m_strDynPath.empty())
  {
    if (!m_curlDynPath)
      const_cast<CFileItem*>(this)->m_curlDynPath = CURL(m_strDynPath);

Review comment (suggestion):
Wouldn't it make more sense to drop the `const` qualifier from the return type here instead since the object is copied anyway. Returning by const value doesn't make much sense

`const_cast` should be avoided.

Code after:
  {
    std::vector<CVariant> thumbs = CServiceBroker::GetSettingsComponent()->GetSettings()->GetList(
        CSettings::SETTING_MUSICLIBRARY_MUSICTHUMBS);
    for (const auto& i : thumbs)
    {
      std::string strFileName = i.asString();
      std::string folderThumb(ART::GetFolderThumb(*this, strFileName));
      if (CFile::Exists(folderThumb))   // folder.jpg
        return folderThumb;
      size_t period = strFileName.find_last_of('.');
      if (period != std::string::npos)
      {
        std::string ext;
        std::string name = strFileName;
        std::string folderThumb1 = folderThumb;
        name.erase(period);
        ext = strFileName.substr(period);
        StringUtils::ToUpper(ext);
        StringUtils::Replace(folderThumb1, strFileName, name + ext);
        if (CFile::Exists(folderThumb1)) // folder.JPG
          return folderThumb1;

        folderThumb1 = folderThumb;
        std::string firstletter = name.substr(0, 1);
        StringUtils::ToUpper(firstletter);
        name.replace(0, 1, firstletter);
        StringUtils::Replace(folderThumb1, strFileName, name + ext);
        if (CFile::Exists(folderThumb1)) // Folder.JPG
          return folderThumb1;

        folderThumb1 = folderThumb;
        StringUtils::ToLower(ext);
        StringUtils::Replace(folderThumb1, strFileName, name + ext);
        if (CFile::Exists(folderThumb1)) // Folder.jpg
          return folderThumb1;
      }
    }
  }
  // No thumb found
  return "";
}

bool CFileItem::SkipLocalArt() const
{
  return (m_strPath.empty() || StringUtils::StartsWithNoCase(m_strPath, "newsmartplaylist://") ||
          StringUtils::StartsWithNoCase(m_strPath, "newplaylist://") || m_bIsShareOrDrive ||
          NETWORK::IsInternetStream(*this) || URIUtils::IsUPnP(m_strPath) ||
          (URIUtils::IsFTP(m_strPath) &&
           !CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bFTPThumbs) ||
          IsPlugin() || IsAddonsPath() || IsLibraryFolder() || IsParentFolder() || IsLiveTV() ||
          IsPVRRecording() || IsDVD());