2011-03-16, 04:32 PM
I have created a batch file to rename recordings to the following format:
1. Title (YYYY-MM-DD HHMM) Subtitle
or if the Subtitle is blank or the same as the title
2. Title (YYYY-MM-DD HHMM) Description
This seems to work well with me to be called out in the postprocessing.bat.
Comments are welcomed.
The tools necessary to run this are: sqlite3.exe and replace.vbs.
-------------beginning of replace.vbs--------------
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close
----------------end of replace.vbs-----------------
--------------beginning of batch file----------------
@ECHO OFF
TITLE NPVR Automatic Recording File Rename
SETLOCAL
IF [%1]==[] GOTO END
::====== Program locations ====
SET DB=C:\Users\Public\NPVR\npvr.DB3
SET SQLITE3="C:\Users\Public\NPVR\Rename Recordings\SQLITE3.exe"
SET REPLACE="C:\Program Files (x86)\CLI\REPLACE.vbs"
::====== File locations ====
SET PROGINFO=%TEMP%\%RANDOM%%RANDOM%.TXT
SET TEMPFILE=%TEMP%\%RANDOM%%RANDOM%.TXT
SET OLDFNAME=%~dpnx1
SET NPVRLOG="C:\Users\Public\NPVR\Rename Recordings\NPVR Rename Log.txt"
::====== Begin Log file ===========
ECHO ORIGINAL FILE: %1>>%NPVRLOG%
::====== Query SQLite3 to dump Title, Date, Description and Subtitle to text file ====
%SQLITE3% "%DB%" "SELECT event_details from SCHEDULED_RECORDING where status = '2' and filename = '%OLDFNAME%';">%PROGINFO%
::====== Capture Title ===
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Title" %PROGINFO%') DO ECHO %%a>%TEMPFILE%
::========= Log Results ====
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Title" %PROGINFO%') DO ECHO RENAMED WITH TITLE: %%a>>%NPVRLOG%
::====== Replace HTML tags and DOS filename and batch problem characters with corresponding acceptable characters ===
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "'" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% """ "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "]"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "\" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "/" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ":" " -"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "*" "#"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "?" "!"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "{"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "}"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "|" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "%" "percent"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "''" "'"
SET /P TITLE=<%TEMPFILE%
IF "%TITLE%"=="" GOTO END
ECHO Title: %TITLE%
::====== Capture Subtitle ====
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/SUBTITLE" %PROGINFO%') DO ECHO %%a>%TEMPFILE%
::========= Log Results =======
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/SUBTITLE" %PROGINFO%') DO ECHO RENAMED WITH SUBTITLE: %%a>>%NPVRLOG%
::====== Replace HTML tags and DOS filename and batch problem characters with corresponding acceptable characters ===
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "'" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% """ "''"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "]"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "\" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "/" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ":" " -"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "*" "#"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "?" "!"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "{"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "}"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "|" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "%" "percent"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "''" "'"
SET /P SUBTITLE=<%TEMPFILE%
IF "%SUBTITLE%"=="" GOTO END
ECHO Subtitle: "%SUBTITLE%"
::====== Capture Description ======
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Description" %PROGINFO%') DO ECHO %%a>%TEMPFILE%
::========= Log Results ========
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Description" %PROGINFO%') DO ECHO RENAMED WITH DESCRIPTION: %%a>>%NPVRLOG%
::====== Replace HTML tags and DOS filename and batch problem characters with corresponding acceptable characters =====
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "'" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% """ "''"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "]"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "\" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "/" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ":" " -"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "*" "#"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "?" "!"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "{"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "}"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "|" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "%" "percent"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "''" "'"
SET /P DESCRIPTION=<%TEMPFILE%
IF "%DESCRIPTION%"=="" GOTO END
ECHO Description: "%DESCRIPTION%"
::====== Capture Date & Time ======
FOR /F "tokens=3-7 delims=>T:-" %%a IN ('FIND "/StartTime" %PROGINFO%') DO SET DATETIME=%%a-%%b-%%c %%d%%e
::========= Log Results =====
ECHO RENAMED WITH DATE/TIME: %DATETIME%>>%NPVRLOG%
IF "Date/Time: %DATETIME%"=="" GOTO END
::======== Set intial value for counter ======
SET /A i=1
::======== Route to desired naming format depending on subtitle and description values ===
IF "%SUBTITLE%" NEQ "" GOTO SUBNUL
IF "%SUBTITLE%" NEQ "%TITLE%" GOTO SUBNEQTITLE
IF "%SUBTITLE%" EQU "%TITLE%" GOTO SUBEQUTITLE
::======== If Subtitle is not blank ======
:SUBNUL
IF "%SUBTITLE%" EQU "%TITLE%" GOTO SUBEQUTITLE
ECHO %TITLE% (%DATETIME%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNULDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:SUBNULDUP
ECHO %TITLE% (%DATETIME%) (%i%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
SET /A i=%i%+1
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNULDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
::======== If Subtitle and Title are not equal ====
:SUBNEQTITLE
ECHO %TITLE% (%DATETIME%) %SUBTITLE%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO "%~dp1%NEWFNAME%>%TEMPFILE%">%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNEQTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:SUBNEQTITLEDUP
ECHO %TITLE% (%DATETIME%) (%i%) %SUBTITLE%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
SET /A i=%i%+1
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNEQTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
::======== If Subtitle and Title are equal ====
:SUBEQUTITLE
ECHO %TITLE% (%DATETIME%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
IF EXIST "%NEWFNAMEPATH%" GOTO SUBEQUTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:SUBEQUTITLEDUP
ECHO %TITLE% (%DATETIME%) (%i%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
SET /A i=%i%+1
IF EXIST "%NEWFNAMEPATH%" GOTO SUBEQUTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:NAMEDONE
::========= Ensure that the target file name doesnt already exist (again) and then rename to new file name =====
IF NOT EXIST "%NEWFNAMEPATH%" RENAME %1 "%NEWFNAME%"
::========= Ensure that the target file name does exist now and then update the SQLite3 database ====
IF EXIST "%NEWFNAMEPATH%" %SQLITE3% %DB% "update scheduled_recording SET filename = '%NEWFNAMEPATH%' where status = '2' and filename = '%OLDFNAME%';"
::========= Log Results ======
IF EXIST "%NEWFNAMEPATH%" ECHO RENAMED TO: "%NEWFNAME%">>%NPVRLOG%
:END
::========= Delete temp files =======
IF EXIST %PROGINFO% DEL %PROGINFO%
IF EXIST %TEMPFILE% DEL %TEMPFILE%
1. Title (YYYY-MM-DD HHMM) Subtitle
or if the Subtitle is blank or the same as the title
2. Title (YYYY-MM-DD HHMM) Description
This seems to work well with me to be called out in the postprocessing.bat.
Comments are welcomed.
The tools necessary to run this are: sqlite3.exe and replace.vbs.
-------------beginning of replace.vbs--------------
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close
----------------end of replace.vbs-----------------
--------------beginning of batch file----------------
@ECHO OFF
TITLE NPVR Automatic Recording File Rename
SETLOCAL
IF [%1]==[] GOTO END
::====== Program locations ====
SET DB=C:\Users\Public\NPVR\npvr.DB3
SET SQLITE3="C:\Users\Public\NPVR\Rename Recordings\SQLITE3.exe"
SET REPLACE="C:\Program Files (x86)\CLI\REPLACE.vbs"
::====== File locations ====
SET PROGINFO=%TEMP%\%RANDOM%%RANDOM%.TXT
SET TEMPFILE=%TEMP%\%RANDOM%%RANDOM%.TXT
SET OLDFNAME=%~dpnx1
SET NPVRLOG="C:\Users\Public\NPVR\Rename Recordings\NPVR Rename Log.txt"
::====== Begin Log file ===========
ECHO ORIGINAL FILE: %1>>%NPVRLOG%
::====== Query SQLite3 to dump Title, Date, Description and Subtitle to text file ====
%SQLITE3% "%DB%" "SELECT event_details from SCHEDULED_RECORDING where status = '2' and filename = '%OLDFNAME%';">%PROGINFO%
::====== Capture Title ===
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Title" %PROGINFO%') DO ECHO %%a>%TEMPFILE%
::========= Log Results ====
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Title" %PROGINFO%') DO ECHO RENAMED WITH TITLE: %%a>>%NPVRLOG%
::====== Replace HTML tags and DOS filename and batch problem characters with corresponding acceptable characters ===
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "'" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% """ "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "]"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "\" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "/" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ":" " -"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "*" "#"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "?" "!"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "{"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "}"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "|" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "%" "percent"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "''" "'"
SET /P TITLE=<%TEMPFILE%
IF "%TITLE%"=="" GOTO END
ECHO Title: %TITLE%
::====== Capture Subtitle ====
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/SUBTITLE" %PROGINFO%') DO ECHO %%a>%TEMPFILE%
::========= Log Results =======
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/SUBTITLE" %PROGINFO%') DO ECHO RENAMED WITH SUBTITLE: %%a>>%NPVRLOG%
::====== Replace HTML tags and DOS filename and batch problem characters with corresponding acceptable characters ===
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "'" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% """ "''"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "]"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "\" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "/" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ":" " -"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "*" "#"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "?" "!"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "{"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "}"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "|" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "%" "percent"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "''" "'"
SET /P SUBTITLE=<%TEMPFILE%
IF "%SUBTITLE%"=="" GOTO END
ECHO Subtitle: "%SUBTITLE%"
::====== Capture Description ======
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Description" %PROGINFO%') DO ECHO %%a>%TEMPFILE%
::========= Log Results ========
FOR /F "tokens=3 delims=<>" %%a IN ('FIND "/Description" %PROGINFO%') DO ECHO RENAMED WITH DESCRIPTION: %%a>>%NPVRLOG%
::====== Replace HTML tags and DOS filename and batch problem characters with corresponding acceptable characters =====
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "'" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% """ "''"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "]"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "\" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "/" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ":" " -"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "*" "#"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "?" "!"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "<" "{"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% ">" "}"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "|" "-"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "%" "percent"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "''" "'"
SET /P DESCRIPTION=<%TEMPFILE%
IF "%DESCRIPTION%"=="" GOTO END
ECHO Description: "%DESCRIPTION%"
::====== Capture Date & Time ======
FOR /F "tokens=3-7 delims=>T:-" %%a IN ('FIND "/StartTime" %PROGINFO%') DO SET DATETIME=%%a-%%b-%%c %%d%%e
::========= Log Results =====
ECHO RENAMED WITH DATE/TIME: %DATETIME%>>%NPVRLOG%
IF "Date/Time: %DATETIME%"=="" GOTO END
::======== Set intial value for counter ======
SET /A i=1
::======== Route to desired naming format depending on subtitle and description values ===
IF "%SUBTITLE%" NEQ "" GOTO SUBNUL
IF "%SUBTITLE%" NEQ "%TITLE%" GOTO SUBNEQTITLE
IF "%SUBTITLE%" EQU "%TITLE%" GOTO SUBEQUTITLE
::======== If Subtitle is not blank ======
:SUBNUL
IF "%SUBTITLE%" EQU "%TITLE%" GOTO SUBEQUTITLE
ECHO %TITLE% (%DATETIME%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNULDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:SUBNULDUP
ECHO %TITLE% (%DATETIME%) (%i%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
SET /A i=%i%+1
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNULDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
::======== If Subtitle and Title are not equal ====
:SUBNEQTITLE
ECHO %TITLE% (%DATETIME%) %SUBTITLE%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO "%~dp1%NEWFNAME%>%TEMPFILE%">%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNEQTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:SUBNEQTITLEDUP
ECHO %TITLE% (%DATETIME%) (%i%) %SUBTITLE%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
SET /A i=%i%+1
IF EXIST "%NEWFNAMEPATH%" GOTO SUBNEQTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
::======== If Subtitle and Title are equal ====
:SUBEQUTITLE
ECHO %TITLE% (%DATETIME%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
IF EXIST "%NEWFNAMEPATH%" GOTO SUBEQUTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:SUBEQUTITLEDUP
ECHO %TITLE% (%DATETIME%) (%i%) %DESCRIPTION%%~x1>%TEMPFILE%
SET /P NEWFNAME=<%TEMPFILE%
ECHO %~dp1%NEWFNAME%>%TEMPFILE%
SET /P NEWFNAMEPATH=<%TEMPFILE%
SET /A i=%i%+1
IF EXIST "%NEWFNAMEPATH%" GOTO SUBEQUTITLEDUP
IF NOT EXIST "%NEWFNAMEPATH%" GOTO NAMEDONE
:NAMEDONE
::========= Ensure that the target file name doesnt already exist (again) and then rename to new file name =====
IF NOT EXIST "%NEWFNAMEPATH%" RENAME %1 "%NEWFNAME%"
::========= Ensure that the target file name does exist now and then update the SQLite3 database ====
IF EXIST "%NEWFNAMEPATH%" %SQLITE3% %DB% "update scheduled_recording SET filename = '%NEWFNAMEPATH%' where status = '2' and filename = '%OLDFNAME%';"
::========= Log Results ======
IF EXIST "%NEWFNAMEPATH%" ECHO RENAMED TO: "%NEWFNAME%">>%NPVRLOG%
:END
::========= Delete temp files =======
IF EXIST %PROGINFO% DEL %PROGINFO%
IF EXIST %TEMPFILE% DEL %TEMPFILE%