#1 2014-05-02 16:16

Karim AlHousiny
Member
Registered: 2014-05-02
Posts: 6

Insert durations to the video files names (ExifTool)

Hi everyone ..
without long intros , I'd like to thank the developer for such amazing App ,
and the whole community for their helpful answers...

- My Qusetion is :
How to insert the duration (as a prefix) to the video files names using ExifTool ?

i know there is a built in tag for avi duration , but i want to do that for all video files .
Thanks in Advance ...

Last edited by Karim AlHousiny (2014-05-02 16:18)

Offline

#2 2014-05-02 18:13

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Insert durations to the video files names (ExifTool)

Hi Karim and welcome!

Karim AlHousiny wrote:

How to insert the duration (as a prefix) to the video files names using ExifTool ?
i know there is a built in tag for avi duration , but i want to do that for all video files .

If :AVI_Duration: don't work..., you may have to utilize a PascalScript to execute your ExifTool to get the wanted value back to rename the file with. As explained there: http://www.den4b.com/wiki/ReNamer:Meta_Tags

For example something similar like that: http://www.den4b.com/forum/viewtopic.php?id=109

Or perhaps, if the information is stored inside the files, something like that: http://www.den4b.com/forum/viewtopic.php?pid=3484#p3484

If you can provide a working command line tool and the needed command, we probably can create a script together...


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2014-05-02 20:53

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,378

Re: Insert durations to the video files names (ExifTool)

Hi Karim,

We already have a script for incorporating an output of a similar tool called "Exiv2" (for extract EXIF/IPTC/XMP tags from many types of images).

http://www.den4b.com/wiki/ReNamer:Scripts:Exiv2

The script can be easily adjusted to fit any tool. So if you give an example command line for ExifTool it will be a good start.

Offline

#4 2014-05-04 11:45

Karim AlHousiny
Member
Registered: 2014-05-02
Posts: 6

Re: Insert durations to the video files names (ExifTool)

Hi Stefan , Hi Denis,

first of all plz accept my apology for not Replying sooner
but i was looking for an answer for the (working command line tool and the needed command)
and also tried to modify the Exiv2 tool script, but unfortunately i'm still trying because i'm not sure of the write Tag Command .

as for the working command line tool, i assure you Stefan that ExifTool is the most comprehensive tool for Meta Tags and there is another Renamer App. that integrated ExifTool into it for this purpose ..
but honestly if you compared between that App and ReNamer from all sides,
you'll find that ReNamer is so much better in everything except
Meta Tags, it's easier there ... by the way, this is the Duration MetaTag used by exifTool in that program <ExifTool:Duration>

finally, this is a list of ExifTool Tag Names ,
(sorry for this, i couldn't post a hyperlink)

sno.phy.queensu.ca/~phil/exiftool/TagNames/

I hope this would help
for writing the script wink . thanks a lot Stefan for your help

Please Admin, take a look at that tool , and provide us with a script for it as an example or integrate it into ReNamer if possible ...
thanks so much, I Really appreciate your efforts

Last edited by Karim AlHousiny (2014-05-04 11:50)

Offline

#5 2014-05-05 11:19

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Insert durations to the video files names (ExifTool)

Hi Karim,

would you please utilize this tool yourself and see if it work for you on all your video files?

Maybe you can search/ask elsewhere for that basics?
(http://u88.n24.queensu.ca/exiftool/foru … pic=3912.0)


Once it works, post the working commend line
and we will provide you the PascalScript similar too http://www.den4b.com/wiki/ReNamer:Scripts:Exiv2

Since I neither have the need nor the vids, I am not of an great help here for these prerequisites...
(not saying I will not do it anyway, if I find some time.  Interesting anyway.... ;-) )


.

Last edited by Stefan (2014-05-05 11:25)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#6 2014-05-06 06:04

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Insert durations to the video files names (ExifTool)

Hi, everyone


I just saw in my hard drive somehing that could come handy for this, but maybe it needs some review before using it

Anyway as a base for start it could work, for example the case that the tag does not exist is not well covered, but I have no time to review it now. Here is what I had:

//** ExifTool **//
// Program needed: http://www.sno.phy.queensu.ca/~phil/exiftool/
// Needs to be renamed from "exiftool(-k)" to "exiftool"

function ExifTool(Tag: String): String;
begin
  // Not sure if needed:
  if not WideFileExists(FilePath) then Exit;

  ExecConsoleApp('exiftool.exe "' + Filepath + '"', Result);
  
  // Extract the tag value
  Result := ReplaceRegEx(Result, '^(.*\n)?\s*' + Tag + '\s*:\s*([^\r]+?)\s*(\r.*)?$', '$2', False, True);
  
  // Renaming illegal punctuation
  Result := ReplaceRegEx(Result, '^(\d+(\.\d+)?) s$', '$1s', False, True);
  Result := ReplaceRegEx(Result, '^0+:0+:0*(\d+)$', '$1s', False, True);
  Result := ReplaceRegEx(Result, '^0+:0*(\d+):0*(\d+)$', '$1m$2s', False, True);
  Result := ReplaceRegEx(Result, '^0?(\d+?):0*(\d+):0*(\d+)$', '$1d$2m$3s', False, True);
  
  // Pad Numbers to 2 digits
  //Result := ReplaceRegEx(Result, '(\d+)', '0$1', False, True);
  //Result := ReplaceRegEx(Result, '0+(\d{2,})', '$1', False, True);
end;

begin
  FileName := WideStripExtension(FileName) + ' (' + ExifTool('Duration') + ')' + WideExtractFileExt(FileName);
end.

I will take a look at it (much) later today... But here it is if someone else wants to change something.

(Looks lilke I tried to make a general purpose thing that later became not so general, so, bad there also)

Last edited by SafetyCar (2014-05-06 06:12)


If this software has helped you, consider getting your pro version. :)

