Example #1
0
 String getCacheThumbName(const String& path)
 {
   XBMC_TRACE;
   Crc32 crc;
   crc.ComputeFromLowerCase(path);
   return StringUtils::Format("%08x.tbn", (unsigned __int32)crc);
 }
Example #2
0
CStdString CTextureCache::GetCacheFile(const CStdString &url)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(url);
  CStdString hex = StringUtils::Format("%08x", (unsigned int)crc);
  CStdString hash = StringUtils::Format("%c/%s", hex[0], hex.c_str());
  return hash;
}
bool CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer->HasPlayer() )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.clear();

  bookmark.player = CPlayerCoreFactory::GetInstance().GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > (int)BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
#ifdef HAS_VIDEO_PLAYBACK
    CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture();

    if (thumbnail)
    {
      g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY);

#if !defined(HAS_LIBAMCODEC)
      if (thumbnail->GetUserState() == CAPTURESTATE_DONE)
      {
#else//HAS_LIBAMCODEC
      {
        CScreenshotAML::CaptureVideoFrame(thumbnail->GetPixels(), width, height, false);
#endif
        Crc32 crc;
        crc.ComputeFromLowerCase(g_application.CurrentFile());
        bookmark.thumbNailImage = StringUtils::Format("%08x_%i.jpg", (unsigned __int32) crc, (int)bookmark.timeInSeconds);
        bookmark.thumbNailImage = URIUtils::AddFileToFolder(CProfilesManager::GetInstance().GetBookmarksThumbFolder(), bookmark.thumbNailImage);
        if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4,
                                            bookmark.thumbNailImage))
          bookmark.thumbNailImage.clear();
      }
#if !defined(HAS_LIBAMCODEC)
      else
        CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail");
#endif

      g_renderManager.ReleaseRenderCapture(thumbnail);
    }
Example #4
0
TEST(TestCrc32, ComputeFromLowerCase)
{
    Crc32 a;
    uint32_t varcrc;
    CStdString s = refdata;
    a.ComputeFromLowerCase(s);
    varcrc = a;
    EXPECT_EQ((uint32_t)0x7f045b3e, varcrc);
}
Example #5
0
 String getCacheThumbName(const String& path)
 {
   TRACE;
   Crc32 crc;
   crc.ComputeFromLowerCase(path);
   CStdString strPath;
   strPath.Format("%08x.tbn", (unsigned __int32)crc);
   return strPath;
 }
Example #6
0
void CBackgroundInfoLoader::LoadCustomImages(CFileItem* pItem, bool bCanBlock)
{
  //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - Enter function with item [path=%s][label=%s]. [bCanBlock=%d] (custi)",(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
  
  for (int nImage=0; nImage < 10; nImage++)
  {
    CStdString strPropName;
    strPropName.Format("Image%d", nImage);
    if (!pItem->HasProperty(strPropName))
    {
      break;
    }
    
    CStdString strImagePath = pItem->GetProperty(strPropName);
    
    //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] Going to try and download property [%s] value [ImagePath=%s] for item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,strPropName.c_str(),strImagePath.c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);

    // Get path for cache picture
    Crc32 crc;
    crc.ComputeFromLowerCase(strImagePath);
    CStdString hex;
    hex.Format("%08x", (unsigned __int32) crc);
    CStdString cacheImagePath;
    cacheImagePath.Format("%s\\%c\\%s_image.tbn", g_settings.GetPicturesThumbFolder().c_str(), hex[0], hex.c_str());
    
    cacheImagePath = _P(cacheImagePath);
    
    //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] For image [ImagePath=%s] the cacheImagePath is [%s]. Item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,strImagePath.c_str(),cacheImagePath.c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);

    if(CFile::Exists(cacheImagePath))
    {
      // Picture exist in cache
      pItem->SetProperty(strPropName, cacheImagePath);
      
      //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] cacheImagePath [%s] already exist and was set to property [%s=%s]. item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,cacheImagePath.c_str(),strPropName.c_str(),(pItem->GetProperty(strPropName)).c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
    }
    else
    {
      // Picture doesn't exist in cache -> Need to download it
      
      BOXEE::BXCurl http;
      bool success = http.HttpDownloadFile(strImagePath,cacheImagePath,"");
      
      if(success)
      {
        pItem->SetProperty(strPropName, cacheImagePath);
        
        //CLog::Log(LOGDEBUG,"CBackgroundInfoLoader::LoadCustomImages - [%d] successed downloading image. cacheImagePath [%s]  was set to property [%s=%s]. item [path=%s][label=%s]. [bCanBlock=%d] (custi)",nImage,cacheImagePath.c_str(),strPropName.c_str(),(pItem->GetProperty(strPropName)).c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
      }
      else
      {
        CLog::Log(LOGERROR,"CBackgroundInfoLoader::LoadCustomImages - [%d] Failed to download [ImagePath=%s] for item [path=%s][label=%s]. [bCanBlock=%d] (pthumb)(custi)",nImage,strImagePath.c_str(),(pItem->m_strPath).c_str(),(pItem->GetLabel()).c_str(),bCanBlock);
      }
    }
  }  
}
Example #7
0
TEST(TestCrc32, Reset)
{
    Crc32 a;
    uint32_t varcrc;
    CStdString s = refdata;
    a.ComputeFromLowerCase(s);
    a.Reset();
    varcrc = a;
    EXPECT_EQ(0xffffffff, varcrc);
}
Example #8
0
CStdString CTextureCache::GetUniqueImage(const CStdString &url, const CStdString &extension)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(url);
  CStdString hex;
  hex.Format("%08x", (unsigned int)crc);
  CStdString hash;
  hash.Format("generated/%c/%s%s", hex[0], hex.c_str(), extension.c_str());
  return GetCachedPath(hash);
}
CStdString CTextureCache::GetCacheFile(const CStdString &url)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(url);
  CStdString hex;
  hex.Format("%08x", (unsigned int)crc);
  CStdString hash;
  hash.Format("%c/%s%s", hex[0], hex.c_str(), CUtil::GetExtension(url).c_str());
  return hash;
}
Example #10
0
void CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.Empty();

  bookmark.player = CPlayerCoreFactory::GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
