2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "MusicDatabaseFile.h"
22 #include "music/MusicDatabase.h"
24 #include "utils/StringUtils.h"
25 #include "utils/URIUtils.h"
29 using namespace XFILE;
31 CMusicDatabaseFile::CMusicDatabaseFile(void)
35 CMusicDatabaseFile::~CMusicDatabaseFile(void)
40 CStdString CMusicDatabaseFile::TranslateUrl(const CURL& url)
42 CMusicDatabase musicDatabase;
43 if (!musicDatabase.Open())
46 CStdString strFileName=URIUtils::GetFileName(url.Get());
47 CStdString strExtension = URIUtils::GetExtension(strFileName);
48 URIUtils::RemoveExtension(strFileName);
50 if (!StringUtils::IsNaturalNumber(strFileName))
53 long idSong=atol(strFileName.c_str());
56 if (!musicDatabase.GetSong(idSong, song))
59 StringUtils::ToLower(strExtension);
60 if (!URIUtils::HasExtension(song.strFileName, strExtension))
63 return song.strFileName;
66 bool CMusicDatabaseFile::Open(const CURL& url)
68 return m_file.Open(TranslateUrl(url));
71 bool CMusicDatabaseFile::Exists(const CURL& url)
73 return !TranslateUrl(url).empty();
76 int CMusicDatabaseFile::Stat(const CURL& url, struct __stat64* buffer)
78 return m_file.Stat(TranslateUrl(url), buffer);
81 unsigned int CMusicDatabaseFile::Read(void* lpBuf, int64_t uiBufSize)
83 return m_file.Read(lpBuf, uiBufSize);
86 int64_t CMusicDatabaseFile::Seek(int64_t iFilePosition, int iWhence /*=SEEK_SET*/)
88 return m_file.Seek(iFilePosition, iWhence);
91 void CMusicDatabaseFile::Close()
96 int64_t CMusicDatabaseFile::GetPosition()
98 return m_file.GetPosition();
101 int64_t CMusicDatabaseFile::GetLength()
103 return m_file.GetLength();