summaryrefslogtreecommitdiff
path: root/vdr-vdrmanager
diff options
context:
space:
mode:
Diffstat (limited to 'vdr-vdrmanager')
-rw-r--r--vdr-vdrmanager/helpers.cpp125
-rw-r--r--vdr-vdrmanager/helpers.h1
2 files changed, 75 insertions, 51 deletions
diff --git a/vdr-vdrmanager/helpers.cpp b/vdr-vdrmanager/helpers.cpp
index d547cc1..80721f3 100644
--- a/vdr-vdrmanager/helpers.cpp
+++ b/vdr-vdrmanager/helpers.cpp
@@ -17,8 +17,12 @@
#include <memory>
#include <vdr/cutter.h>
#include <vdr/sources.h>
+#include <fstream>
#define TIMER_SEP "#|#|#"
+// Taken from vdr-ive
+#define INDEXFILESUFFIX "/index.vdr"
+#define LENGTHFILESUFFIX "/length.vdr"
string cHelpers::GetRecordings(string args) {
return SafeCall(GetRecordingsIntern);
@@ -395,7 +399,7 @@ string cHelpers::SetTimerIntern(char op, string param) {
bool forceDelete = true;
if (t->Recording()) {
- if(forceDelete == true){
+ if (forceDelete == true) {
t->Skip();
cRecordControls::Process(time(NULL));
} else {
@@ -497,7 +501,7 @@ string cHelpers::SetTimerIntern(string args) {
// in VDRs cTimer::Parse method. The '|' will be replaced
// back to ':' by the cTimer::Parse() method.
-// Fix was submitted by rofafor: see
+ // Fix was submitted by rofafor: see
// http://www.vdr-portal.de/board/thread.php?threadid=100398
string params = replaceAll(args, "|##", "|");
@@ -540,6 +544,51 @@ string cHelpers::SearchEventsIntern(string wantedChannels, string pattern) {
return result + "END\r\n";
}
+
+//copied from vdr-live
+
+long cHelpers::Duration(cRecording* recording)
+{
+ long RecLength = 0;
+ if (!recording->FileName()) return 0;
+#if VDRVERSNUM < 10704
+ cString filename = cString::sprintf("%s%s", recording->FileName(), INDEXFILESUFFIX);
+ if (*filename) {
+ if (access(filename, R_OK) == 0) {
+ struct stat buf;
+ if (stat(filename, &buf) == 0) {
+ struct tIndex { int offset; uchar type; uchar number; short reserved; };
+ int delta = buf.st_size % sizeof(tIndex);
+ if (delta) {
+ delta = sizeof(tIndex) - delta;
+ esyslog("ERROR: invalid file size (%ld) in '%s'", buf.st_size, *filename);
+ }
+ RecLength = (buf.st_size + delta) / sizeof(tIndex) / SecondsToFrames(60);
+ }
+ }
+ }
+#elif VDRVERSNUM < 10721
+ // open index file for reading only
+ cIndexFile *index = new cIndexFile(recording->FileName(), false, recording->IsPesRecording());
+ if (index && index->Ok()) {
+ RecLength = (int) (index->Last() / SecondsToFrames(60, recording->FramesPerSecond()));
+ }
+ delete index;
+#else
+ return recording->LengthInSeconds() / 60;
+#endif
+ if (RecLength == 0) {
+ cString lengthFile = cString::sprintf("%s%s", recording->FileName(), LENGTHFILESUFFIX);
+ ifstream length(*lengthFile);
+ if(length)
+ length >> RecLength;
+ }
+
+ return RecLength;
+}
+
+
+
string cHelpers::ToText(cRecording * recording) {
const cRecordingInfo * info = recording->Info();
#if APIVERSNUM >= 10705
@@ -577,13 +626,14 @@ string cHelpers::ToText(cRecording * recording) {
char buf[100];
string result = "";
-#if APIVERSNUM >= 10705
- time_t startTime = event->StartTime();
- time_t endTime = event->EndTime();
+#if VDRVERSNUM < 10726
+ time_t startTime = recording->start;
#else
- time_t startTime = 0L;
- time_t endTime = 1L;
+ time_t startTime = recording->Start();
#endif
+
+ time_t endTime = startTime + RecordingLengthInSeconds(recording);
+
snprintf(buf, sizeof(buf) - 1, "%d", recording->Index());
result = buf;
result += ":";
@@ -603,14 +653,14 @@ string cHelpers::ToText(cRecording * recording) {
}
result += ":";
- if (info->Title()) {
+ if (info->Title()) {
result += MapSpecialChars(info->Title());
#if APIVERSNUM >= 10705
} else if (event->Title()) {
result += MapSpecialChars(event->Title());
#endif
} else {
- result += "<unknown>";
+ result += recording->Name();
}
result += ":";
@@ -646,6 +696,19 @@ string cHelpers::ToText(cRecording * recording) {
result += "";
}
+ result += ":";
+
+ cRecordControl *rc = cRecordControls::GetRecordControl(
+ recording->FileName());
+ if(rc){
+ cTimer *timer = rc->Timer();
+ if(timer){
+ char buf[100];
+ snprintf(buf, sizeof(buf) - 1, "%lu", timer->StopTime());
+ result += buf;
+ }
+ }
+
result += "\r\n";
return result;
}
@@ -793,7 +856,7 @@ string cHelpers::ToText(const cEvent * event) {
result += MapSpecialChars(channel->GetChannelID().ToString());
result += ":";
result += GetAudioTracks(channel);
- result += "\r\n";
+ result += "\r\n";
if (eventTimer) {
result += ToText(eventTimer);
@@ -1000,47 +1063,7 @@ string cHelpers::UnMapSpecialChars(string text) {
* based on vdr-restfulapi's RecordingLengthInSeconds
*/
int cHelpers::RecordingLengthInSeconds(cRecording* recording) {
-
- int nf = -1;
-#if APIVERSNUM >= 10721
- nf = recording->NumFrames();
-#endif
-
-#if APIVERSNUM <= 10720
- struct tIndexTs {
- uint64_t offset:40;
- int reserved:7;
- int independent:1;
- uint16_t number:16;
- tIndexTs(off_t Offset, bool Independent, uint16_t Number) {
- offset = Offset;
- reserved = 0;
- independent = Independent;
- number = Number;
- }
- };
-
- struct stat buf;
-#if APIVERSNUM >= 10703
- cString fullname = cString::sprintf("%s%s", recording->FileName(), recording->IsPesRecording() ? "/index" ".vdr" : "/index");
-#else
- cString fullname = cString::sprintf("%s%s", recording->FileName(), "/index" ".vdr");
-#endif
-
- if (recording->FileName() && *fullname && access(fullname, R_OK) == 0 && stat(fullname, &buf) == 0)
- nf = buf.st_size ? (buf.st_size - 1) / sizeof(tIndexTs) + 1 : 0;
-#endif
-
- if (nf == -1) {
- return -1;
- }
-
-#if APIVERSNUM >= 10703
- return int(((double) nf / recording->FramesPerSecond()));
-#else
- return int((double)nf / FRAMESPERSEC);
-#endif
-
+ return Duration(recording) * 60;
}
/** Compress a STL string using zlib with given compression level and return
diff --git a/vdr-vdrmanager/helpers.h b/vdr-vdrmanager/helpers.h
index 6a0d844..b9ebee5 100644
--- a/vdr-vdrmanager/helpers.h
+++ b/vdr-vdrmanager/helpers.h
@@ -33,6 +33,7 @@ public:
static string Trim(string text);
static string decompress_string(const string& str);
static string compress_string(const string& str, int compressionlevel = Z_BEST_COMPRESSION);
+ static long Duration(cRecording* recording);
private:
static string SafeCall(string (*)());
static string SafeCall(string (*)(string), string arg);