#ifdef HAS_VIDEO_PLAYBACK
    CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture();
    g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY);
    if (thumbnail->GetUserState() == CAPTURESTATE_DONE)
    {
      Crc32 crc;
      crc.ComputeFromLowerCase(g_application.CurrentFile());
      bookmark.thumbNailImage.Format("%08x_%i.jpg", (unsigned __int32) crc, m_vecItems->Size() + 1);
      bookmark.thumbNailImage = URIUtils::AddFileToFolder(g_settings.GetBookmarksThumbFolder(), bookmark.thumbNailImage);
      if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4,
                                          bookmark.thumbNailImage))
        bookmark.thumbNailImage.Empty();
    }
    else
      CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail");

    g_renderManager.ReleaseRenderCapture(thumbnail);
#endif
  }
  videoDatabase.Open();
  if (tag)
    videoDatabase.AddBookMarkForEpisode(*tag, bookmark);
  else
    videoDatabase.AddBookMarkToFile(g_application.CurrentFile(), bookmark, CBookmark::STANDARD);
  videoDatabase.Close();
  Update();
}
Example #11
0
void CMusicDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
{
  CStdString path = CLegacyPathTranslation::TranslateMusicDbPath(strDirectory);
  URIUtils::RemoveSlashAtEnd(path);

  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString strFileName = StringUtils::Format("special://temp/%08x.fi", (unsigned __int32) crc);
  CFile::Delete(strFileName);
}
Example #12
0
CStdString CThumbnailCache::GetMusicThumb(const CStdString& path)
{
  Crc32 crc;
  CStdString noSlashPath(path);
  URIUtils::RemoveSlashAtEnd(noSlashPath);
  crc.ComputeFromLowerCase(noSlashPath);
  CStdString hex;
  hex.Format("%08x", (unsigned __int32) crc);
  CStdString thumb;
  thumb.Format("%c/%s.tbn", hex[0], hex.c_str());
  return URIUtils::AddFileToFolder(g_settings.GetMusicThumbFolder(), thumb);
}
void CVideoDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
{
  CStdString path(strDirectory);
  URIUtils::RemoveSlashAtEnd(path);

  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString strFileName;
  strFileName.Format("special://temp/%08x.fi", (unsigned __int32) crc);
  CFile::Delete(strFileName);
}
void CMusicDatabaseDirectory::ClearDirectoryCache(const CStdString& strDirectory)
{
  CFileItem directory(strDirectory, true);
  if (CUtil::HasSlashAtEnd(directory.m_strPath))
    directory.m_strPath.Delete(directory.m_strPath.size() - 1);

  Crc32 crc;
  crc.ComputeFromLowerCase(directory.m_strPath);

  CStdString strFileName;
  strFileName.Format("Z:\\%08x.fi", (unsigned __int32) crc);
  CFile::Delete(_P(strFileName));
}
Example #15
0
CStdString CThumbnailCache::GetMusicThumbHashPath(const CStdString &path, bool split) {
  Crc32 crc;
  crc.ComputeFromLowerCase(path);
  CStdString thumb;
  if (split) {
    CStdString hex;
    hex.Format("%08x", (__int32)crc);
    thumb.Format("%s\\%c\\%08x.tbn", g_settings.GetMusicThumbFolder(), hex[0], (unsigned __int32)crc);
  } else {
    thumb.Format("%s\\%08x.tbn", g_settings.GetMusicThumbFolder(), (unsigned __int32)crc);
  }
  return thumb;
}
Example #16
0
void CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.Empty();

  bookmark.player = CPlayerCoreFactory::GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
    CSingleLock lock(g_graphicsContext);
    // we're really just using the CTexture here as a pixel buffer
    CTexture texture(width, height, XB_FMT_B8G8R8A8);
