Wanted: Filesize of recordings available in skins

Message ID 1128446818.3737.34.camel@merlin.local
State New
Headers

Commit Message

Christoph Haubrich Oct. 4, 2005, 5:26 p.m. UTC
  Am Do, 2005-09-29 um 19.36 schrieb Christoph Hermanns:

> 1. Is this size information already available for a plugin ?
>     If not, i would highly welcome that this size information	
>     can be accessed from a plugin.
> 

Hi,

some days ago I wrote some lines to display the size of a recording. It
requires Rolf Ahrenberg's enAIO-2.6-Patch (actually the rename-patch
which is included in enAIO but I didn't try that) and I tested it with
vdr 1.3.32 and 1.3.34. 
It displays an additional line in the rename menu with the size in human
readable format (that is "GB" in most cases). 

@Rolf: would you like to include it in your enAIO-Patch?

regards
Christoph
  

Comments

Rolf Ahrenberg Oct. 5, 2005, 6:17 p.m. UTC | #1
On Tue, 4 Oct 2005, Christoph Haubrich wrote:

> @Rolf: would you like to include it in your enAIO-Patch?

No, sorry. The recording length patch provides already the file
size and you can always use the calc-plugin to calculate the size
in megabytes instead of minutes displayed on the OSD.

BTW. Frank might include it into his BigPatch that contains all 
non-essential patches/addons :)

BR,
--
rofa
  

Patch

diff -Nur vdr-1.3.32-org/i18n.c vdr-1.3.32/i18n.c
--- vdr-1.3.32-org/i18n.c	2005-09-18 14:36:43.000000000 +0200
+++ vdr-1.3.32/i18n.c	2005-09-18 14:46:48.000000000 +0200
@@ -5690,6 +5690,28 @@ 
     "",//TODO
     "",//TODO
   },
+  { "Size",
+    "Größe",
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+    "",//TODO
+  },
+
   { NULL }
   };
 
diff -Nur vdr-1.3.32-org/menu.c vdr-1.3.32/menu.c
--- vdr-1.3.32-org/menu.c	2005-09-18 14:36:43.000000000 +0200
+++ vdr-1.3.32/menu.c	2005-09-18 14:47:54.000000000 +0200
@@ -1611,6 +1611,46 @@ 
   Add(new cMenuEditRecPathItem(tr("Path"),  path,     sizeof(path)                   ));
   Add(new cMenuEditIntItem(tr("Priority"), &priority, 0,            MAXPRIORITY      ));
   Add(new cMenuEditIntItem(tr("Lifetime"), &lifetime, 0,            MAXLIFETIME      ));
+
+  long long llSize=0;
+  double dSize=0.0;
+  char *buffer = NULL;
+  DIR *dir=opendir(recording->FileName()); 
+  if (dir) {
+    struct dirent *entry;
+    struct stat fileinfo;
+    while ( NULL != (entry = readdir(dir))) {
+         asprintf (&buffer, "%s/%s", recording->FileName(), entry->d_name);
+         if (stat(buffer, &fileinfo) == 0) {
+            llSize += (long long)fileinfo.st_size;
+         }
+         else
+         {
+            isyslog("couldn't stat '%s': %s", buffer, strerror(errno));
+         }
+         free(buffer);
+    }
+    closedir(dir);
+  } else {
+    esyslog("Error opening directory \"%s\": %s", recording->FileName(), strerror(errno));
+  }
+
+  const char * const Units[5] = {"Bytes", "kB", "MB", "GB", "TB"};
+  int Unit = 0;
+  dSize = llSize;
+  while (dSize >= 1024.0)
+  {
+     dSize /= 1024.0;
+     Unit++;
+  }
+    
+  asprintf (&buffer, "%s:\t%.2f %s", tr("Size"), dSize, Units[Unit]);
+  
+  cOsdItem *item;
+  item = new cOsdItem(buffer);
+  item->SetSelectable(false);
+  Add(item); 
+  free(buffer);
 }
 
 eOSState cMenuRenameRecording::ProcessKey(eKeys Key)