Svdrp-renr-patch

From VDR Wiki
Revision as of 08:41, 18 July 2007 by Coder (talk | contribs) (Svdr-renr-patch moved to Svdrp-renr-patch: typing error)
Jump to navigation Jump to search

Description

The svdrp-renr patch allows the renaming of recordings via the SVDRP protocol.

With a patched version of VDRAdmin or actual VDRAdmin-AM, recordings can be easily renamed through the web interface.

This version is just a small part of the Liemikuutio patch, adapted to vdr 1.5.5.

Hardware requirements

Software requirements

  • vdr 1.5.5
  • patch

Applying the patch

If the patch is compressed you have to unpack it before

gunzip patch

Now you can install it with

cd $SOURCEDIR/VDR
patch -p 1 < /path/to/patch

Note, VDR has to be recompiled now, see VDR installation.

Problems

Patch

--- vdr-1.5.5-vanilla/recording.c	2007-06-17 15:10:12.000000000 +0200
+++ vdr-1.5.5-svdrp_renr/recording.c	2007-07-18 10:25:46.000000000 +0200
@@ -823,6 +823,44 @@
   resume = RESUME_NOT_INITIALIZED;
 }
 
+bool cRecording::Rename(const char *newName, int *newPriority, int *newLifetime)
+{
+  bool result = false;
+  char *newFileName;
+  struct tm tm_r;
+  struct tm *t = localtime_r(&start, &tm_r);
+  char *localNewName = ExchangeChars(strdup(newName), true);
+  asprintf(&newFileName, NAMEFORMAT, VideoDirectory, localNewName,
+    t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min,
+    *newPriority, *newLifetime);
+  free(localNewName);
+  if (strcmp(FileName(), newFileName)) {
+     if (access(newFileName, F_OK) == 0) {
+        isyslog("recording %s already exists", newFileName);
+        }
+     else {
+        isyslog("renaming recording %s to %s", FileName(), newFileName);
+        result = MakeDirs(newFileName, true);
+        if (result)
+           result = RenameVideoFile(FileName(), newFileName);
+        if (result) {
+           priority = *newPriority;
+           lifetime = *newLifetime;
+           free(fileName);
+           fileName = strdup(newFileName);
+           free(name);
+           name = strdup(newName);
+           free(sortBuffer);
+           sortBuffer = NULL;
+           free(titleBuffer);
+           titleBuffer = NULL;
+           }
+        }
+     }
+  free(newFileName);
+  return result;
+}
+
 // --- cRecordings -----------------------------------------------------------
 
 cRecordings Recordings;
--- vdr-1.5.5-vanilla/recording.h	2007-06-17 14:53:05.000000000 +0200
+++ vdr-1.5.5-svdrp_renr/recording.h	2007-07-18 09:20:22.000000000 +0200
@@ -100,6 +100,9 @@
   bool Remove(void);
        // Actually removes the file from the disk
        // Returns false in case of error
+  bool Rename(const char *newName, int *newPriority, int *newLifetime);
+       // Changes the file name
+       // Returns false in case of error
   };
 
 class cRecordings : public cList<cRecording>, public cThread {
--- vdr-1.5.5-vanilla/svdrp.c	2007-06-23 15:14:59.000000000 +0200
+++ vdr-1.5.5-svdrp_renr/svdrp.c	2007-07-18 09:14:31.000000000 +0200
@@ -293,6 +293,8 @@
   "REMO [ on | off ]\n"
   "    Turns the remote control on or off. Without a parameter, the current\n"
   "    status of the remote control is reported.",
+  "RENR <number> <new name>\n"
+  "    Rename recording. Number must be the Number as returned by LSTR command.",
   "SCAN\n"
   "    Forces an EPG scan. If this is a single DVB device system, the scan\n"
   "    will be done on the primary device unless it is currently recording.",
@@ -1415,6 +1417,38 @@
      Reply(250, "Remote control is %s", cRemote::Enabled() ? "enabled" : "disabled");
 }
 
+void cSVDRP::CmdRENR(const char *Option)
+{
+  bool recordings = Recordings.Update(true);
+  if (recordings) {
+     if (*Option) {
+        char *tail;
+        int n = strtol(Option, &tail, 10);
+        cRecording *recording = Recordings.Get(n - 1);
+        if (recording && tail && tail != Option) {
+           int priority = recording->priority;
+           int lifetime = recording->lifetime;
+           char *oldName = strdup(recording->Name());
+           tail = skipspace(tail);
+           if (recording->Rename(tail, &priority, &lifetime)) {
+              Reply(250, "Renamed \"%s\" to \"%s\"", oldName, recording->Name());
+              Recordings.ChangeState();
+              Recordings.TouchUpdate();
+              }
+           else
+              Reply(501, "Renaming \"%s\" to \"%s\" failed", oldName, tail);
+           free(oldName);
+           }
+        else
+          Reply(501, "Recording not found or wrong syntax");
+        }
+     else
+        Reply(501, "Missing Input settings");
+     }
+  else
+     Reply(550, "No recordings available");
+}
+						
 void cSVDRP::CmdSCAN(const char *Option)
 {
   EITScanner.ForceScan();
@@ -1536,6 +1570,7 @@
   else if (CMD("PLUG"))  CmdPLUG(s);
   else if (CMD("PUTE"))  CmdPUTE(s);
   else if (CMD("REMO"))  CmdREMO(s);
+  else if (CMD("RENR"))  CmdRENR(s);
   else if (CMD("SCAN"))  CmdSCAN(s);
   else if (CMD("STAT"))  CmdSTAT(s);
   else if (CMD("UPDT"))  CmdUPDT(s);
--- vdr-1.5.5-vanilla/svdrp.h	2007-04-30 14:28:28.000000000 +0200
+++ vdr-1.5.5-svdrp_renr/svdrp.h	2007-07-18 09:10:06.000000000 +0200
@@ -79,6 +79,7 @@
   void CmdPLUG(const char *Option);
   void CmdPUTE(const char *Option);
   void CmdREMO(const char *Option);
+  void CmdRENR(const char *Option);
   void CmdSCAN(const char *Option);
   void CmdSTAT(const char *Option);
   void CmdUPDT(const char *Option);