#ifdef HAS_VIDEO_PLAYBACK
    //g_renderManager.CreateThumbnail(&texture, width, height);
#endif
    Crc32 crc;
    crc.ComputeFromLowerCase(g_application.CurrentFile());
    bookmark.thumbNailImage.Format("%08x_%i.jpg", (unsigned __int32) crc, m_vecItems->Size() + 1);
    bookmark.thumbNailImage = CUtil::AddFileToFolder(g_settings.GetBookmarksThumbFolder(), bookmark.thumbNailImage);
    if (!CPicture::CreateThumbnailFromSurface(texture.GetPixels(), width, height, texture.GetPitch(),
                                        bookmark.thumbNailImage))
      bookmark.thumbNailImage.Empty();
  }
  videoDatabase.Open();
  if (tag)
    videoDatabase.AddBookMarkForEpisode(*tag, bookmark);
  else
    videoDatabase.AddBookMarkToFile(g_application.CurrentFile(), bookmark, CBookmark::STANDARD);
  videoDatabase.Close();
  Update();
}
Example #17
0
  PyObject* XBMC_GetCacheThumbName(PyObject *self, PyObject *args)
  {
    PyObject *pObjectText;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText)) return NULL;
 
    string strText;
    if (!PyGetUnicodeString(strText, pObjectText, 1)) return NULL;

    Crc32 crc;
    CStdString strPath;
    crc.ComputeFromLowerCase(strText);
    strPath.Format("%08x.tbn", (unsigned __int32)crc);
    return Py_BuildValue((char*)"s", strPath.c_str());
  }
