second-state / chat-with-chatgpt

Chat with ChatGPT via GitHub issue comments.
110 stars 13 forks source link

Kodi *.nfo files and video tagging #378

Closed The-Bart-The closed 2 months ago

alabulei1 commented 2 months ago

Hello, I am your assistant on GitHub, built by the Second State team. I am ready for your question now!

The-Bart-The commented 2 months ago

I would like a Windows Batch script that tags a video based on the contents of a matching Kodi *.nfo file.

alabulei1 commented 2 months ago

Creating a Windows Batch script to tag a video based on the contents of a Kodi *.nfo file can involve multiple steps and tools. Here is a high-level overview of the process:

  1. Identify the video file and its corresponding *.nfo file in the directory.
  2. Parse the necessary information from the *.nfo file, such as Title, Genre, Year, etc.
  3. Use a tool or library that can add metadata/tags to the video file. For example, you can use FFmpeg for this task.
  4. Update the video file metadata/tags based on the information parsed from the *.nfo file.

Here is a basic example of how you can approach this using FFmpeg in a Windows Batch script:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo

rem Parse information from the *.nfo file
for /f "tokens=*" %%A in ('findstr /C:"<title>" "%NfoFilePath%"') do set Title=%%A
for /f "tokens=*" %%B in ('findstr /C:"<genre>" "%NfoFilePath%"') do set Genre=%%B
for /f "tokens=*" %%C in ('findstr /C:"<year>" "%NfoFilePath%"') do set Year=%%C

rem Use FFmpeg to add metadata/tags to the video file
set Metadata="title=%Title%:genre=%Genre%:year=%Year%"
%FFmpegPath% -i "%VideoFilePath%" -c copy -metadata title="%Title%" -metadata genre="%Genre%" -metadata year="%Year%" "output.mp4"

echo Video tagging completed.

In this script:

This is just a basic example to give you a starting point. Feel free to customize and expand upon this script to better suit your specific requirements. Let me know if you need more help!

The-Bart-The commented 2 months ago

Won’t the findstr command just return the entire line of the *.nfo file instead of just the value of the tag?

alabulei1 commented 2 months ago

You are correct. The findstr command in the provided script will return the entire line where the tag is found in the *.nfo file. If you want to extract only the value of the tag (e.g., the text within <title> </title> tags), you can modify the script to extract the value within the tags.

Here is an updated example script that extracts the values within the tags:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo

rem Function to extract the value between XML tags
:ExtractValue
for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do set Value=%%A
exit /b

rem Extract and assign values from the *.nfo file
call :ExtractValue title
set Title=!Value!
call :ExtractValue genre
set Genre=!Value!
call :ExtractValue year
set Year=!Value!

rem Use FFmpeg to add metadata/tags to the video file
set Metadata="title=%Title%:genre=%Genre%:year=%Year%"
%FFmpegPath% -i "%VideoFilePath%" -c copy -metadata title="%Title%" -metadata genre="%Genre%" -metadata year="%Year%" "output.mp4"

echo Video tagging completed.

In this updated script:

This modification should help in correctly extracting only the values within the tags from the *.nfo file. Feel free to test the script and adjust it further as needed. Let me know if you need any more assistance!

The-Bart-The commented 2 months ago

Could you include an intermediate step of writing the tags into a valid FFMETADATA1 file?

alabulei1 commented 2 months ago

Certainly! Adding an intermediate step to write the extracted tag values into a valid FFMETADATA1 file before using FFmpeg to apply the metadata/tags to the video file can be helpful. Here's an updated script that includes this intermediate step:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo
set MetadataFilePath=C:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags
:ExtractValue
for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do set Value=%%A
exit /b

rem Extract and assign values from the *.nfo file
call :ExtractValue title
set Title=!Value!
call :ExtractValue genre
set Genre=!Value!
call :ExtractValue year
set Year=!Value!

rem Write the metadata/tags to FFMETADATA1 file
echo title=%Title% > "%MetadataFilePath%"
echo genre=%Genre% >> "%MetadataFilePath%"
echo year=%Year% >> "%MetadataFilePath%"

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
%FFmpegPath% -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "output.mp4"

echo Video tagging completed.

In this updated script:

This additional step will help you store the metadata/tags in a separate file before applying them to the video file using FFmpeg. Please adjust the paths and customize the script as needed for your specific requirements. Let me know if you have any more questions or need further assistance!

The-Bart-The commented 2 months ago

a valid FFMETADATA1 file has

