NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Information Community Announcements v
« Previous 1 … 6 7 8 9 10 … 56 Next »
NPVR Rename Recordings Batch File

 
  • 0 Vote(s) - 0 Average
NPVR Rename Recordings Batch File
raceviper13
Offline

Junior Member

UA
Posts: 33
Threads: 4
Joined: Jun 2007
#1
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% "&apos;" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&amp;" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&quot;" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&gt;" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&lt;" "]"
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% "&apos;" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&amp;" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&quot;" "''"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&gt;" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&lt;" "]"
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% "&apos;" "'"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&amp;" "and"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&quot;" "''"
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&gt;" "["
CSCRIPT.EXE //NoLogo %REPLACE% %TEMPFILE% "&lt;" "]"
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%
gEd
Offline

Posting Freak

London
Posts: 3,514
Threads: 100
Joined: Jan 2005
#2
2011-03-16, 10:29 PM
fantastic!

I was trying to figure out how to do this myself but my programming is not good enough (certainly not in dos). I will test it out. Many thanks for sharing.
“If this is the way Queen Victoria treats her prisoners, she doesn't deserve to have any.”
b00sfuk
Offline

Senior Member

Posts: 319
Threads: 26
Joined: Mar 2005
#3
2011-03-17, 08:14 PM
Very interested in this as was spoilt with Renamerecordings with GB-PVR. Had a quick play and it runs but had a few problems. Will look again at weekend when I have more time but I saw:

Files without a subtitle did not rename
Files with a subtitle renamed but with the (long) description (not subtitle) as a filename. Also did not seem to update db as entry disappeared from recordings screen.

Might be me as I was rushed but need more time to review.

Thanks for your work.
Silverstone LC10M with iMON
Gigabyte 780G+4850e, AMD 6570
Blackgold BGT3620, Harmony 555 Remote
Win7 32-bit, SAF
wtg
Offline

Posting Freak

Posts: 1,402
Threads: 120
Joined: Mar 2005
#4
2011-03-17, 09:31 PM
Impressive batch file, though it reminds me why I don't like trying to do anything complicated in a batch file. Smile

I haven't tried the batch file but looking through it, it doesn't appear to handle updating the filename in the recording's associated alternative datastream file, correct? Perhaps I'm simply overlooking it. If it doesn't I don't think it's a problem but I'm not 100% certain.
raceviper13
Offline

Junior Member

UA
Posts: 33
Threads: 4
Joined: Jun 2007
#5
2011-03-18, 11:46 AM
Thanks for the feedback. You'll definitely want to try this out on your own system and configure as necessary. I should have mentioned that everyone should use at their own risk and that you'll want to try this out on a copy of the db prior to assessing it's usability.

b00sfuk: I don't know why ones without a subtitle didn't rename or why ones with a subtitle renamed, but with a long description instead of the subtitle.

wtg: I don't know what "the recording's associated alternative datastream file" is. You may have to let me know what that is.

I was really hoping someone else would solve this one before I had to go and write a rudimentary batch file. If not, we'll have to get as much input from everyone to make sure it works well for more than just me.
wtg
Offline

Posting Freak

Posts: 1,402
Threads: 120
Joined: Mar 2005
#6
2011-03-18, 02:49 PM
On an NTFS volume, NPVR records the event details XML data in an alternative data stream (ADS) attached to the recording and this XML file also contains the recording's filename. If your recording is 'RAMBO.TS', it also an associated 'RAMBO.TS:metadata.xml' ADS too. On non-NTFS volumes this data is now written as a separate file.

Windows doesn't make alternate data streams easy to see but if you type 'MORE < RAMBO.TS:metadata.xml' you can see the data. (Notice the < input redirection... it's necessary). Also, I think notepad can view them too... notepad 'RAMBO.TS:metadata.xml' will open the file.

I'm not sure of all the details as to why NPVR does this but it's nice in the event that you're recording database is lost... all the recording details are preserved in the ADS file and there are a couple utilities around that will re-import them for you. Also, NPVR's Video Library uses the ADS file to show you the recording details when you select a recording instead of fetching it out of the DB.

I tell you all of this only because I know the recording's file name is preserved in the ADS metadata.xml. I don't think it'll hurt anything if the name in the metadata doesn't match following a file rename, but I don't know that for certain either.

If you want more info just search the forums for metadata.xml. Also you might be interested to know there's also a recording.ts:timing.info ADS too containing timing data sub uses for more accurate skips.
raceviper13
Offline

Junior Member

UA
Posts: 33
Threads: 4
Joined: Jun 2007
#7
2011-03-30, 07:00 PM
I've improved the batch code just a bit. Again, please look at the comments and know that you should 'rem' out a few lines to make sure that undesired changes will be made before making the changes.

--added metadata.xml update
--added character limit to description of 100 as too many characters in the file name will cause very strange results.

see attached updated bat
JimF
Offline

Member

Posts: 217
Threads: 19
Joined: Oct 2005
#8
2011-04-22, 12:06 AM
Thanks a lot, the lack of subtitles is what has been holding me back on NPVR. But I notice a couple of things:

When I record two programs simultaneously (which is possible with HDHomeRun), the show that should have the subtitle is not changed; it has only the original title (e.g., Without a Trace_20110421_18001900.ts).

But the other show picks up both the title and subtitle of the first show. For example, a show in the series "PCN Tours" is titled "Without a Trace (2011-04-21 2200) The team finds plenty of suspects when a high-end Russian matchmaker disappears.ts". Also, as you can see, the "subtitle" is not really the subtitle at all, but rather the description of the show.

If I can provide any more details, just let me know what you need, or maybe I can change something in the PostProcessing.bat file?
HDHomeRun Prime, Win7 64-bit, NPVR 3.4.8
raceviper13
Offline

Junior Member

UA
Posts: 33
Threads: 4
Joined: Jun 2007
#9
2011-04-23, 11:52 PM
I've made some updates to the program. I'm sorry, but you may have to debug your own batch file as I have this configured for my own system and I don't have any time to make it more universal for everyone. You would want to go through this line by line to get it configured for your system.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  BlueRetroVE+ skin for NPVR Jaggy 101 40,386 2018-01-10, 04:48 AM
Last Post: pitbull1969
  NextBlue skin for npvr Northpole 162 61,912 2015-12-16, 07:39 PM
Last Post: Northpole
  GuidePlus for NPVR carpeVideo 143 54,353 2015-07-12, 06:06 PM
Last Post: madas
  HD Logos for the NPVR WebRadio Plugin Lao Pan 3 3,380 2014-02-09, 01:32 PM
Last Post: Lao Pan
  xnpvrcli - linux/unix client for NPVR tmrt 43 21,385 2013-06-08, 01:18 PM
Last Post: Reddwarf
  External tool: Transfer Season Record schedules from GBPVR to NPVR kendrak24 37 20,923 2013-04-11, 05:58 AM
Last Post: kendrak24
  Yet Another RenameRecordings Batch files SANGER_A2 53 28,065 2012-06-16, 06:45 AM
Last Post: SANGER_A2
  SSPlus v1.0.0 (Screensaver for NPVR) ACTCMS 12 4,920 2012-01-28, 10:03 PM
Last Post: mvallevand
  Just:Retro skin for NextPVR (npvr) Jaggy 4 2,599 2012-01-22, 10:42 PM
Last Post: Jaggy
  SearchLite - Yet Another NPVR Genre Maker mvallevand 12 6,104 2012-01-21, 04:15 PM
Last Post: mvallevand

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode