Media files tagger

Discuss and share scripts and script files...
highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Search for and tag video files [custom columns]

Post by highend »

Thanks for the files.

I know how to solve the problem but it's necessary to switch from position based tags to named ones.
Once I've finished the script you'll see what I mean.

A short glimpse of how this will work e.g. for multiple audio streams:

Code: Select all

    $desc    = "#::#Audio_Channels="; // Must be preceded with the used separator
    $tags    = tagitems("tags", , <cc_item>);
    $matches = regexmatches($tags, "$desc.*?(#::#|$)", <crlf>);
    $trimmed = replacelist($matches, "$desc<crlf>#::#", "", <crlf>);
    $joined  = replace($trimmed, <crlf>, "/");
    return $joined;
or in short form:

Code: Select all

    $desc = "#::#Audio_Channels=";
    return replace(replacelist(regexmatches(tagitems("tags", , <cc_item>), "$desc.*?(#::#|$)", <crlf>), "$desc<crlf>#::#", "", <crlf>), <crlf>, "/");
This would output "2/6" for the test file and will work regardless of how many audio streams are present...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Search for and tag video files [custom columns]

Post by amirvf »

Excellent job.

There is one more issue which is related to MediaInfo but could be improved in the script. The normal behavior of MediaInfo is to return empty values for missing items. For example if there are no subtitles in the video file, the corresponding value would be empty instead of "0". It's a good idea to fill the corresponding columns which have empty values with a generic term to avoid confusions. This will make a big improvement in columns compared to when the info is directly fetched from MediaInfo. The generic term for empty values could be something like "Nil", "Empty", "N/A", etc.

One more thing. I double checked the entire code. At the moment there are no lines regarding the replacement of unallowed characters in tags. So, values containing quotation still result in the failure of tagging.

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Search for and tag video files [custom columns]

Post by highend »

It's a good idea to fill the corresponding columns which have empty values with a generic term to avoid confusions.
You can do that in the custom column script. A simple return of "what the user wants as a nil value in that column" if the tag value is empty
At the moment there are no lines regarding the replacement of unallowed characters in tags
No, but the code is already present in my current version
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Search for and tag video files [custom columns]

Post by highend »

Script is online, see the first post...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Search for and tag video files [custom columns]

Post by amirvf »

highend wrote: 05 Nov 2020 20:04 Script is online, see the first post...
I'm working on it :tup: :tup: :tup:

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Search for and tag video files [custom columns]

Post by amirvf »

highend wrote: 05 Nov 2020 20:04 Script is online, see the first post...
I tried the script with the default ini file. Loading the script results in an error: call to undefined function addidentifier.

Unfortunately the full error is distorted and not readable due to the bug associated with font spacing in 4k displays.
You can see the screenshot of error message in this thread: viewtopic.php?f=2&t=22321

Here is the content of generated ini file:

Code: Select all

[General]
; The path where the necessary template file will be stored
TemplatePath=C:\Users\Amir\AppData\Local\Temp

; The path where the command line version of "MediaInfo.exe" exists
MediaInfoPath=C:\Program Files\MediaInfo_CLI_20.09_Windows_x64

; The extensions of the video files to tag
; Instead of ";"-separated list, you could use "{:Video}" as well
Extensions=*.avi;*.mkv;*.mp4



; Template definition(s)
; Do NOT change the name of "Template_Default"!
; All additional template(s) must follow the naming schema of "Template_01"
; with "Template_02", "..._03", etc.
; Only the numbered additional template(s) use the "Path=" key
; If that path matches the current one in XYplorer when the script is started,
; that template will be chosen. First match wins!
; If no path match is found, the "Template_Default" will be chosen!

; Schema of the "General, Video, Audio and Text" keys:
;     Each key can only exist once per template section
;     Each value to be provided by the template must be embraced by "%"
;     and needs to be preceded by an "identifier" string
;     Do not use any additional separator between the different values,
;     this must be done in the belonging custom column script!

;     Schema of an "identifier":
;         It should match the name of the attribute you want to retrieve
;         It must end with a "="
;         It can only consist of the letters a-z and 0-9, even spaces are not allowed
;         It is not case-sensitive
;         Non valid examples would be: Codec ID= / Codec-ID= / etc.

; Note: Not all attributes have exactly the same name as in the standard output of MediaInfo
;     E.g.: The "General" section can have an attribute called "Movie name"
;     You cannot access it in the template via "%MovieName%" but need to use "%Title%" instead!
;     So before you finally tag your video files with this script, make sure that your template
;     works correctly via a manual MediaInfo call from a command prompt!