;FFMETADATA1

as the first line in the file

alabulei1 commented 2 months ago

Thank you for the clarification. Here's the updated script that includes the required ;FFMETADATA1 as the first line in the FFMETADATA1 file:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo
set MetadataFilePath=C:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags
:ExtractValue
for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do set Value=%%A
exit /b

rem Extract and assign values from the *.nfo file
call :ExtractValue title
set Title=!Value!
call :ExtractValue genre
set Genre=!Value!
call :ExtractValue year
set Year=!Value!

rem Write the metadata/tags to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
echo title=%Title% >> "%MetadataFilePath%"
echo genre=%Genre% >> "%MetadataFilePath%"
echo year=%Year% >> "%MetadataFilePath%"

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
%FFmpegPath% -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "output.mp4"

echo Video tagging completed.

In this updated script:

This modification ensures that the FFMETADATA1 file format is correct and aligns with the requirements for applying metadata/tags using FFmpeg. Feel free to test this script and let me know if you need further assistance!

The-Bart-The commented 2 months ago

Could you expand this to include every potential line in an .nfo file that’s also a legal .mkv video tag?

alabulei1 commented 2 months ago

To include every potential line in an .nfo file as legal .mkv video tags, you can extract all the lines between the <tag> and </tag> pairs in the .nfo file and write them into a FFMETADATA1 file. Here's an updated script that captures each tag value from the .nfo file and writes them to the FFMETADATA1 file:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo
set MetadataFilePath=C:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and convert to FFmpeg tag format
:ExtractTags
(for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do (
    set "Tag=%%A"
    set "Tag=!Tag:^|=^^!"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    echo %1=!Tag!
)) >> "%MetadataFilePath%"
exit /b

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags genre
call :ExtractTags year
call :ExtractTags director
call :ExtractTags actor
call :ExtractTags description

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
%FFmpegPath% -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "output.mkv"

echo Video tagging completed.

In this updated script:

This script should capture and include all potential tags from the .nfo file as legal .mkv video tags using FFmpeg. Customize it with additional tags as needed and test it with your *.nfo files. Let me know if you need further assistance or modifications!

The-Bart-The commented 2 months ago

What about season, episode number, network?

alabulei1 commented 2 months ago

To include additional tags like season, episode number, and network from the .nfo file as legal .mkv video tags, you can extend the script to extract and write these values. Here's an updated script that includes these tags in addition to the previously mentioned tags:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo
set MetadataFilePath=C:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and convert to FFmpeg tag format
:ExtractTags
(for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do (
    set "Tag=%%A"
    set "Tag=!Tag:^|=^^!"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    echo %1=!Tag!
)) >> "%MetadataFilePath%"
exit /b

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags genre
call :ExtractTags year
call :ExtractTags director
call :ExtractTags actor
call :ExtractTags description
call :ExtractTags season
call :ExtractTags episode
call :ExtractTags network

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
%FFmpegPath% -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "output.mkv"

echo Video tagging completed.

In this updated script:

You can customize this script further to include any other tags you may need from your *.nfo files. Test it with your data to ensure all desired tags are being extracted and applied correctly. Let me know if you require any more assistance or modifications!

The-Bart-The commented 2 months ago

What about necessary escape characters in the FFMETADATA1 file?

alabulei1 commented 2 months ago

To ensure that the extracted tag values from the *.nfo file are correctly formatted and escaped in the FFMETADATA1 file for use with FFmpeg, you can modify the script to handle necessary escape characters properly. Here's an updated script that includes proper escaping for special characters in the tag values:

@echo off

setlocal enabledelayedexpansion

rem Set path to FFmpeg executable
set FFmpegPath=C:\path\to\ffmpeg\ffmpeg.exe

rem Set path to video file and its corresponding *.nfo file
set VideoFilePath=C:\path\to\video\video.mp4
set NfoFilePath=C:\path\to\nfo\video.nfo
set MetadataFilePath=C:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and escape special characters for FFmpeg
:ExtractTags
for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do (
    set "Tag=%%A"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    (echo %1=!Tag!) >> "%MetadataFilePath%"
)
exit /b

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags genre
call :ExtractTags year
call :ExtractTags director
call :ExtractTags actor
call :ExtractTags description
call :ExtractTags season
call :ExtractTags episode
call :ExtractTags network

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
%FFmpegPath% -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "output.mkv"

echo Video tagging completed.

In this updated script:

