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 if (!URIUtils::HasExtension(song.strFileName, strExtension))
62 return song.strFileName;
65 bool CMusicDatabaseFile::Open(const CURL& url)
67 return m_file.Open(TranslateUrl(url));
70 bool CMusicDatabaseFile::Exists(const CURL& url)
72 return !TranslateUrl(url).empty();
75 int CMusicDatabaseFile::Stat(const CURL& url, struct __stat64* buffer)
77 return m_file.Stat(TranslateUrl(url), buffer);
80 unsigned int CMusicDatabaseFile::Read(void* lpBuf, int64_t uiBufSize)
82 return m_file.Read(lpBuf, uiBufSize);
85 int64_t CMusicDatabaseFile::Seek(int64_t iFilePosition, int iWhence /*=SEEK_SET*/)
87 return m_file.Seek(iFilePosition, iWhence);
90 void CMusicDatabaseFile::Close()
95 int64_t CMusicDatabaseFile::GetPosition()
97 return m_file.GetPosition();
100 int64_t CMusicDatabaseFile::GetLength()
102 return m_file.GetLength();