Example #18
0
void CLastFmManager::CacheTrackThumb(const int nrInitialTracksToAdd)
{
  unsigned int start = CTimeUtils::GetTimeMS();
  CSingleLock lock(m_lockCache);
  int iNrCachedTracks = m_RadioTrackQueue->size();
  CFileCurl http;
  for (int i = 0; i < nrInitialTracksToAdd && i < iNrCachedTracks; i++)
  {
    CFileItemPtr item = (*m_RadioTrackQueue)[i];
    if (!item->GetMusicInfoTag()->Loaded())
    {
      //cache albumthumb, GetThumbnailImage contains the url to cache
      if (item->HasThumbnail())
      {
        CStdString coverUrl = item->GetThumbnailImage();
        CStdString crcFile;
        CStdString cachedFile;
        CStdString thumbFile;

        Crc32 crc;
        crc.ComputeFromLowerCase(coverUrl);
        crcFile.Format("%08x.tbn", (__int32)crc);
        URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, crcFile, cachedFile);
        URIUtils::AddFileToFolder(g_settings.GetLastFMThumbFolder(), crcFile, thumbFile);
        item->SetThumbnailImage("");
        try
        {
          //download to temp, then make a thumb
          if (CFile::Exists(thumbFile) || (http.Download(coverUrl, cachedFile) && CPicture::CreateThumbnail(cachedFile, thumbFile)))
          {
            if (CFile::Exists(cachedFile))
              CFile::Delete(cachedFile);
            item->SetThumbnailImage(thumbFile);
          }
        }
        catch(...)
        {
          CLog::Log(LOGERROR, "LastFmManager: exception while caching %s to %s.", coverUrl.c_str(), thumbFile.c_str());
        }
      }
      if (!item->HasThumbnail())
      {
        item->SetThumbnailImage("DefaultAlbumCover.png");
      }
      item->GetMusicInfoTag()->SetLoaded();
    }
  }
  CLog::Log(LOGDEBUG, "%s: Done (time: %i ms)", __FUNCTION__, (int)(CTimeUtils::GetTimeMS() - start));
}
Example #19
0
char* Interface_Filesystem::get_cache_thumb_name(void* kodiBase, const char* filename)
{
  CAddonDll* addon = static_cast<CAddonDll*>(kodiBase);
  if (addon == nullptr || filename == nullptr)
  {
    CLog::Log(LOGERROR, "Interface_Filesystem::%s - invalid data (addon='%p', filename='%p)", __FUNCTION__, kodiBase, filename);
    return nullptr;
  }

  Crc32 crc;
  crc.ComputeFromLowerCase(filename);
  std::string string = StringUtils::Format("%08x.tbn", static_cast<unsigned int>(crc));
  char* buffer = strdup(string.c_str());
  return buffer;
}
Example #20
0
CStdString CEdenVideoArtUpdater::GetThumb(const CStdString &path, const CStdString &path2, bool split)
{
  // get the locally cached thumb
  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString thumb;
  if (split)
  {
    CStdString hex = StringUtils::Format("%08x", (__int32)crc);
    thumb = StringUtils::Format("%c\\%08x.tbn", hex[0], (unsigned __int32)crc);
  }
  else
    thumb = StringUtils::Format("%08x.tbn", (unsigned __int32)crc);

  return URIUtils::AddFileToFolder(path2, thumb);
}
Example #21
0
CStdString CThumbnailCache::GetThumb(const CStdString &path, const CStdString &path2, bool split /* = false */)
{
  // get the locally cached thumb
  Crc32 crc;
  crc.ComputeFromLowerCase(path);

  CStdString thumb;
  if (split)
  {
    CStdString hex;
    hex.Format("%08x", (__int32)crc);
    thumb.Format("%c\\%08x.tbn", hex[0], (unsigned __int32)crc);
  }
  else
    thumb.Format("%08x.tbn", (unsigned __int32)crc);

  return URIUtils::AddFileToFolder(path2, thumb);
}
Example #22
0
bool CRSSDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
  CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - path [%s]", strPath.c_str());

  m_cacheDirectory = DIR_CACHE_ALWAYS;

  CStdString strURL = strPath;
  CStdString newURL;

  CStdString strRoot = strPath;
  if (CUtil::HasSlashAtEnd(strRoot))
    strRoot.Delete(strRoot.size() - 1);

  // If we have the items in the cache, return them
  if (g_directoryCache.GetDirectory(strRoot, items))
  {
    return true;
  }

  // Remove the rss:// prefix and replace it with http://
  if (strURL.Left(7) == "http://")
  {
    newURL = strURL;
  }
  else
  {
    strURL.Delete(0,6);
    
    // if first symbol is '/', we have local file
    if (strURL.Left(1) == "/")
    {
      newURL = "file://";
    }
    else 
    {
      newURL = "http://";
    }
    newURL = newURL + strURL;
  }
  
  // Remove the last slash
  if (CUtil::HasSlashAtEnd(newURL))
  {
    CUtil::RemoveSlashAtEnd(newURL);
  }

  // Create new thread and run the feed retreival from it
  // In order to allow progress dialog and cancel operation

  m_strUrl = newURL;

  Crc32 crc;
  crc.ComputeFromLowerCase(newURL);

  CStdString strLocalFile;
  strLocalFile.Format("special://temp/rss-%08x-%lu.xml", (unsigned __int32)crc, CTimeUtils::GetTimeMS());

  CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - going to load url [%s] to file [%s]", newURL.c_str(), strLocalFile.c_str());

  if (!BOXEE::Boxee::GetInstance().AsyncLoadUrl(newURL, _P(strLocalFile), "rss-load", NULL))
  {
    CGUIDialogOK::ShowAndGetInput(51014,0,0,0);
    return false;
  }

  SDL_LockMutex(m_pOpFinishedMutex);
  int result = SDL_CondWaitTimeout(m_pOpFinishedCond,m_pOpFinishedMutex,REQUEST_WAIT_PERIOD);
  SDL_UnlockMutex(m_pOpFinishedMutex);

  m_feed.GetItemList(items);

  if (result != 0)
  {
    m_cacheDirectory = DIR_CACHE_NEVER;
    // set this property so that the UI will handle the timeout
    CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory, loading timed out, path [%s] loaded:%d out of %d", strPath.c_str(), items.Size(),items.GetPageContext().m_itemsPerPage);
    items.SetProperty("isRequestTimedOut",true);
  }

  CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - done loading url, got [%d] items (result=[%d])",items.Size(),result);

  if (items.Size() == 0)
  {
    m_cacheDirectory = DIR_CACHE_NEVER;
    return true;
  }
  else
  {
    CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - Going to add [DefaultSortLabel] property to each item. [path=%s][NumOfItems=%d] (vns)",strPath.c_str(),items.Size());

    for(int i=0; i<items.Size(); i++)
    {
      CFileItemPtr item = items[i];

      char pos[5];
      sprintf(pos,"%d",i+1);

      item->SetProperty("DefaultSortLabel",pos);
 
      //CLog::Log(LOGDEBUG,"CRSSDirectory::GetDirectory - For item [path=%s] set property [DefaultSortLabel=%s] (vns)", (item->m_strPath).c_str(),(item->GetProperty("DefaultSortLabel")).c_str());
    }

    items.SetProperty("preferredsortmethod", SORT_METHOD_DEFAULT);
    items.SetProperty("preferredsortorder", SORT_ORDER_ASC);
  }

  return true;
}
Example #23
0
uint32_t CDatabase::ComputeCRC(const CStdString &text)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(text);
  return crc;
}
Example #24
0
DWORD CDatabase::ComputeCRC(const CStdString &text)
{
  Crc32 crc;
  crc.ComputeFromLowerCase(text);
  return (DWORD)crc;
}
bool CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag)
{
  CVideoDatabase videoDatabase;
  CBookmark bookmark;
  bookmark.timeInSeconds = (int)g_application.GetTime();
  bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime();

  if( g_application.m_pPlayer->HasPlayer() )
    bookmark.playerState = g_application.m_pPlayer->GetPlayerState();
  else
    bookmark.playerState.clear();

  bookmark.player = CPlayerCoreFactory::Get().GetPlayerName(g_application.GetCurrentPlayer());

  // create the thumbnail image
#ifdef HAS_VIDEO_PLAYBACK
  float aspectRatio = g_renderManager.GetAspectRatio();
#else
  float aspectRatio = 1.0f;
#endif
  int width = BOOKMARK_THUMB_WIDTH;
  int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio);
  if (height > (int)BOOKMARK_THUMB_WIDTH)
  {
    height = BOOKMARK_THUMB_WIDTH;
    width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio);
  }
  {
#ifdef HAS_VIDEO_PLAYBACK
    CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture();

    if (thumbnail)
    {
      g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY);

      if (thumbnail->GetUserState() == CAPTURESTATE_DONE)
      {
        Crc32 crc;
        crc.ComputeFromLowerCase(g_application.CurrentFile());
        bookmark.thumbNailImage = StringUtils::Format("%08x_%i.jpg", (unsigned __int32) crc, (int)bookmark.timeInSeconds);
        bookmark.thumbNailImage = URIUtils::AddFileToFolder(CProfilesManager::Get().GetBookmarksThumbFolder(), bookmark.thumbNailImage);
        if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4,
                                            bookmark.thumbNailImage))
          bookmark.thumbNailImage.clear();
      }
      else
        CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail");

      g_renderManager.ReleaseRenderCapture(thumbnail);
    }
#endif
  }
  videoDatabase.Open();
  if (tag)
    videoDatabase.AddBookMarkForEpisode(*tag, bookmark);
  else
  {
    std::string path = g_application.CurrentFile();
    if (g_application.CurrentFileItem().HasProperty("original_listitem_url") && 
       !URIUtils::IsVideoDb(g_application.CurrentFileItem().GetProperty("original_listitem_url").asString()))
      path = g_application.CurrentFileItem().GetProperty("original_listitem_url").asString();
    videoDatabase.AddBookMarkToFile(path, bookmark, CBookmark::STANDARD);
  }
  videoDatabase.Close();
  return true;
}