2 * Copyright (C) 2012-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 "dialogs/GUIDialogOK.h"
22 #include "pvr/PVRManager.h"
23 #include "settings/AdvancedSettings.h"
24 #include "PVRRecordings.h"
25 #include "pvr/addons/PVRClients.h"
26 #include "utils/StringUtils.h"
27 #include "utils/RegExp.h"
28 #include "utils/StringUtils.h"
29 #include "video/VideoDatabase.h"
36 CPVRRecording::CPVRRecording()
41 CPVRRecording::CPVRRecording(const PVR_RECORDING &recording, unsigned int iClientId)
45 m_strRecordingId = recording.strRecordingId;
46 m_strTitle = recording.strTitle;
47 m_iClientId = iClientId;
48 m_recordingTime = recording.recordingTime + g_advancedSettings.m_iPVRTimeCorrection;
49 m_duration = CDateTimeSpan(0, 0, recording.iDuration / 60, recording.iDuration % 60);
50 m_iPriority = recording.iPriority;
51 m_iLifetime = recording.iLifetime;
52 m_strDirectory = recording.strDirectory;
53 m_strPlot = recording.strPlot;
54 m_strPlotOutline = recording.strPlotOutline;
55 m_strStreamURL = recording.strStreamURL;
56 m_strChannelName = recording.strChannelName;
57 m_genre = StringUtils::Split(CEpg::ConvertGenreIdToString(recording.iGenreType, recording.iGenreSubType), g_advancedSettings.m_videoItemSeparator);
58 m_playCount = recording.iPlayCount;
59 m_strIconPath = recording.strIconPath;
60 m_strThumbnailPath = recording.strThumbnailPath;
61 m_strFanartPath = recording.strFanartPath;
64 bool CPVRRecording::operator ==(const CPVRRecording& right) const
66 return (this == &right) ||
67 (m_strRecordingId == right.m_strRecordingId &&
68 m_iClientId == right.m_iClientId &&
69 m_strChannelName == right.m_strChannelName &&
70 m_recordingTime == right.m_recordingTime &&
71 m_duration == right.m_duration &&
72 m_strPlotOutline == right.m_strPlotOutline &&
73 m_strPlot == right.m_strPlot &&
74 m_strStreamURL == right.m_strStreamURL &&
75 m_iPriority == right.m_iPriority &&
76 m_iLifetime == right.m_iLifetime &&
77 m_strDirectory == right.m_strDirectory &&
78 m_strFileNameAndPath == right.m_strFileNameAndPath &&
79 m_strTitle == right.m_strTitle &&
80 m_strIconPath == right.m_strIconPath &&
81 m_strThumbnailPath == right.m_strThumbnailPath &&
82 m_strFanartPath == right.m_strFanartPath);
85 bool CPVRRecording::operator !=(const CPVRRecording& right) const
87 return !(*this == right);
90 void CPVRRecording::Reset(void)
92 m_strRecordingId = StringUtils::EmptyString;
94 m_strChannelName = StringUtils::EmptyString;
95 m_strDirectory = StringUtils::EmptyString;
96 m_strStreamURL = StringUtils::EmptyString;
99 m_strFileNameAndPath = StringUtils::EmptyString;
100 m_strIconPath = StringUtils::EmptyString;
101 m_strThumbnailPath = StringUtils::EmptyString;
102 m_strFanartPath = StringUtils::EmptyString;
103 m_bGotMetaData = false;
105 m_recordingTime.Reset();
106 CVideoInfoTag::Reset();
109 int CPVRRecording::GetDuration() const
111 return (m_duration.GetDays() * 60*60*24 +
112 m_duration.GetHours() * 60*60 +
113 m_duration.GetMinutes() * 60 +
114 m_duration.GetSeconds());
117 bool CPVRRecording::Delete(void)
119 PVR_ERROR error = g_PVRClients->DeleteRecording(*this);
120 if (error != PVR_ERROR_NO_ERROR)
129 bool CPVRRecording::Rename(const CStdString &strNewName)
131 m_strTitle.Format("%s", strNewName);
132 PVR_ERROR error = g_PVRClients->RenameRecording(*this);
133 if (error != PVR_ERROR_NO_ERROR)
142 bool CPVRRecording::SetPlayCount(int count)
146 if (g_PVRClients->SupportsRecordingPlayCount(m_iClientId) &&
147 !g_PVRClients->SetRecordingPlayCount(*this, count, &error))
156 void CPVRRecording::UpdateMetadata(void)
160 if (!g_PVRClients->SupportsRecordingPlayCount(m_iClientId))
162 if (!m_bGotMetaData && db.Open())
164 CFileItem pFileItem(*this);
165 m_playCount = db.GetPlayCount(pFileItem);
169 if ((g_PVRClients->SupportsLastPlayedPosition(m_iClientId)))
171 int iPosition = g_PVRClients->GetRecordingLastPlayedPosition(*this);
174 m_resumePoint.timeInSeconds = iPosition;
175 m_resumePoint.totalTimeInSeconds = (double)GetDuration();
178 else if (!m_bGotMetaData && db.Open())
180 db.GetResumeBookMark(m_strFileNameAndPath, m_resumePoint);
183 m_bGotMetaData = true;
186 bool CPVRRecording::IncrementPlayCount()
188 return SetPlayCount(m_playCount + 1);
191 bool CPVRRecording::SetLastPlayedPosition(int lastplayedposition)
194 if (g_PVRClients->SupportsLastPlayedPosition(m_iClientId) &&
195 !g_PVRClients->SetRecordingLastPlayedPosition(*this, lastplayedposition, &error))
203 int CPVRRecording::GetLastPlayedPosition() const
206 if (g_PVRClients->SupportsLastPlayedPosition(m_iClientId))
208 rc = g_PVRClients->GetRecordingLastPlayedPosition(*this);
210 DisplayError(PVR_ERROR_SERVER_ERROR);
215 void CPVRRecording::DisplayError(PVR_ERROR err) const
217 if (err == PVR_ERROR_SERVER_ERROR)
218 CGUIDialogOK::ShowAndGetInput(19033,19111,19110,0); /* print info dialog "Server error!" */
219 else if (err == PVR_ERROR_REJECTED)
220 CGUIDialogOK::ShowAndGetInput(19033,19068,19110,0); /* print info dialog "Couldn't delete recording!" */
222 CGUIDialogOK::ShowAndGetInput(19033,19147,19110,0); /* print info dialog "Unknown error!" */
227 void CPVRRecording::Update(const CPVRRecording &tag)
229 m_strRecordingId = tag.m_strRecordingId;
230 m_iClientId = tag.m_iClientId;
231 m_strTitle = tag.m_strTitle;
232 m_recordingTime = tag.m_recordingTime;
233 m_duration = tag.m_duration;
234 m_iPriority = tag.m_iPriority;
235 m_iLifetime = tag.m_iLifetime;
236 m_strDirectory = tag.m_strDirectory;
237 m_strPlot = tag.m_strPlot;
238 m_strPlotOutline = tag.m_strPlotOutline;
239 m_strStreamURL = tag.m_strStreamURL;
240 m_strChannelName = tag.m_strChannelName;
241 m_genre = tag.m_genre;
242 m_strIconPath = tag.m_strIconPath;
243 m_strThumbnailPath = tag.m_strThumbnailPath;
244 m_strFanartPath = tag.m_strFanartPath;
246 if (g_PVRClients->SupportsRecordingPlayCount(m_iClientId))
247 m_playCount = tag.m_playCount;
250 strShow.Format("%s - ", g_localizeStrings.Get(20364).c_str());
251 if (m_strPlotOutline.Left(strShow.size()).Equals(strShow))
253 CStdString strEpisode = m_strPlotOutline;
254 CStdString strTitle = m_strDirectory;
256 int pos = strTitle.ReverseFind('/');
257 strTitle.erase(0, pos + 1);
258 strEpisode.erase(0, strShow.size());
259 m_strTitle.Format("%s - %s", strTitle.c_str(), strEpisode);
260 pos = strEpisode.Find('-');
261 strEpisode.erase(0, pos + 2);
262 m_strPlotOutline = strEpisode;
267 void CPVRRecording::UpdatePath(void)
269 if (!m_strStreamURL.IsEmpty())
271 m_strFileNameAndPath = m_strStreamURL;
275 CStdString strTitle(m_strTitle);
276 CStdString strDatetime(m_recordingTime.GetAsSaveString());
277 CStdString strDirectory;
278 CStdString strChannel;
279 strTitle.Replace('/',' ');
281 if (!m_strDirectory.IsEmpty())
282 strDirectory.Format("%s/", m_strDirectory.c_str());
283 if (!m_strChannelName.IsEmpty())
284 strChannel.Format(" (%s)", m_strChannelName.c_str());
285 m_strFileNameAndPath.Format("pvr://recordings/%s%s, TV%s, %s.pvr", strDirectory.c_str(), strTitle.c_str(), strChannel.c_str(), strDatetime.c_str());
289 const CDateTime &CPVRRecording::RecordingTimeAsLocalTime(void) const
291 static CDateTime tmp;
292 tmp.SetFromUTCDateTime(m_recordingTime);
297 CStdString CPVRRecording::GetTitleFromURL(const CStdString &url)
300 if (reg.RegComp("pvr://recordings/(.*/)*(.*), TV( \\(.*\\))?, "
301 "(19[0-9][0-9]|20[0-9][0-9])[0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9].pvr"))
303 if (reg.RegFind(url.c_str()) >= 0)
304 return reg.GetReplaceString("\\2");
306 return StringUtils::EmptyString;
309 void CPVRRecording::CopyClientInfo(CVideoInfoTag *target) const
314 target->m_playCount = m_playCount;
315 target->m_resumePoint = m_resumePoint;