Idea on how to handle 'Proper' releases

Come up with a useful post-processing script? Share it here!
Post Reply
feerlessleadr
Jr. Member
Jr. Member
Posts: 67
Joined: April 30th, 2009, 12:09 pm

Idea on how to handle 'Proper' releases

Post by feerlessleadr »

Hi all, i had an idea today while sitting in work on what i think is a pretty common problem I have.

Sometimes when I am downloading a show, lets call that show X, a group will release the proper a few hours later, causing me to have 2 versions of the same episode.  Now normally I would just add a filter to my rss feed to reject the proper, but most of the times I would like the proper instead of the original download. 

Would it be possible to write a script to detect the word 'Proper' in the file name of a download and if found, will search the download tv show directory for the same episode number and delete the previously downloaded file?

So for example, lets say I downloaded 'Show - 1x01' and it is sitting in '\Show\Season 1\'.  An hour later a proper for 'Show - 1x01' shows up and is downloaded.  During the post processing, i would like to have a script that will search the filename of the current downloaded file, and if the word 'Proper' is in it, it will then search the '\Show\Season 1\' directory for another 1x01 episode.  If a match is found, the older file is then deleted and replaced by the newly downloaded file.

Hopefully that made some sort of sense.  I have been searching on the internet, but I can't really find anything that would accomplish this, and since I don't know how to write my own batch files, I am hoping someone here might know.

Thanks

::EDIT:: Another possible way to handle this problem would be to have a script that would find duplicate files and delete the file that is older.
Last edited by feerlessleadr on May 18th, 2010, 2:29 pm, edited 1 time in total.
markus101
Release Testers
Release Testers
Posts: 406
Joined: August 13th, 2008, 2:51 am

Re: Idea on how to handle 'Proper' releases

Post by markus101 »

I believe SickBeard will do this for you. I know SABSync does exactly this. Assuming you have it configured to download Propers it will delete the existing file on disk and download the new proper in its place.

SABSync is designed to replace SABnzbd's built in RSS feeds, as is SickBeard, though they accomplish this is different ways. When 0.6 comes out you could have the Pre-Queue script do pretty much the same, though you would have to have some structure to the storage of the files to avoid deleting something totally different.

Code: Select all

http://wiki.sabnzbd.org/user-pre-queue-script
-Markus
Co-developer of NzbDrone (.Net NNTP PVR) - http://www.nzbdrone.com
feerlessleadr
Jr. Member
Jr. Member
Posts: 67
Joined: April 30th, 2009, 12:09 pm

Re: Idea on how to handle 'Proper' releases

Post by feerlessleadr »

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.
feerlessleadr
Jr. Member
Jr. Member
Posts: 67
Joined: April 30th, 2009, 12:09 pm

Re: Idea on how to handle 'Proper' releases

Post by feerlessleadr »

Final Update:

Here is my final script that I use in conjunction with TV Renamer (to rename my episodes), Media Companion (to scrape the applicable nfo, tbn and fanart for each show/episode) and XBMC (obviously to watch my tv.

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.
            )
        )
    )
)
"C:\Program Files (x86)\TVRename\TVRename.exe" /doall /hide /quit
"C:\Users\Kevin\Other Stuff\XBMC\Media Companion\mc_com.exe" -e
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
This script will first delete any unnecessary files left over from the download process, it will then check to see if there are 2 duplicate episodes in the download directory.  If a duplicate is found, it will delete the older of the 2 files.  It will then call TV Renamer which will lookup the episode number from the TVDB and will rename the episode accordingly.  Finally, it will call Media Companion to scrape the episode's nfo & tbn from the TVDB. 

As mentioned in my previous post, you will need to have tv sorting enabled, however you can't have the episode name added to the file since for some reason the script won't recognize duplicates if the newer file has any text after '1x01'

Hope someone finds this as helpful as I do.
Post Reply