You can test this script with your *.nfo files containing various special characters to verify that the tag values are correctly extracted, escaped, and applied as metadata/tags in the resulting video file. Let me know if you need further assistance or have any other requirements!

The-Bart-The commented 2 months ago

What if the script and video and *.nfo file are on a drive other than C: ?

alabulei1 commented 2 months ago

If you need to run the script and process files located on a drive other than C:, you can easily adjust the script to accommodate different drive letters. Here's an updated script that allows you to specify the drive letter for the locations of the script, video file, and NFO file:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and escape special characters for FFmpeg
:ExtractTags
for /f "tokens=2 delims=<>" %%A in ('findstr /C:"<%1>" "%NfoFilePath%"') do (
    set "Tag=%%A"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    (echo %1=!Tag!) >> "%MetadataFilePath%"
)
exit /b

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags genre
call :ExtractTags year
call :ExtractTags director
call :ExtractTags actor
call :ExtractTags description
call :ExtractTags season
call :ExtractTags episode
call :ExtractTags network

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

Modify the DriveLetter variable and update the paths accordingly based on your file locations. Run the script with these modifications to process your video, NFO file, and generate the output *.mkv file on the desired drive. If you have any specific requirements or need further assistance, feel free to ask!

The-Bart-The commented 2 months ago

can you add usebackq to the findstr command

alabulei1 commented 2 months ago

Absolutely! Adding usebackq to the findstr command allows it to treat the backquotes as command line input. Here's the updated script with usebackq included in the findstr command:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and escape special characters for FFmpeg
:ExtractTags
(for /f "usebackq tokens=2 delims=<>" %%A in ("%NfoFilePath%") do (
    set "Tag=%%A"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    (echo %1=!Tag!)
)) >> "%MetadataFilePath%"
exit /b

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags genre
call :ExtractTags year
call :ExtractTags director
call :ExtractTags actor
call :ExtractTags description
call :ExtractTags season
call :ExtractTags episode
call :ExtractTags network

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

By using usebackq in the for /f loop, the script should now handle the file input from %NfoFilePath% properly. Feel free to test the updated script and let me know if you need any more adjustments or assistance!

The-Bart-The commented 2 months ago

the FFMETADATA1 file outputted is not valid. its contents are

=title =originaltitle/ =showtitle =season =episode =displayseason =displayepisode =id =ratings/ =userrating =plot =runtime =thumb =mpaa/ =premiered =aired =watched =playcount/ =studio =credits =trailer/ =dateadded =epbookmark/ =code/ =fileinfo =streamdetails =video =codec =aspect =width =height =durationinseconds =stereomode/ =/video =audio =codec =language =channels =/audio =audio =codec =language =channels =/audio =subtitle =language =/subtitle =subtitle =language =/subtitle =subtitle =language =/subtitle =subtitle =language/ =/subtitle =subtitle =language/ =/subtitle =/streamdetails =/fileinfo

alabulei1 commented 2 months ago

It appears that there might have been an issue with how the tag values were being extracted and written to the FFMETADATA1 file. Let's update the script to ensure that the tag values are read correctly from the NFO file and written in the proper format for FFmpeg metadata.

