just wanted to give an update to my idea.
I posted a similar question on the computing.net message board and I got a response. Basically, I asked if someone could write up a script that would scan a directory for 2 duplicate files by matching the filenames up to a certain point. so for example the original file would be 'Show Name - 1x01 - Episode Name.mkv' and the duplicate file (usually the proper or repack) would be named 'Show Name - 1x01.mkv) (i currently use TV Rename to rename my tv episodes and it won't rename the file if there is a duplicate, which when a proper/repack is downloaded there is of course a duplicate).
Here is the script that I was given:
Code: Select all
:: Delete.Duplicate.Video.Files.bat
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
[b]SET file_path=%~1[/b]
FOR /F "delims=" %%a IN ('DIR /B /S /O:N "%file_path%\*.mkv" "%file_path%\*.avi"') DO (
CALL :get_file_info "%%a"
SET old_file=!new_file!
SET old_file_date=!new_file_date!
SET new_file=!file_name!
SET new_file_date=!file_date!
FOR /F %%b IN ('@ECHO "!old_file!"^|FIND /C "!new_file!"') DO (
IF "%%b" EQU "1" (
IF !old_file_date! GTR !new_file_date! (
ECHO older: !new_file_date! !new_file!
ECHO newer: !old_file_date! !old_file!
DEL "%file_path%\!old_file!.*"
ECHO.
)
IF !new_file_date! GTR !old_file_date! (
ECHO older: !old_file_date! !old_file!
ECHO newer: !new_file_date! !new_file!
DEL "%file_path%\!new_file!.*"
ECHO.
)
IF !new_file_date! EQU !old_file_date! (
ECHO same: !old_file_date! !old_file!
ECHO same: !new_file_date! !new_file!
ECHO Same timestamps. No files deleted...
ECHO.
)
)
)
)
EXIT /B
:get_file_info
SET file_date=%~t1
FOR /F "tokens=1-4 delims=: " %%c IN ("%file_date%") DO (
SET hours=0%%d
SET hours=!hours:00=!
SET hours=!hours:~-2!
IF %%d LSS 12 (
IF "%%f" EQU "PM" (
SET /A hours=!hours!+12
)
)
SET file_date=%%c !hours!:%%e
)
SET file_name=%~n1
GOTO :EOF
Everything is working well save for 2 problems. My first problem is that during the testing of this script on the my 0 byte copy of my TV show directory, i noticed that if the newer file (the proper/repack) had any text whatsoever after the season and episode number, the script wouldn't pick up the episode as a duplicate. This normally wouldn't be a problem for me since I am using NZBs.org and since no episode title is passed to sab, it will ususally just leave the episode name blank, however since RC1, sab has been adding the group name at the end of the filename (which I can only assume sab thinks is the episode name). I have already asked for help on that issue however located in this thread
http://forums.sabnzbd.org/index.php?topic=4492.0
My second issue is that I am having a lot of trouble combining this script with 3 other tv show post processing scripts.
Here is my current tv show post processing script that works with no problems (this currently uses 3 separate scripts):
Code: Select all
@echo off
setlocal
set fcount=0
set nzbcount=0
set sfvcount=0
set par2count=0
set txtcount=0
set gifcount=0
set urlcount=0
set srrcount=0
echo.
echo [Cleanup] Cleaning up download directory: %1
echo [Cleanup] Deleting .nzb files
for /f %%V in ('dir %1\*.nzb /b /s ^2^>NUL ^| find /v /c ""') do set/a nzbcount = %%V
if %nzbcount% GTR 0 del /s /q %1\*.nzb > NUL 2>NUL
echo [Cleanup] Deleting .sfv files
for /f %%V in ('dir %1\*.sfv /b /s ^2^>NUL ^| find /v /c ""') do set/a sfvcount = %%V
if %sfvcount% GTR 0 del /s /q %1\*.sfv > NUL 2>NUL
echo [Cleanup] Deleting .par2 files
for /f %%V in ('dir %1\*.par2 /b /s ^2^>NUL ^| find /v /c ""') do set/a par2count = %%V
if %par2count% GTR 0 del /s /q %1\*.par2 > NUL 2>NUL
echo [Cleanup] Deleting .txt files
for /f %%V in ('dir %1\*.txt /b /s ^2^>NUL ^| find /v /c ""') do set/a txtcount = %%V
if %txtcount% GTR 0 del /s /q %1\*.txt > NUL 2>NUL
echo [Cleanup] Deleting .gif files
for /f %%V in ('dir %1\*.gif /b /s ^2^>NUL ^| find /v /c ""') do set/a gifcount = %%V
if %gifcount% GTR 0 del /s /q %1\*.gif > NUL 2>NUL
echo [Cleanup] Deleting .url files
for /f %%V in ('dir %1\*.url /b /s ^2^>NUL ^| find /v /c ""') do set/a urlcount = %%V
if %urlcount% GTR 0 del /s /q %1\*.url > NUL 2>NUL
echo [Cleanup] Deleting .srr files
for /f %%V in ('dir %1\*.srr /b /s ^2^>NUL ^| find /v /c ""') do set/a srrcount = %%V
if %srrcount% GTR 0 del /s /q %1\*.srr > NUL 2>NUL
set/a fcount = %nzbcount% + %sfvcount% + %par2count% + %txtcount% + %gifcount% + %urlcount% + %srrcount%
echo [Cleanup] Deleted %fcount% files (%nzbcount% nzb, %sfvcount% sfv, %par2count% par2, %txtcount% txt,
%gifcount% gif, %urlcount% url, %srrcount% srr)
echo.
CALL "C:\Users\Kevin\Other Stuff\Usenet\Scripts\TV Rename.bat"
CALL "C:\Users\Kevin\Other Stuff\Usenet\Scripts\MC Scrape TV Shows.bat"
If i try to call the proper/repack batch file using the call command (similar to how I am currently calling the last 2 batch files), the working directory parameters get all messed up and the proper/repack script doesn't work (it scans my whole hard drive instead of just the working directory for duplicates). If i try to just insert the proper/repack code into the current batch file before I call the last 2 batch files, the post processing stops when I hit the end of the proper/repack code (highlighted in bold below).
Code: Select all
@echo off
setlocal
set fcount=0
set nzbcount=0
set sfvcount=0
set par2count=0
set txtcount=0
set gifcount=0
set urlcount=0
set srrcount=0
echo.
echo [Cleanup] Cleaning up download directory: %1
echo [Cleanup] Deleting .nzb files
for /f %%V in ('dir %1\*.nzb /b /s ^2^>NUL ^| find /v /c ""') do set/a nzbcount = %%V
if %nzbcount% GTR 0 del /s /q %1\*.nzb > NUL 2>NUL
echo [Cleanup] Deleting .sfv files
for /f %%V in ('dir %1\*.sfv /b /s ^2^>NUL ^| find /v /c ""') do set/a sfvcount = %%V
if %sfvcount% GTR 0 del /s /q %1\*.sfv > NUL 2>NUL
echo [Cleanup] Deleting .par2 files
for /f %%V in ('dir %1\*.par2 /b /s ^2^>NUL ^| find /v /c ""') do set/a par2count = %%V
if %par2count% GTR 0 del /s /q %1\*.par2 > NUL 2>NUL
echo [Cleanup] Deleting .txt files
for /f %%V in ('dir %1\*.txt /b /s ^2^>NUL ^| find /v /c ""') do set/a txtcount = %%V
if %txtcount% GTR 0 del /s /q %1\*.txt > NUL 2>NUL
echo [Cleanup] Deleting .gif files
for /f %%V in ('dir %1\*.gif /b /s ^2^>NUL ^| find /v /c ""') do set/a gifcount = %%V
if %gifcount% GTR 0 del /s /q %1\*.gif > NUL 2>NUL
echo [Cleanup] Deleting .url files
for /f %%V in ('dir %1\*.url /b /s ^2^>NUL ^| find /v /c ""') do set/a urlcount = %%V
if %urlcount% GTR 0 del /s /q %1\*.url > NUL 2>NUL
echo [Cleanup] Deleting .srr files
for /f %%V in ('dir %1\*.srr /b /s ^2^>NUL ^| find /v /c ""') do set/a srrcount = %%V
if %srrcount% GTR 0 del /s /q %1\*.srr > NUL 2>NUL
set/a fcount = %nzbcount% + %sfvcount% + %par2count% + %txtcount% + %gifcount% + %urlcount% + %srrcount%
echo [Cleanup] Deleted %fcount% files (%nzbcount% nzb, %sfvcount% sfv, %par2count% par2, %txtcount% txt,
%gifcount% gif, %urlcount% url, %srrcount% srr)
echo.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET file_path=%~1
FOR /F "delims=" %%a IN ('DIR /B /S /O:N "%file_path%\*.mkv" "%file_path%\*.avi"') DO (
CALL :get_file_info "%%a"
SET old_file=!new_file!
SET old_file_date=!new_file_date!
SET new_file=!file_name!
SET new_file_date=!file_date!
FOR /F %%b IN ('@ECHO "!old_file!"^|FIND /C "!new_file!"') DO (
IF "%%b" EQU "1" (
IF !old_file_date! GTR !new_file_date! (
ECHO older: !new_file_date! !new_file!
ECHO newer: !old_file_date! !old_file!
DEL "%file_path%\!old_file!.*"
ECHO.
)
IF !new_file_date! GTR !old_file_date! (
ECHO older: !old_file_date! !old_file!
ECHO newer: !new_file_date! !new_file!
DEL "%file_path%\!new_file!.*"
ECHO.
)
IF !new_file_date! EQU !old_file_date! (
ECHO same: !old_file_date! !old_file!
ECHO same: !new_file_date! !new_file!
ECHO Same timestamps. No files deleted...
ECHO.
)
)
)
)
EXIT /B
:get_file_info
SET file_date=%~t1
FOR /F "tokens=1-4 delims=: " %%c IN ("%file_date%") DO (
SET hours=0%%d
SET hours=!hours:00=!
SET hours=!hours:~-2!
IF %%d LSS 12 (
IF "%%f" EQU "PM" (
SET /A hours=!hours!+12
)
)
SET file_date=%%c !hours!:%%e
)
[b]SET file_name=%~n1
GOTO :EOF[/b]
CALL "C:\Users\Kevin\Other Stuff\Usenet\Scripts\TV Rename.bat"
CALL "C:\Users\Kevin\Other Stuff\Usenet\Scripts\MC Scrape TV Shows.bat"
I am sure there is an easy way to fix this, I just don't know what that way is :-) Based on my limited testing, this script should work well for identifying and deleting older episodes in place of propers/repacks once i can get the kinks worked out.
BTW - I just want to stress that I take no credit for this script as it was written completely by orangeboy on computing.net.