/
VideoDatabaseFile.cpp
executable file
·122 lines (99 loc) · 2.98 KB
/
VideoDatabaseFile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright (C) 2005-2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "VideoDatabaseFile.h"
#include "video/VideoDatabase.h"
#include "URL.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include <sys/stat.h>
using namespace XFILE;
CVideoDatabaseFile::CVideoDatabaseFile(void)
{
}
CVideoDatabaseFile::~CVideoDatabaseFile(void)
{
Close();
}
CStdString CVideoDatabaseFile::TranslateUrl(const CURL& url)
{
CStdString strFileName=URIUtils::GetFileName(url.Get());
if (strFileName.empty())
return "";
CStdString strPath = URIUtils::GetDirectory(url.Get());
if (strPath.empty())
return "";
CStdString strExtension = URIUtils::GetExtension(strFileName);
URIUtils::RemoveExtension(strFileName);
if (!StringUtils::IsNaturalNumber(strFileName))
return "";
long idDb=atol(strFileName.c_str());
CStdStringArray pathElem;
StringUtils::SplitString(strPath, "/", pathElem);
if (pathElem.size() == 0)
return "";
CStdString itemType = pathElem.at(2);
VIDEODB_CONTENT_TYPE type;
if (itemType.Equals("movies") || itemType.Equals("recentlyaddedmovies"))
type = VIDEODB_CONTENT_MOVIES;
else if (itemType.Equals("episodes") || itemType.Equals("recentlyaddedepisodes"))
type = VIDEODB_CONTENT_EPISODES;
else if (itemType.Equals("musicvideos") || itemType.Equals("recentlyaddedmusicvideos"))
type = VIDEODB_CONTENT_MUSICVIDEOS;
else
return "";
CVideoDatabase videoDatabase;
if (!videoDatabase.Open())
return "";
CStdString realFilename;
videoDatabase.GetFilePathById(idDb, realFilename, type);
return realFilename;
}
bool CVideoDatabaseFile::Open(const CURL& url)
{
return m_file.Open(TranslateUrl(url));
}
bool CVideoDatabaseFile::Exists(const CURL& url)
{
return !TranslateUrl(url).empty();
}
int CVideoDatabaseFile::Stat(const CURL& url, struct __stat64* buffer)
{
return m_file.Stat(TranslateUrl(url), buffer);
}
unsigned int CVideoDatabaseFile::Read(void* lpBuf, int64_t uiBufSize)
{
return m_file.Read(lpBuf, uiBufSize);
}
int64_t CVideoDatabaseFile::Seek(int64_t iFilePosition, int iWhence /*=SEEK_SET*/)
{
return m_file.Seek(iFilePosition, iWhence);
}
void CVideoDatabaseFile::Close()
{
m_file.Close();
}
int64_t CVideoDatabaseFile::GetPosition()
{
return m_file.GetPosition();
}
int64_t CVideoDatabaseFile::GetLength()
{
return m_file.GetLength();
}