Here's the revised script:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and escape special characters for FFmpeg
:ExtractTags
(for /f "usebackq tokens=2 delims=<>" %%A in ("%NfoFilePath%") do (
    set "Tag=%%A"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    (echo #!1=!Tag!)
)) >> "%MetadataFilePath%"
exit /b

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags originaltitle
call :ExtractTags showtitle
call :ExtractTags season
call :ExtractTags episode
call :ExtractTags ratings
call :ExtractTags plot
call :ExtractTags runtime
call :ExtractTags thumb
call :ExtractTags mpaa
call :ExtractTags premiered
call :ExtractTags aired
call :ExtractTags studio
call :ExtractTags source
call :ExtractTags original_filename
call :ExtractTags user_note

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this revised script:

Please give this updated script a try with your NFO file, and let me know if you encounter any further issues or if you need additional modifications.

The-Bart-The commented 2 months ago

now the contents are

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

Tag

alabulei1 commented 2 months ago

It seems that the tag values are being extracted correctly, but they are not being assigned to the appropriate FFmpeg metadata tags in the FFMETADATA1 file. Let's modify the script to ensure that each extracted tag value is paired with the corresponding FFmpeg metadata tag.

Here's the updated script:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Function to extract the value between XML tags and escape special characters for FFmpeg
:ExtractTags
for /f "usebackq tokens=2 delims=<>" %%A in ("%NfoFilePath%") do (
    set "Tag=%%A"
    set "Tag=!Tag:&=^&!"
    set "Tag=!Tag:<=^<!"
    set "Tag=!Tag:>=^>!"
    echo #!1=!Tag!>> "%MetadataFilePath%"
    exit /b
)

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"
call :ExtractTags title
call :ExtractTags originaltitle
call :ExtractTags showtitle
call :ExtractTags season
call :ExtractTags episode
call :ExtractTags ratings
call :ExtractTags plot
call :ExtractTags runtime
call :ExtractTags thumb
call :ExtractTags mpaa
call :ExtractTags premiered
call :ExtractTags aired
call :ExtractTags studio
call :ExtractTags source
call :ExtractTags original_filename
call :ExtractTags user_note

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this revised script:

Please try running this updated script with your NFO file and let me know if the FFMETADATA1 file now contains the expected tag values mapped to the appropriate FFmpeg metadata tags. Feel free to reach out if you encounter any further issues or need additional assistance.

The-Bart-The commented 2 months ago

now the contents are

Tag

alabulei1 commented 2 months ago

It seems that the script is only extracting and assigning the value of the first tag from the NFO file to the FFmpeg metadata tag, resulting in the repeated output of the same tag value in the FFMETADATA1 file. Let's modify the script to properly loop through all the tags in the NFO file and assign them to the corresponding FFmpeg metadata tags.

Here's the updated script:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Extract and write all tag values from the *.nfo file to FFMETADATA1 file
echo ;FFMETADATA1 > "%MetadataFilePath%"

rem Loop through each tag in the NFO file and assign it to the corresponding FFmpeg metadata tag
for /f "tokens=1,* delims==" %%A in ('findstr "=" "%NfoFilePath%"') do (
    set "TagName=%%A"
    set "TagValue=%%B"
    set "TagValue=!TagValue:&=^&!"
    set "TagValue=!TagValue:<=^<!"
    set "TagValue=!TagValue:>=^>!"
    echo !TagName!=!TagValue!>> "%MetadataFilePath%"
)

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

Please run this modified script with your NFO file and check if the FFMETADATA1 file now contains all the tag values mapped to their appropriate FFmpeg metadata tags. Let me know if you need any further assistance or encounter any issues.

The-Bart-The commented 2 months ago

now the contents are

;FFMETADATA1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?^> <uniqueid default="true" type="tvdb"^>10360064^</uniqueid^>

alabulei1 commented 2 months ago

It appears that the contents of the FFMETADATA1 file now contain XML elements and formatting that may not be compatible with FFmpeg's metadata format. To properly integrate the tag values from the NFO file into the FFmpeg metadata, we need to correctly parse the tag values and directly write them in FFmpeg's metadata format.

Let's update the script to handle the given XML format and extract the relevant tag value for the FFmpeg metadata.

Here's the modified script:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Parse the NFO file to extract the tag value and remove XML formatting
for /f "tokens=2 delims=^>" %%A in ('type "%NfoFilePath%" ^| findstr /i "uniqueid"') do (
    set "TagValue=%%A"
    set "TagValue=!TagValue:~0,-1!"  rem Remove the last character which is "^"
)

rem Write the extracted tag value to the FFMETADATA1 file in FFmpeg metadata format
echo uniqueid=!TagValue!>> "%MetadataFilePath%"

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

Please run this modified script with your NFO file and check if the FFMETADATA1 file now contains the extracted uniqueid value mapped to the appropriate FFmpeg metadata tag. Let me know if you encounter any issues or need further assistance.

The-Bart-The commented 2 months ago

I apologize for formatting that wrong.  The actual contents are

;FFMETADATA1 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?^>
  <uniqueid default="true" type="tvdb"^>10360064^</uniqueid^>
alabulei1 commented 2 months ago

Thank you for providing the correct format of the XML content within the NFO file. We will now adjust the script to correctly extract the tag value from the <uniqueid> element and utilize it for the FFmpeg metadata.

Here's the revised script to incorporate the updated XML content:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Parse the NFO file to extract the tag value from the uniqueid element
for /f "tokens=2 delims=^>" %%A in ('type "%NfoFilePath%" ^| findstr /i "<uniqueid"') do (
    set "TagValue=%%A"
    set "TagValue=!TagValue:~0,-1!"  rem Remove the last character which is "^"
)

rem Write the extracted tag value to the FFMETADATA1 file in FFmpeg metadata format
echo uniqueid=!TagValue!>> "%MetadataFilePath%"

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

Please run this revised script with your NFO file and verify if the FFMETADATA1 file now includes the extracted uniqueid value mapped to the appropriate FFmpeg metadata tag. Let me know if you need further assistance or encounter any issues.

The-Bart-The commented 2 months ago

That wasn’t the NFO file, it was the generated FFMETADATA1 file.

alabulei1 commented 2 months ago

I see, thank you for clarifying. Since the contents in the FFMETADATA1 file need to match the format expected by FFmpeg, we will need to adjust the script to handle the XML content in the NFO file correctly while extracting the tag values for the FFmpeg metadata.

Here's the updated script that properly extracts the tag value from the <uniqueid> element in the NFO file and writes it in the FFmpeg metadata format:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and NFO file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Extract the tag value from the uniqueid element in the NFO file
for /f "tokens=2 delims=^>" %%A in ('type "%NfoFilePath%" ^| findstr /i "<uniqueid"') do (
    set "TagValue=%%A"
    set "TagValue=!TagValue:~0,-1!"  rem Remove the last character which is "^"
)

rem Write the extracted tag value to the FFMETADATA1 file in FFmpeg metadata format
echo uniqueid=!TagValue!>> "%MetadataFilePath%"

rem Use FFmpeg to add metadata/tags from FFMETADATA1 file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

Please run this revised script with the NFO file containing the <uniqueid> element and check if the FFMETADATA1 file is now generated with the extracted uniqueid value formatted properly for FFmpeg metadata. Let me know if you need any further assistance or encounter any issues.

The-Bart-The commented 2 months ago

please ignore my prompt before my prompt before last and try again

alabulei1 commented 2 months ago

Certainly! Let's modify the script to correctly handle the generated FFMETADATA1 file instead of the NFO file. The script will extract the tag value from the FFMETADATA1 file and write it in the appropriate format for FFmpeg metadata.

Here's the updated script:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and metadata files
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, and metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt
set FFMETADATAFilePath=%DriveLetter%:\path\to\metadata\FFMETADATA1

rem Extract the tag value from the FFMETADATA1 file
for /f "usebackq tokens=1,* delims=<^> " %%a in ("%FFMETADATAFilePath%") do (
    if "%%a"=="uniqueid" (
        set "TagValue=%%b"
        echo uniqueid=!TagValue!>> "%MetadataFilePath%"
    )
)

rem Use FFmpeg to add metadata/tags from metadata file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

Please run this revised script with your FFMETADATA1 file and check if it correctly processes the tag value and applies it as metadata to the video file. Let me know if you encounter any issues or need further assistance.

The-Bart-The commented 2 months ago

I’m not looking for "uniqueid" specifically I’m looking for the values from when I wrote

the FFMETADATA1 file outputted is not valid. its contents are

=title =originaltitle/ =showtitle =season =episode =displayseason =displayepisode =id =ratings/ =userrating =plot =runtime =thumb =mpaa/ =premiered =aired =watched =playcount/ =studio =credits =trailer/ =dateadded =epbookmark/ =code/ =fileinfo =streamdetails =video =codec =aspect =width =height =durationinseconds =stereomode/ =/video =audio =codec =language =channels =/audio =audio =codec =language =channels =/audio =subtitle =language =/subtitle =subtitle =language =/subtitle =subtitle =language =/subtitle =subtitle =language/ =/subtitle =subtitle =language/ =/subtitle =/streamdetails =/fileinfo

alabulei1 commented 2 months ago

Thank you for providing the contents of the FFMETADATA1 file. Based on the information you shared, here is an updated script that correctly processes the values from the FFMETADATA1 file and writes them in the appropriate format for FFmpeg metadata:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and metadata files
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, and metadata files
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt
set FFMETADATAFilePath=%DriveLetter%:\path\to\metadata\FFMETADATA1

rem Extract the tag values from the FFMETADATA1 file and write them in FFmpeg metadata format
for /f "tokens=1,* delims==/ " %%a in ('type "%FFMETADATAFilePath%"') do (
    if "%%a" neq "" (
        echo %%a=%%b>> "%MetadataFilePath%"
    )
)

rem Use FFmpeg to add metadata/tags from metadata file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mkv"

echo Video tagging completed.

In this updated script:

Please run this revised script with your FFMETADATA1 file and verify if it correctly processes the tag values and adds them as metadata to the video file. Feel free to let me know if you need further assistance or encounter any issues.

The-Bart-The commented 2 months ago

We need to start over completely.

I would like a Windows Batch script that tags a video based on the contents of a matching Kodi *.nfo file.

alabulei1 commented 2 months ago

Understood! Let's start fresh with a new Windows Batch script that tags a video based on the contents of a matching Kodi .nfo file. The script will extract metadata from the .nfo file and apply it to the video using FFmpeg.

Here's a step-by-step guide to achieve this:

  1. First, make sure you have the FFmpeg executable available on your system.

  2. Create a new Windows Batch script (let's name it tag_video_from_nfo.bat).

  3. Add the following code into the Batch script:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, NFO file, and output file
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, NFO file, and output file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set NfoFilePath=%DriveLetter%:\path\to\nfo\video.nfo
set OutputFilePath=%DriveLetter%:\path\to\output\output.mp4

rem Read metadata tags from the Kodi .nfo file
for /f "tokens=1,* delims=: " %%a in ('type "%NfoFilePath%" ^| findstr /i /c:"<title>" /c:"<plot>" /c:"<year>" /c:"<director>" /c:"<genre>"') do (
    set "Tag=%%a"
    set "Data=%%b"
    if defined Data (
        echo !Tag!=!Data!>> temp_metadata.txt
    )
)

rem Use FFmpeg to add metadata/tags from temp_metadata.txt to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i temp_metadata.txt -map_metadata 1 -c copy "%OutputFilePath"

rem Clean up temporary metadata text file
del temp_metadata.txt

echo Video tagging completed.
  1. In this script:

    • Update the DriveLetter and set the correct paths for FFmpeg, video file, .nfo file, and output file.
    • The script reads specific metadata tags (<title>, <plot>, <year>, <director>, <genre>) from the Kodi .nfo file and stores them in a temporary metadata text file.
    • It then uses FFmpeg to add this metadata to the video file and saves the tagged video as the output file.
    • Finally, the script cleans up the temporary metadata text file.
  2. Save the Batch script and run it from the command line to tag your video based on the metadata from the matching Kodi .nfo file.

Please adjust the script paths and metadata tags according to your Kodi .nfo file structure. Let me know if you need further customization or assistance with the script.

The-Bart-The commented 2 months ago

The contents of the intermediate FFMETADATA1 file are

<title>Clan=of the Cave Mom</title>
<plot>A=parenting disagreement between Marge and Luann Van Houten escalates into a life-or-death struggle for survival.</plot>
alabulei1 commented 2 months ago

Thank you for providing the contents of the intermediate FFMETADATA1 file. Based on the data format you provided, we can modify the script to read tag-value pairs enclosed in <tag> and </tag> from the file and generate metadata for FFmpeg.

Here is the updated script based on the provided metadata format:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and metadata files
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, and intermediate metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set IntermediateMetadataFilePath=%DriveLetter%:\path\to\metadata\FFMETADATA1
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Read tag-value pairs from the intermediate metadata file and convert them to FFmpeg metadata
(for /f "usebackq tokens=2,3 delims=<>" %%a in ("%IntermediateMetadataFilePath%") do (
    echo %%a=%%b>> "%MetadataFilePath%"
))

rem Use FFmpeg to add metadata/tags from metadata file to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%MetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mp4"

echo Video tagging completed.

In this updated script:

Please run this revised script with your provided metadata file and let me know if it correctly processes the data and applies them as metadata to the video file. If you have any more details or specific requirements, feel free to share them.

The-Bart-The commented 2 months ago

no, the intermediate FFMETADATA1 file was the one generated by your previous script called temp_metadata.txt and not a previously existing file.

alabulei1 commented 2 months ago

I see, thank you for clarifying. In that case, we can modify the script to directly process the extracted tag-value pairs from the temporary metadata file (previously named temp_metadata.txt). Here is the updated script that incorporates this change:

@echo off
setlocal enabledelayedexpansion

rem Set the drive letter for the script, video file, and metadata files
set DriveLetter=D

rem Set the paths to FFmpeg executable, video file, and intermediate metadata file
set FFmpegPath=%DriveLetter%:\path\to\ffmpeg\ffmpeg.exe
set VideoFilePath=%DriveLetter%:\path\to\video\video.mp4
set TemporaryMetadataFilePath=%DriveLetter%:\path\to\metadata\temp_metadata.txt
set MetadataFilePath=%DriveLetter%:\path\to\metadata\metadata.txt

rem Use FFmpeg to add metadata/tags from temp_metadata.txt to the video file
"%FFmpegPath%" -i "%VideoFilePath%" -i "%TemporaryMetadataFilePath%" -map_metadata 1 -c copy "%DriveLetter%:\path\to\output\output.mp4"

echo Video tagging completed.

In this updated script:

Run the script with the appropriate paths and filenames to tag the video based on the extracted metadata from the temporary file. Let me know if you encounter any issues or need further assistance.

The-Bart-The commented 2 months ago

You’ve gone off in the wrong direction again.  We need to start over completely.

I would like a Windows Batch script that generates a FFMETADATA1file for a video based on the contents of its matching Kodi .nfo file.  Some XML parsing will of course be required.  Some escape characters for the FFMETADATA1file will of course need to be generated.  The .nfo file path will be passed to the batch script as its only parameter.

alabulei1 commented 2 months ago

Understood. Let's create a new Windows Batch script that generates an FFMETADATA1 file for a video based on the metadata extracted from its matching Kodi .nfo file. The script will perform XML parsing to extract metadata and generate appropriate escape characters for the FFMETADATA1 file.

Here's the batch script that takes the .nfo file path as a parameter and generates the FFMETADATA1 file:

@echo off
setlocal enabledelayedexpansion

rem Check if the script is invoked with the correct parameter
if "%~1"=="" (
    echo Usage: %0 "full_path_to_nfo_file"
    exit /b
)

rem Set the path to the FFmpeg metadata file
set MetadataFilePath=FFMETADATA1

rem Initialize the FFMETADATA1 file
echo [TITLE] > %MetadataFilePath
echo > %MetadataFilePath

rem Extract metadata tags from the Kodi .nfo file and generate FFmpeg metadata
for /f "tokens=1,* delims=<>" %%a in ('type %1 ^| findstr /i /c:"<title>" /c:"<plot>" /c:"<year>" /c:"<director>" /c:"<genre>"') do (
    set "Tag=%%a"
    set "Data=%%b"

    rem Handle special characters in metadata
    set "Data=!Data:<=^<!"
    set "Data=!Data:>=^>!"

    rem Append metadata to the FFMETADATA1 file
    echo !Tag!=!Data!>> %MetadataFilePath
)

echo FFmpeg metadata file generated successfully.

In this script:

To use the script, save it with a .bat extension, and run it from the command line with the full path to the Kodi .nfo file as a parameter. Let me know if you need any further assistance or customization.

The-Bart-The commented 2 months ago

The generated FFMETADATA1 file which you have named MetadataFilePath is not a valid FFMETADATA1 file.  Its contents are:

ECHO is off.
  =title^>Clan of the Cave Mom^</title^>
  =plot^>A parenting disagreement between Marge and Luann Van Houten escalates into a life-or-death struggle for survival.^</plot^>
alabulei1 commented 2 months ago

I apologize for the oversight. Let's correct the script to ensure that the generated FFMETADATA1 file contains valid FFmpeg metadata format. We will adjust the escaping of special characters and provide the appropriate formatting for FFmpeg metadata tags.

Here is an updated version of the script:

@echo off
setlocal enabledelayedexpansion

rem Check if the script is invoked with the correct parameter
if "%~1"=="" (
    echo Usage: %0 "full_path_to_nfo_file"
    exit /b
)

rem Set the path to the FFmpeg metadata file
set MetadataFilePath=FFMETADATA1

rem Initialize the FFMETADATA1 file with header
echo [TITLE] > %MetadataFilePath
echo > %MetadataFilePath

rem Extract metadata tags from the Kodi .nfo file and generate FFmpeg metadata
for /f "usebackq tokens=2,3 delims=<>" %%a in (`type "%~1" ^| findstr /i "title plot year director genre"`) do (
    set "Tag=%%a"
    set "Data=%%b"

    rem Remove leading and trailing whitespaces from the data
    for /f "tokens=*" %%d in ("!Data!") do (
        set "Data=%%d"
    )

    rem Handle special characters in metadata
    set "Data=!Data:<^=^<!"
    set "Data=!Data:>^=^>!"

    rem Append metadata to the FFMETADATA1 file in FFmpeg format
    echo !Tag!=!Data!>> %MetadataFilePath
)

echo FFmpeg metadata file generated successfully.

In this updated script:

To use the script, save it with a .bat extension and run it from the command line with the full path to the Kodi .nfo file as a parameter. The script should now generate a valid FFMETADATA1 file based on the metadata extracted from the .nfo file. Let me know if you encounter any issues or if you need further assistance.

The-Bart-The commented 2 months ago

The generated FFMETADATA1 file which you have named MetadataFilePath is still not a valid FFMETADATA1 file.  Its contents are:

ECHO is off.
title=Clan of the Cave Mom
originaltitle/=<=<
showtitle=The Simpsons
plot=A parenting disagreement between Marge and Luann Van Houten escalates into a life-or-death struggle for survival.
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
alabulei1 commented 2 months ago

I apologize for the oversight. Let's correct the script to ensure that the generated FFMETADATA1 file contains valid FFmpeg metadata format with proper tag-value pairs and appropriate escaping.

Here is an updated version of the script:

@echo off
setlocal enabledelayedexpansion

REM Check if the script is invoked with the correct parameter
if "%~1"=="" (
    echo Usage: %0 "full_path_to_nfo_file"
    exit /b
)

REM Set the path to the FFmpeg metadata file
set MetadataFilePath=FFMETADATA1

REM Initialize the FFMETADATA1 file with header
echo [FORMAT] > %MetadataFilePath
echo > %MetadataFilePath

REM Extract metadata tags from the Kodi .nfo file and generate FFmpeg metadata
for /f "usebackq tokens=2,3 delims=<>" %%a in (`type "%~1" ^| findstr /i "title plot year director genre"`) do (
    set "Tag=%%a"
    set "Data=%%b"

    REM Remove leading and trailing whitespaces and special characters from the data
    set "Data=!Data:<=^<!"
    REM Escape special characters in the data
    set "Data=!Data:>=^>!"
    set "Data=!Data:/=<=<!"

    REM Append metadata to the FFMETADATA1 file in FFmpeg format
    echo !Tag!=!Data!>> %MetadataFilePath
)

echo FFmpeg metadata file generated successfully.

In this updated script:

Please save the updated script with a .bat extension and run it from the command line with the full path to the Kodi .nfo file as a parameter. The script should now generate a valid FFMETADATA1 file. Let me know if you encounter any issues or if you need further assistance.

The-Bart-The commented 2 months ago

The generated FFMETADATA1 file which you have named MetadataFilePath is still not a valid FFMETADATA1 file.  Its contents are:

ECHO is off.
title=Clan of the Cave Mom
originaltitle/=<=<
showtitle=The Simpsons
plot=A parenting disagreement between Marge and Luann Van Houten escalates into a life-or-death struggle for survival.
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
subtitle=<=<
/subtitle=<=<
alabulei1 commented 2 months ago

I apologize for the oversight. It seems there was a mistake in the script's logic. Let's make some adjustments to ensure that the FFmpeg metadata is generated correctly from the Kodi .nfo file.

Here is an updated version of the script:

@echo off
setlocal enabledelayedexpansion

REM Check if the script is invoked with the correct parameter
if "%~1"=="" (
    echo Usage: %0 "full_path_to_nfo_file"
    exit /b
)

REM Set the path to the FFmpeg metadata file
set MetadataFilePath=FFMETADATA1

REM Initialize the FFMETADATA1 file with header
echo [FORMAT] > %MetadataFilePath
echo > %MetadataFilePath

REM Extract metadata tags from the Kodi .nfo file and generate FFmpeg metadata
for /f "tokens=2,3 delims=<>" %%a in ('type "%~1" ^| findstr /i "title plot year director genre"') do (
    set "Tag=%%a"
    set "Data=%%b"

    REM Remove leading and trailing whitespaces from the data
    for /f "tokens=*" %%d in ("!Data!") do (
        set "Data=%%d"
    )

    REM Handle special characters in metadata
    set "Data=!Data:<=^<!"
    set "Data=!Data:>=^>!"
    set "Data=!Data:/=<=<!"

    REM Append metadata to the FFMETADATA1 file in FFmpeg format
    echo !Tag!=!Data!>> %MetadataFilePath
)

echo FFmpeg metadata file generated successfully.

In this updated script:

Please save the updated script with a .bat extension and run it from the command line with the full path to the Kodi .nfo file as a parameter. The updated script should now generate a valid FFMETADATA1 file. Let me know if you encounter any issues or if you need further assistance.

The-Bart-The commented 2 months ago

The generated FFMETADATA1 file which you have named MetadataFilePath is still not a valid FFMETADATA1 file.  Its contents are exactly as before.  You’ll need to filter out empty XML tags and keep ECHO is off. from entering the FFMETADATA1 file.  Also all valid FFMETADATA1 files include ;FFMETADATA1 at the head of the file.