本文介绍了在文件夹内批处理文件以创建MediaInfo.nfo文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个批处理,其目的是使用MediaInfo.exe(CLI)创建包含所有"mediainfo"文件的单个文本文件(.nfo).文件夹中包含的视频文件.

I'm trying to create a Batch whose purpose is to use MediaInfo.exe (CLI) to create a single text file (.nfo) containing all the "mediainfo" of the video files contained in a folder.

从上下文菜单执行批处理:右键单击包含视频文件的文件夹.为此,该文件将放置在"shell:sendto"中.

The Batch is executed from the context menu: right click on the folder containing the video files.To do so, the file will be placed in "shell:sendto".

生成的包含所有mediainfo的.nfo文件必须放置/保存或移动".在包含视频文件的文件夹中.

The generated .nfo file containing all the mediainfo has to be "placed/saved or move" in the folder containing the video files.

一个特殊性是我需要更改最终的.nfo文件,以便删除完整名称"行中的所有路径部分.:

A specificity is that i need to alter the final .nfo file, in order to delete all the path part of the lines "Complete name" :

Complete name                            : /Users/me/Downloads/Folder1/Folder2/RÉCENTS/[File] File Name - 185  (Encode Format 1080p).mkv

在此示例中:进行搜索&替换以仅离开:

in this example : Do a search & replace to leave only :

Complete name                            : [File] File Name - 185  (Encode Format 1080p).mkv


目前,我已经设法创建了这个批处理(下面的链接).这个有一些错误,即:


For the moment, I've managed to create this batch (link below).This one has a few bugs, namely :

  • 找不到文件(x2)
  • 如果有特殊字符,则会出错的Powershell

总结批次搜索的过程:

1..右键单击包含文件>的文件夹.发送到>单击批处理文件.

1. Right click on the folder containing the files > send to > click on the Batch file.

2..创建文件夹中包含的文件的所有媒体信息txt文件

2. Creation of all the Media info txt files of the files contained in the folder

3..通过在每个内容"----"之间添加分隔符来合并媒体信息txt文件.

3. Merge Media Info txt files by adding a separator between each content "----".

4..使用Regex替换最终文件,以删除文件名之前的所有路径,然后将(.nfo)保存在文件夹中.

4. Search & Replace on the final file with a Regex to remove all path before filename, then save (.nfo) inside the folder.

5..从步骤2中清除旧的临时文件.

5. Clean the old temporary files from step 2.

我设法创建的实际批处理文件:

@echo off
 
:: Fullpath current folder : %cd%
:: Fullpath folder where the right click was made : %~f1
:: Name of the folder where the right click was made : for %%f in ("%~f1") do set Name=%%~nxf
 
for %%f in ("%~f1") do set Name=%%~nxf
 
:: Step 1: Creating a temporary folder
mkdir "%~f1-Temp"
 
:: Step 2: Creation of all nfo txt files in the temporary folder
FOR /F "tokens=*" %%G IN ('dir "%~f1" /b *.mkv') DO (
   call "C:\Users\me\Desktop\MediaInfo\MediaInfo.exe" "%~f1\%%G" > "%~f1-Temp\%%~nG.txt"
)
 
:: Step 3: Filling in the final nfo
setlocal enabledelayedexpansion
set i=0
 
FOR /F "tokens=*" %%G IN ('dir "%~f1" /b *.mkv') DO (
   IF !i! == 1 (
     echo ------------------------------------------------------------------------------------------------------------------------------------ >> "%~f1-Temp\%Name%.txt"
     echo. >> "%~f1-Temp\%Name%.txt"
     echo. >> "%~f1-Temp\%Name%.txt"
  )
   cat "%~f1-Temp\%%~nG.txt" >> "%~f1-Temp\%Name%.txt" 
   set i=1
)
endlocal
 
:: Step 4: Removing the path
setlocal
set $source="%~f1-Temp\%Name%.txt"
set $dest="%~f1-Temp\%Name%1.txt"
set "search=%~f1\\"
 
for /f "delims=" %%a in ('powershell -c "(get-content '%$source%') | foreach-object {$_ -replace '(?<=Complete name\s+:\s+).+\\'} | set-content '%$dest%'"') do echo %%a
endlocal
 
:: Step 5: Renaming the nfo and moving to the right place
Ren "%~f1-Temp\%Name%1.txt" "%Name%.nfo"
move "%~f1-Temp\%Name%.nfo" "%~f1"
 
