Skip to content

Commit

Permalink
CHG: refine destination filename when copying from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Oct 9, 2012
1 parent fb725b7 commit 4aa1bc7
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion xbmc/utils/FileOperationJob.cpp
Expand Up @@ -32,6 +32,9 @@
#include "guilib/LocalizeStrings.h"
#include "guilib/GUIWindowManager.h"
#include "dialogs/GUIDialogExtendedProgressBar.h"
#include "video/VideoInfoTag.h"
#include "music/tags/MusicInfoTag.h"
#include "utils/StringUtils.h"

#ifdef HAS_FILESYSTEM_RAR
#include "filesystem/RarManager.h"
Expand Down Expand Up @@ -163,7 +166,7 @@ bool CFileOperationJob::DoProcess(FileAction action, CFileItemList & items, cons
CURL::Decode(strFileName);

// special case for upnp
if (URIUtils::IsUPnP(items.GetPath()) || URIUtils::IsUPnP(pItem->GetPath()))
if ( URIUtils::IsUPnP(items.GetPath()) || URIUtils::IsUPnP(pItem->GetPath()) )
{
// get filename from label instead of path
strFileName = pItem->GetLabel();
Expand All @@ -178,6 +181,59 @@ bool CFileOperationJob::DoProcess(FileAction action, CFileItemList & items, cons
strFileName = CUtil::MakeLegalFileName(strFileName);
}

// special case for video db
if ( URIUtils::IsVideoDb(pItem->GetPath()) )
{
// Build filename
if (pItem->HasVideoInfoTag())
{
CVideoInfoTag* tag = pItem->GetVideoInfoTag();
if (tag->m_type == "movie")
{
strFileName.Format("%s (%d)", tag->m_strTitle, tag->m_iYear);
}
else if (tag->m_type == "episode")
{
strFileName.Format("%s - S%dE%d - %s", tag->m_strShowTitle, tag->m_iSeason, tag->m_iEpisode, tag->m_strTitle);
}
else if (tag->m_type == "musicvideo")
{
strFileName = tag->m_strTitle;
}
}
else
strFileName = pItem->GetLabel();

if(!pItem->m_bIsFolder && URIUtils::GetExtension(strFileName).length() == 0)
{
// FIXME: for now we only work well if the url has the extension
// we should map the content type to the extension otherwise
strFileName += URIUtils::GetExtension(pItem->GetPath());
}
strFileName = CUtil::MakeLegalFileName(strFileName);
}

// special case for music db
if ( URIUtils::IsMusicDb(pItem->GetPath()) )
{
// Build filename
if (pItem->HasMusicInfoTag())
{
MUSIC_INFO::CMusicInfoTag* tag = pItem->GetMusicInfoTag();
strFileName.Format("%s - %s - %d - %s", StringUtils::Join(tag->m_artist, "+"), tag->m_strAlbum, tag->m_iTrack, tag->m_strTitle);
}
else
strFileName = pItem->GetLabel();

if(!pItem->m_bIsFolder && URIUtils::GetExtension(strFileName).length() == 0)
{
// FIXME: for now we only work well if the url has the extension
// we should map the content type to the extension otherwise
strFileName += URIUtils::GetExtension(pItem->GetPath());
}
strFileName = CUtil::MakeLegalFileName(strFileName);
}

CStdString strnewDestFile;
if(!strDestFile.IsEmpty()) // only do this if we have a destination
URIUtils::AddFileToFolder(strDestFile, strFileName, strnewDestFile);
Expand Down

0 comments on commit 4aa1bc7

Please sign in to comment.