Offline

#7 2014-05-06 12:35

Karim AlHousiny
Member
Registered: 2014-05-02
Posts: 6

Re: Insert durations to the video files names (ExifTool)

Hi Stefan ,
For your first question , yes, I've tried that tool , and it works perfectly .
actually I'm not sure if I'm allowed to post another renamer app name, but what I'm sure of,
is that all my videos worked on it too (Using ExivTool which is integrated into it by default) .

I also have to tell you that I already done It before by that program,
but the reason I asked about that script is I COULDN'T find any other program as powerful as ReNamer, or even close of it !
anyway, I'll try to get the needed command and post it hear... Thank you So Much for your time

Offline

#8 2014-05-06 12:43

Karim AlHousiny
Member
Registered: 2014-05-02
Posts: 6

Re: Insert durations to the video files names (ExifTool)

SafetyCar wrote:

Hi, everyone


I just saw in my hard drive somehing that could come handy for this, but maybe it needs some review before using it

Anyway as a base for start it could work, for example the case that the tag does not exist is not well covered, but I have no time to review it now. Here is what I had:

//** ExifTool **//
// Program needed: http://www.sno.phy.queensu.ca/~phil/exiftool/
// Needs to be renamed from "exiftool(-k)" to "exiftool"

function ExifTool(Tag: String): String;
begin
  // Not sure if needed:
  if not WideFileExists(FilePath) then Exit;

  ExecConsoleApp('exiftool.exe "' + Filepath + '"', Result);
  
  // Extract the tag value
  Result := ReplaceRegEx(Result, '^(.*\n)?\s*' + Tag + '\s*:\s*([^\r]+?)\s*(\r.*)?$', '$2', False, True);
  
  // Renaming illegal punctuation
  Result := ReplaceRegEx(Result, '^(\d+(\.\d+)?) s$', '$1s', False, True);
  Result := ReplaceRegEx(Result, '^0+:0+:0*(\d+)$', '$1s', False, True);
  Result := ReplaceRegEx(Result, '^0+:0*(\d+):0*(\d+)$', '$1m$2s', False, True);
  Result := ReplaceRegEx(Result, '^0?(\d+?):0*(\d+):0*(\d+)$', '$1d$2m$3s', False, True);
  
  // Pad Numbers to 2 digits
  //Result := ReplaceRegEx(Result, '(\d+)', '0$1', False, True);
  //Result := ReplaceRegEx(Result, '0+(\d{2,})', '$1', False, True);
end;

begin
  FileName := WideStripExtension(FileName) + ' (' + ExifTool('Duration') + ')' + WideExtractFileExt(FileName);
end.

I will take a look at it (much) later today... But here it is if someone else wants to change something.

(Looks lilke I tried to make a general purpose thing that later became not so general, so, bad there also)

Hi SafetyCar ,
Thank you for your reply and sharing your script with us..
I'll try it and tell you the results ... Appreciate your help smile

Offline

#9 2014-05-06 19:20

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Insert durations to the video files names (ExifTool)

Sure, we know AdvancedRenamer too tongue

There is no bad in this, we can all learn from each other...



.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#10 2014-05-06 19:35

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Insert durations to the video files names (ExifTool)

I didn't like my previous script, I prefer something more dedicated to the task.

I've made some changes, but I now remember why I didn't use exiftool too much, there is a console window on the screen each time it reads a file, and that is very anoying. I don't know if denis could do something about this... I read something related here http://u88.n24.queensu.ca/exiftool/foru … 8#msg10498 but I don't know if it would possible to make a change that wouldn't affect other scripts.

Anyway, here is the modified code...

//** ExifTool **//
// Program needed: http://www.sno.phy.queensu.ca/~phil/exiftool/
// Needs to be renamed from "exiftool(-k)" to "exiftool"

function FF(V: Extended): WideString;
begin
  Result := FormatFloat('00', V);
end;

var
  Output: String;
  D, h, m, s: Extended;

begin
  ExecConsoleApp('exiftool.exe -s3 -n -duration -playDuration -mediaDuration "' + Filepath + '"', Output);
  Output := ReplaceRegEx(Output, '^([^\r]+).*$', '$1', False, True);
  Output := WideReplaceStr(Output, '.', ',');
  D := StrToFloatDef(Output, -1);
  
  if (D >= 0) then begin
    D := D/3600;
    h := Trunc(D);
    D := (D-h)*60;
    m := Trunc(D);
    D := (D-m)*60;
    s := Trunc(D);
    
    if (H>0) then begin
      Output := FF(h)+'h'+FF(m)+'m';
    end else begin
      Output := FF(m)+'m'+FF(s)+'s';
    end;
    
    FileName := WideStripExtension(FileName) + ' (' + Output + ')' + WideExtractFileExt(FileName);
  end else begin
    FileName := ':: ERROR ::';
  end;
end.

Last edited by SafetyCar (2014-05-06 19:40)


If this software has helped you, consider getting your pro version. :)

Offline

Board footer

Powered by FluxBB