:: Step 6: Deleting temporary files
rmdir /s /q "%~f1-Temp"
 
pause

如果您对已编码的内容有改进或/或更正的建议,请不要犹豫!预先感谢您的帮助!

If you have suggestions for improvement or/and corrections of what is already coded, don't hesitate!Thank you in advance for your help!

推荐答案

我认为您已经通过向MediaInfo提供完整路径作为参数来自己创建了一个问题.如果仅提供文件名,则完整名称将仅反映文件名.

I think you've created an issue yourself, by providing MediaInfo with the full path as the argument. If you just provide it with the filename, the Complete name will reflect just the filename.

此外,除非我误解了您的意图,否则当我认为不必要时,您会遇到很多麻烦.

In addition, unless I'm misunderstanding your intention, you're jumping through many hoops when I do not believe they are necessary.

以下示例批处理文件应在通常的脚本目录中创建,如果愿意,甚至可以在文档"中创建.

The following example batch file should be created in your usual scripts directory, or even 'Documents' if you prefer.

然后,您应该在"SendTo"目录中为其创建快捷方式,为其提供一个您会理解的名称,也许是 MediaNFO .

Then you should create a shortcut to it in your 'SendTo' directory, giving it a name which you'll understand, perhaps MediaNFO.

现在您需要做的就是右键单击目录,然后选择发送到 MediaNFO .这应该在右键单击的目录中创建一个文件,该文件与该目录的名称相同,并包含该文件包含的每个受支持文件的 mediainfo 输出.完整名称行不应包含路径信息,而应仅包含文件名.

Now all you should need to do is right click on your directory and choose Send toMediaNFO. This should create a file within the right clicked directory, with the same name as that directory, and containing the mediainfo output for every supported file it contains. The Complete name line should not include the path information, only the File name.

@Echo Off
SetLocal EnableExtensions

Set "MIExe=%UserProfile%\Standalone\MediaInfo\MediaInfo.exe"
Set "OutExt=nfo"
Set "HR=------------------------------------------------------------------"

For %%G In ("%~1") Do If "%%~aG" Lss "d" (If "%%~aG" GEq "-" (
        Echo Error! File arg.
        GoTo EndIt) Else (Echo Error! Invalid directory arg.
        GoTo EndIt)) Else If "%%~dG" == "" (
    Echo Error! Full directory path required.
    GoTo EndIt)

If Not Exist "%MIExe%" (Echo Error! MediaInfo not found.
    GoTo EndIt)

PushD "%~1"

Set "ExtLst="
For %%G In (aac ac3 aifc aiff ape asf au avi avr dat dts flac iff ifo irca m1v
    m2v mac mat mka mks mkv mov mp2 mp3 mp4 mpeg mpg mpgv mpv ogg ogm paf pvf qt
    ra rm rmvb sd2 sds vob w64 wav wma wmv xi) Do If Not Defined ExtLst (
    Set "ExtLst=".":"*.%%G"") Else Call Set "ExtLst=%%ExtLst%% ".":"*.%%G""

Set "}=%PATHEXT%" && Set "PATHEXT="
%SystemRoot%\System32\where.exe /Q %ExtLst%
If ErrorLevel 1 (Echo Error! Directory has no supported files.
    GoTo EndIt)

Set "i="
(For /F "Delims=" %%G In ('%SystemRoot%\System32\where.exe %ExtLst% 2^> NUL'
) Do (If Defined i Echo %HR%
    "%MIExe%" "%%~nxG"
    Set "i=T")) 1> "%~nx1.%OutExt%"

:EndIt
%SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1> NUL
GoTo :EOF

您可以在 4 行上更改 mediainfo.exe 的位置,并在 5 行上更改输出扩展名.但别无其他修改.

You can change the location of mediainfo.exe on line 4, and the output extension, on line 5; but nothing else should be modified.

您还应该注意,我已经为此脚本添加了一些输入验证.如果您的输入目录不是包含现有mediainfo可执行文件支持文件的标准目录路径,它将报告错误并关闭.

You should also note that I've added some input validation to this script. If your input directory is not a fully qualified directory path containing supported files for an existing mediainfo executable, it will report an error and close.

这篇关于在文件夹内批处理文件以创建MediaInfo.nfo文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 00:49