;     Take a look at the example template in the "Template_Default" section...

; Per template: "Path="         -> Can be a full or partial path (not case-sensitive!)
;                                  E.g.: "R:\Movies\" / "\with subtitle streams\" / etc.
;
;               "Recursive="    -> Scan recursively or not (true / false)
;
;               "Replacements=" -> Additional character / string replacements
;                                  Find and replace patterns must be separated by "<::>"
;                                  and multiple patterns must be separated by "|"
;                                  E.g.: "&<::>and|*<::>-"
;                                  To remove a character / string, just leave the right side
;                                  of the separator empty
;
;                                  Some characters are not allowed in XYplorers tag database:
;                                  01. A double quote character ("), replaced by a single quote (')
;                                  02. A bar character (|), replaced by a forward slash (/)
;
;                                  Additionally, the default tag separator (,) will be replaced by (;)
;                                  These replacements will already be performed by the script file!

[Template_Default]
General=Format=%Format%Duration=%Duration/String3%OverallBitRate=%OverallBitRate%
Video=CodecID=%CodecID%Width=%Width%Height=%Height%FrameRate=%FrameRate%DisplayAspectRatio=%DisplayAspectRatio/String%
Audio=Channels=%Channel(s)%CodecID=%CodecID%BitRate=%BitRate/String%
Text=Language=%Language%Default=%Default%

Recursive=false
Replacements=


[Template_01]
General=
Video=
Audio=
Text=

Path=
Recursive=false
Replacements=
Any ideas about this error?

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Search for and tag video files [custom columns]

Post by highend »

Redownload the script and start it again
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Search for and tag video files [custom columns]

Post by amirvf »

highend wrote: 07 Nov 2020 00:26 Redownload the script and start it again
Excellent job! :appl: :appl: :appl: :appl: :tup: :tup: :tup: :tup:
Without a single glitch, blazing fast tagging (even on network drives), and instant loading of columns everywhere as you don't even notice if you are in a local drive or network drive.

This script is by far the best method to retrieve full video metadata in terms of speed, simplicity, and the ability for limitless customization.

MediaInfo has 7 sections. At the moment you have included "General", "Video", "Audio", and "Text".
I checked MediaInfo CLI to retrieve information from different audio file formats (ogg, mp3, wav, realaudio, ac3, dts, aac, m4a, au, aiff) and it provided comprehensive info for all formats. As "Audio" section is already included, it's a good idea to allow scanning and tagging of audio/music files as well. And then the most suitable name for this script would be "Script to Tag Media Files".

Additionally I checked the "Image" section of MediaInfo CLI and I could retrieve valuable information with the different image formats including jpg, jpeg, png, psd, bmp, gif, pcx, tga, and tif. If the "Image" section of MediaInfo CLI is included in the codes, it makes this script an amazing tool to tag all multimedia files as fast as greased lightning!

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Media files tagger

Post by highend »

v0.3 is online

If you are upgrading from v0.1:
Rename your current .ini file!
Start the script once, it creates a new .ini file.

Copy over necessary values into the new .ini file.
Especially the "General=, Video=, Audio= and Text=" ones, if defined.
Make sure to read the changelog (the "Extensions=" key was moved from "[General]" into all sections and "Path=" was deleted)!

Code: Select all

/*
@Changelog:
+++ major new feature
  + new feature
  * changed feature
  - removed feature
  # note / comment
  % improved performance
  ! fixed minor bug
!!! fixed major bug

v0.3
  # Renamed "Template_Default" to "Template_Video"
  + New key per template section: EmptyValue=
    If set to e.g. "N/A", all empty values returned by the template will
    be replaced with this string
  + New key per template section: MenuName=
    If left empty, the template section name is used. Otherwise the
    value of this key
  - Removed key per template section: Path=
    The script will no longer try to find a match between the value of this
    key and the current path in XYplorer
  * Moved key "Extensions=" from "General" to each template section
  + A menu will be used from now on to select the template section to process
*/

One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Media files tagger

Post by highend »

v0.4 is online

No .ini file changes necessary
Added a 'must have': Already existing tags are NOT removed (but our own tag is created / refreshed (if already present) with the new values)

Code: Select all

v0.4
  + Only show the menu to select a template if more than one is defined
  + Do not overwrite all tags but keep the ones that are not made by this
    script
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Media files tagger

Post by amirvf »

highend wrote: 10 Nov 2020 14:50 v0.4 is online

No .ini file changes necessary
Added a 'must have': Already existing tags are NOT removed (but our own tag is created / refreshed (if already present) with the new values)

Code: Select all

v0.4
  + Only show the menu to select a template if more than one is defined
  + Do not overwrite all tags but keep the ones that are not made by this
    script
The script is perfect and works very fast.
Is it possible to have labels (through a parameter such as MenuLabel for each template in the INI file) for the each MenuName so each menu item could be loaded independently?
This is very useful if the script is assigned as a toolbar button, and we want to further facilitate the process without the need to choose an option from the pop-up menu.

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Media files tagger

Post by highend »

v0.5
+ You can choose a specific template section (either by the name of the
section) itself or by the value of the "MenuName" of that section by
populating a permanent variable ($P_MEDIA_FILES_TAGGER_USE_SECTION)
before you run the script
E.g.: perm $P_MEDIA_FILES_TAGGER_USE_SECTION = "Video file(s)";
load "Media files tagger.xys";
You can't do it by trying to call the load command with a label.
You just do it by populating the permanent variable and then load the script as before.
Internally the permanent variable is reset immediately so if you want to call the script
again you need to fill the permanent variable again.
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Media files tagger

Post by amirvf »

highend wrote: 18 Nov 2020 10:52
v0.5
+ You can choose a specific template section (either by the name of the
section) itself or by the value of the "MenuName" of that section by
populating a permanent variable ($P_MEDIA_FILES_TAGGER_USE_SECTION)
before you run the script
E.g.: perm $P_MEDIA_FILES_TAGGER_USE_SECTION = "Video file(s)";
load "Media files tagger.xys";
You can't do it by trying to call the load command with a label.
You just do it by populating the permanent variable and then load the script as before.
Internally the permanent variable is reset immediately so if you want to call the script
again you need to fill the permanent variable again.
Excellent solution! :tup: :tup: :tup:

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Media files tagger

Post by amirvf »

I use the script to tag video files. There is a new issue I am facing. Although EmptyValue has been defined properly, it applies only to some parameters:

Code: Select all

[General]
TemplatePath=C:\Users\Amir\AppData\Local\Temp
MediaInfoPath=C:\Program Files\MediaInfo_CLI_20.09_Windows_x64

[Template_Video]
General=Format=%Format%Duration=%Duration/String3%OverallBitRate=%OverallBitRate/String%AudioCount=%AudioCount%VideoCount=%VideoCount%FrameRate=%FrameRate%TextCount=%TextCount%Cover=%Cover%Title=%Title%Genre=%Genre%Director=%Director%Actor=%Actor%LongDescription=%LongDescription%
Video=Width=%Width%Height=%Height%DisplayAspectRatio=%DisplayAspectRatio/String%Title=%Title%BitRate=%BitRate/String%VideoFormatList=%Format%
Audio=Channels=%Channel(s)%BitRate=%BitRate/String%Title=%Title%AudioLanguageList=%Language/String3%AudioFormatList=%Format%
Text=Language=%Language%Default=%Default%

MenuName=Video file(s)
Extensions={:Video}
Recursive=true
EmptyValue=N/A
Replacements=
Here is the generated tag for one of my video files:

Code: Select all

#::#General_Format=MPEG-4#::#General_Duration=01:37:36.518#::#General_OverallBitRate=2 296 kb/s#::#General_AudioCount=1#::#General_VideoCount=1#::#General_FrameRate=23.976#::#General_TextCount=N/A#::#General_Cover=#::#General_Title=N/A#::#General_Genre=#::#General_Director=N/A#::#General_Actor=#::#General_LongDescription=N/A#::#Video_Width=1920#::#Video_Height=816#::#Video_DisplayAspectRatio=2.35:1#::#Video_Title=N/A#::#Video_BitRate=2 150 kb/s#::#Video_VideoFormatList=AVC#::#Audio_Channels=2#::#Audio_BitRate=144 kb/s#::#Audio_Title=N/A#::#Audio_AudioLanguageList=eng#::#Audio_AudioFormatList=AAC
The same behavior applies for all other video files.

Any ideas?
Last edited by amirvf on 22 Nov 2020 21:35, edited 2 times in total.

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Media files tagger

Post by highend »

I need the belonging mediainfo.exe -i "<that file>" output from a command prompt as well...
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Post Reply