Author Topic: Alt.binz Scripts - The Code!  (Read 34133 times)

Offline Hecks

  • Contributor
  • ***
  • Posts: 2011
  • naughty cop
Alt.binz Scripts - The Code!
« on: October 21, 2007, 10:17:41 PM »
Since version 0.26.1, Alt.binz includes an Execute Command feature that runs after PAR2 checking, repairing or unraring is complete (whichever is last in the cycle).  Usage as follows:

Quote from: Rdl
There is a default execute command under setup->NZB #2, but command can be specified separately for any collection.

Format for command is:
full_path_to_exe_bat_or_whatever "parameters"

Use $d for full download path without a trailing delimiter
Use $u for full unrar path without a trailing delimiter

Examples:

c:\util\MyCleanupRoutine.exe "-a $d"
c:\util\CleanupAfterUnrar.bat "$d $u"



Post any scripts you've written in this thread, with brief info about usage, command parameters, and so on.

:)

-Hecks
« Last Edit: November 05, 2009, 12:51:09 PM by davidq666 »

Offline Hecks

  • Contributor
  • ***
  • Posts: 2011
  • naughty cop
Logdownloads.bat
« Reply #1 on: October 21, 2007, 10:19:06 PM »
Here's a little sample batch script (using cmd.exe) to get us started:

Description:
Logs all new files in download and unrar directories with date/time stamps.

Usage:

Copy the code, open Notepad, paste and save the file in your Altbinz directory (or anywhere else) as  "logdownloads.bat" (*with* quotation marks).

Command:
c:\program files\altbinz\logdownloads.bat "$d $u"

Code: [Select]
@echo off

:set_logfile
set logfile=C:\dldlog.txt
if not exist %logfile% echo Alt.binz Download Log > %logfile%

:set_folders
set dldir=%1
set undir=%2

:check_folders
if exist %dldir% for %%f in (%dldir%\*.*) do (call :log_files "%%f")
if exist %undir% for %%f in (%undir%\*.*) do (call :log_files "%%f")
goto :eof

:log_files
find /I "%~nx1" "%logfile%" >nul
if %ERRORLEVEL%==0 goto :eof
for /f "tokens=*" %%t in ('time /t') do (set timet=%%t)
echo %DATE% %TIMET% %~dpnx1 >> %logfile%
goto :eof


-Hecks
« Last Edit: November 05, 2009, 07:54:31 PM by davidq666 »

Offline davidq666

  • Contributor
  • ***
  • Posts: 1302
  • Watashi Wa Ero Desu!
Join.bat
« Reply #2 on: April 16, 2009, 04:06:34 PM »
a small script made by cr4zyfr4g, that was posted in the request-forum:

Description:

Checks for split files joins them either into download or unrar-dir and deletes all split files afterwards

Usage:
Copy the code, open Notepad, paste and save the file in your Altbinz directory (or anywhere else) as  "join.bat" (*with* quotation marks).

Command:
path-to-bat\join.bat "$d" for joining in download-dir
path-to-bat\join.bat "$d" "$u" for joining in unrar-dir

Code: [Select]
@ECHO OFF

if exist "%1\*.001" (
TITLE joining
set d=%1
set u=%2
if "%2"=="" set u=%1
if not exist "%2" (
md %2
)
for /f %%a in ('dir /b %1\*.001') do (
call :SUB %%a
)
Echo joined!
pause
)

goto :eof

:sub
copy /b "%d%\%~n1.*" "%u%\_%~n1"
del "%d%\%~n1.*" > nul
goto :eof
« Last Edit: November 05, 2009, 07:54:06 PM by davidq666 »

Offline MrbLOB9000

  • Contributor
  • ***
  • Posts: 43
7zip.bat
« Reply #3 on: October 31, 2009, 05:08:11 AM »
figured out a script that will unzip split 7zip, can be found here

Description:

Uses the app 7zip to unzips 7zip files to the set unrar location.

Afterwards
  • nfo
  • jpg
  • png
  • wmv
  • avi
  • mpg
  • mpeg
  • mkv

are moved to unrar dir

and
  • par2
  • 7zip
  • sfv

are deleted.

If the download-folder is left empty it gets deleted as well.

Usage:
Copy the code, open Notepad, paste and save the file in your Altbinz directory (or anywhere else) as  "7zip.bat" (*with* quotation marks).

Command:
path-to-bat\7zip.bat "$d" "$u"

Code: [Select]
rem in nzb#2 put this for default execution command: C:\folder\7zip.bat "$d" "$u"
If exist %1\*.7z.001 GOTO Contains7z
If exist %1\*.7z GOTO Contains7z

GOTO notempty

:Contains7z
FOR %%F IN (%1\*.7z.001) DO "C:\Program Files\7-Zip\7z.exe" x -o%2 "%%F"
IF ERRORLEVEL 1 GOTO Failed

FOR %%F IN (%1\*.7z) DO "C:\Program Files\7-Zip\7z.exe" x -o%2 "%%F"
IF ERRORLEVEL 1 GOTO Failed

move %1\*.nfo %2
move %1\*.jpg %2
move %1\*.png %2
move %1\*.wmv %2
move %1\*.avi %2
move %1\*.mpg %2
move %1\*.mpeg %2
move %1\*.mkv %2

del %1\*.7z.*
del %1\*.7z
del %1\*.par2
del %1\*.sfv

rem @echo off
dir %1|find " 0 File(s)" > NUL
if errorlevel 1 goto notempty

dir %1| find " 2 Dir(s)" > NUL
if errorlevel 1 goto notempty

rd %1

:Failed
:notempty


by adding or changing lines like:

move %1\*.nfo %2
or
del %1\*.sfv

u can easily adapt it to delete or move the types of files you would like...

P.S: The option to move files is different from the option "move to unrar folder" in settings->unrar!

The settings-option will only work if an unraring has taken place beforehand.
The script-option will work every time there is a par2-set.
« Last Edit: November 05, 2009, 08:32:43 PM by davidq666 »

Offline davidq666

  • Contributor
  • ***
  • Posts: 1302
  • Watashi Wa Ero Desu!
simple-clean-up.bat
« Reply #4 on: November 23, 2009, 09:34:45 PM »
Description:

deletes nfos, jpgs, pngs, sfvs and srr files and deletes the download dir afterwards if empty

Usage:
Copy the code, open Notepad, paste and save the file in your Altbinz directory (or anywhere else) as  "simple-clean-up.bat" (*with* quotation marks).

Command:
path-to-bat\simple-clean-up.bat "$d"

Code: [Select]
del %1\*.nfo
del %1\*.jpg
del %1\*.png
del %1\*.sfv
del %1\*.srr
rd %1
« Last Edit: February 02, 2010, 03:43:53 PM by davidq666 »

Offline boredazfcuk

  • Contributor
  • ***
  • Posts: 4
log-rename-clean_up.bat
« Reply #5 on: April 27, 2010, 10:59:58 AM »
Here's mine:

Needs to have the download and unrar folders passed to it e.g. D:\Documents\RSS\TidyUp.bat "$d" "$u"

It logs all folders that it unrars to and creates a shortcut to the log on the desktop to let me know something has been downloaded. It then uses a freeware utility (Bulk Rename Command http://www.bulkrenameutility.co.uk/Download.php) to rename the downloaded file e.g. show1.s01e01.720p.x264.aac20.releasegroup.mkv becomes "Show 1 S01E01.mkv"
It then removes the download folder and quits.


Code: [Select]
set logfile=D:\Documents\RSS\dllog.txt
if not exist %logfile% echo Alt.Binz Download Log > %logfile%
date /t >> %logfile%
echo New file in %2 >> %logfile%
echo. >> %logfile%
copy /y "D:\Documents\RSS\RSS.lnk" %USERPROFILE%\Desktop

if (%2) == ("D:\Video\TV Shows\Show 1\Season 1") GOTO SHOW1
if (%2) == ("D:\Video\TV Shows\Show 2\Season 2") GOTO SHOW2
if (%2) == ("D:\Video\TV Shows\Show 2\Season 2") GOTO SHOW3
GOTO EXIT

:SHOW1
D:\Documents\RSS\brc64.exe /DIR:%2 /PATTERN:*.*.* /REMOVEWORDS:720 /REMOVEWORDS:264 /REMOVEWORDS:2HD /STRIPSYMBOLS /REMOVEWORDS:DD51 /REMOVEWORDS:AAC20 /STRIPCHARS /INSERT:"Show 1":1 /INSERT:" ":7 /INSERT:S:8 /INSERT:E:11 /TRIM /EXECUTE
GOTO END

:SHOW2
D:\Documents\RSS\brc64.exe /DIR:%2 /PATTERN:*.*.mkv /REMOVEWORDS:720 /REMOVEWORDS:264 /REMOVEWORDS:2HD /STRIPSYMBOLS /REMOVEWORDS:DD51 /REMOVEWORDS:AAC20 /STRIPCHARS /INSERT:"Show 2":1 /INSERT:" ":7 /INSERT:S:8 /INSERT:E:11 /TRIM /EXECUTE
GOTO END

:SHOW3
D:\Documents\RSS\brc64.exe /DIR:%2 /PATTERN:*.*.avi /REMOVEWORDS:720 /REMOVEWORDS:264 /REMOVEWORDS:2HD /STRIPSYMBOLS /REMOVEWORDS:DD51 /REMOVEWORDS:AAC20 /STRIPCHARS /INSERT:"Show 3":1 /INSERT:" ":7 /INSERT:S:8 /INSERT:E:11 /TRIM /EXECUTE
GOTO END

:END
rd /s /q %1

:EXIT

« Last Edit: April 27, 2010, 11:44:43 AM by boredazfcuk »

Offline simmc

  • Contributor
  • ***
  • Posts: 1
Move Movies to Movies Folder
« Reply #6 on: June 11, 2010, 07:42:55 PM »
i like my movies to move from the unrar dir to the movies dir. i do this using the avi's file size.
if any avi's file size > 650mg then move it to the movies dir.

Code: [Select]
for %%a in ("C:\Users\Me\Downloads\*.avi") do (if %%~za GTR 681574400 move "%%a" Movies)


Offline musictrivianut

  • Contributor
  • ***
  • Posts: 34
Re: Alt.binz Scripts - The Code!
« Reply #7 on: July 18, 2010, 01:27:55 AM »
Okay, so I finally have my batch file about 90% of where I want it to be, but until I learn how to read media stream information on the command line, it's going to have to do.

I like watching 720p television episodes through my PS3 on my 50" Kuro plasma.  However, most all of them are uploaded in an mkv container.  For the last couple of weeks, just since I got my connection back and upgraded to watching the 720p episodes over the regular ones, I have been downloading and converting them to m2ts format and renaming them manually.  The conversion allows me to serve them using PS3 Media Server without any transcoding and the renaming bit, well, that's just a quirk of mine.  I dislike the long file names with all of the extra info.

I got tired of doing it all the long way and one of the purposes of having a computer is to make life easier, isn't it?  So, I delved into writing batch files to automate everything.  I had done a little bit before, but nothing on the scale that I ended up using; this was definitely a learning experience.  What I came up with probably isn't the best way to do it, but it works for my setup.  I was having problems with altbinz passing the download directory and collection name, so I ended up just setting the directory in a variable, since that never changes, and writing a routine to read the name of the file, since the collection name doesn't always match the name of the file.

Currently, I think the only issue may be with the creation of the meta file used by tsMuxeR for the conversion.  I'm using a generic file, written each time for each different file downloaded.  It won't always work, since some files may be encoded using DTS and I don't really want it to take that and convert it to AC3, but as I mentioned before, I don't yet know how to read the encoding information from the command line to tailor the meta file, so it will have to do for now.

If anybody has any suggestions, I am always looking to improve my coding skills.  I tried to put enough remarks in the file to explain what each section is doing, but I'll answer questions, also.

Oh yeah, my thanks to boredazfcuk for pointing out that Bulk Rename Utility has a command line version.  I've been using the GUI for a long time and love it, but didn't know about BRC.

Update: Okay, so I found a pre-compiled command-line version of MediaInfo for Windows and have figured out how to read the information the I need out of it (well, most of it, anyhow).  So, I have updated my batch file.  Reading the encoding information comes in handy to determine the frame rate.  Not all of the files I am trying to convert have the same frame rate and, for some reason, leaving it blank and having tsMuxeR read it from the stream didn't always work either.  So, the batch file now determines the frame rate using MediaInfo and writes it to the meta file (as well as the audio encoding scheme, DTS or AC3).  I also discovered that not all of the video files have the video stream as track 1 and the audio as track 2; sometimes they are reversed.  That led to the other major change - if the first attempt fails, it swaps the track numbers in the meta file and running a second attempt at conversion.

I think that covers most everything that I updated.  I am incredibly satisfied with the file the way it works now.  I have tested it with a good dozen files with varying frame rates and mixed track numbers and it has yet to choke on one.  There is nothing else I can think to do to improve it, so I think I'm done for now.

And while I didn't get any comments or questions after posting it the first time, those are still welcome.

Update 2:  Turns out I left out a rather important line of code, the one that runs tsMuxeR the second time if the first attempt fails.  Should work now.

Final update (hopefully):  After much research, I finally figured out how to parse a text file and read the information passed from mediainfo.  The program now reads the frame rate and video and audio tracks from the file and sets variables for use in the meta file for muxing.  I've also discovered that the PS3 will not pass a DTS stream unless it is from an optical disc, so I also added routines to check for a DTS audio track, demux it, convert it to AC3 format and then mux the video and audio into a new file.  I've been using the new batch file for a couple of days now and it hasn't choked on any of the mkv files I've thrown at it, so I think it's done (finally).

Hope that someone else out there can make use of it, but I have to say, learning how to do all of this has really helped my batch writing skills (I've learned a lot that I did not know before).

Code: [Select]
@echo off
setlocal ENABLEEXTENSIONS

rem this batch file converts a downloaded file from an mkv container to m2ts
rem it uses mediainfo command line interface to read video and audio track numbers
rem tsmuxer to demux dts tracks and remux files to m2ts format and
rem eac3to to convert dts tracks to ac3 format

rem set the download directory and change to it

set dldir=C:\temp
cd %dldir%

rem if the file did not unrar correctly, the next command will quit the program

if not exist %dldir%\*.mkv goto :eof

rem the next set of commands finds the name of the file that was downloaded
rem (there should only be one mkv file in the directory)
rem Bulk Rename line that follows will remove spaces from the target filename

"C:\Program Files\brc_64\brc64.exe" /DIR:%dldir% /PATTERN:"*.mkv" /CHANGECASE:L /REPLACECI:" ":.  /TRIM /QUIET /EXECUTE

for /f "delims=" %%A in ('forfiles /m *.mkv /c "cmd /c echo @fname"') do set filename=%%A
set filename=%filename:"=%

rem set the remaining variables

set muxdir=C:\Program Files (x86)\tsMuxeR
set eacdir=C:\Program Files (x86)\eac3to
set metafile=%dldir%\%filename%.meta
set media=%dldir%\%filename%.mediainfo.txt
set newmedia=%dldir%\%filename%.media.new.txt

rem need to determine which track is video and which is audio, since they are not
rem always consistent.  if the settings are not correct, tsmuxer will fail

c:\mediainfo.cli\mediainfo --Inform %filename%.mkv > %media%

find /i "id " %media% > %newmedia%

rem mediainfo always writes the video track information first, so the first ID will
rem always be that one.  setting a counter will let us skip over the video lines to
rem find the audio track number.  not interested in anything after that.

set line=1

for /f "tokens=1,2 delims=:" %%G in (%newmedia%) do (
set /a line+=1
if "%%G"=="ID                               " (
   set videotrack=%%H
   goto :findaudio)
)

:findaudio

set videotrack=%videotrack: =%
set /a line+=1

for /f "tokens=1,2 delims=: skip=%line%" %%G in (%newmedia%) do (
set /a line+=1
if "%%G"=="ID                               " (
   set audiotrack=%%H
   goto :setframes)
)

:setframes

set audiotrack=%audiotrack: =%

for /f "tokens=1,2 delims=:" %%G in (%media%) do (
if "%%G"=="Frame rate                       " set frames=%%H
)

set frames=%frames:fps=%
set frames=%frames: =%

:checkdts

findstr /I dts %media%
if not errorlevel 1 (goto :dts) else (goto :writemeta)

:dts

rem write meta file demuxing dts track
echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --demux --vbv-len=500 > %metafile%
echo A_DTS, "%dldir%\%filename%.mkv", track=%audiotrack% >> %metafile%

rem demux audio
"%muxdir%\tsMuxeR.exe" "%metafile%" %dldir%

rem get name of dts file
for /f "delims=" %%A in ('forfiles /m *.dts /c "cmd /c echo @fname"') do set dtsfile=%%A
set dtsfile=%dtsfile:"=%

rem check for demuxing error
if not exist %dtsfile%.dts goto :failed
for /f %%A in ("%dldir%\%dtsfile%.dts") do set size=%%~zA
if %size%==0 goto :failed

rem convert dts to ac3
"%eacdir%\eac3to.exe" %dtsfile%.dts %dtsfile%.ac3 -640

rem write new meta file for m2ts container
echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbv-len=500 > %metafile%
echo V_MPEG4/ISO/AVC, "%dldir%\%filename%.mkv", insertSEI, contSPS, fps=%frames%, track=%videotrack% >> %metafile%
echo A_AC3, "%dldir%\%dtsfile%.ac3" >> %metafile%

goto :mux

:writemeta

echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbv-len=500 > %metafile%
echo V_MPEG4/ISO/AVC, %dldir%\%filename%.mkv, insertSEI, contSPS, fps=%frames%, track=%videotrack% >> %metafile%
echo A_AC3, %dldir%\%filename%.mkv, track=%audiotrack% >> %metafile%

:mux

"%muxdir%\tsMuxeR.exe" %metafile% %dldir%\%filename%.m2ts

rem if conversion was successful, delete downloaded file and clean up
rem otherwise, note the failure, clean up and quit

if not exist %filename%.m2ts goto :failed
for /f %%A IN ("%filename%.m2ts") do set size=%%~zA
if %size%==0 goto :failed

rem remove downloaded file, leaving converted file

del %dldir%\%filename%.mkv

goto :end

:failed

rem delete the failed conversion file and rename the downloaded file to note failure

del %dldir%\%filename%.m2ts
ren %dldir%\%filename%.mkv %filename%.conversion.failed.mkv

:end

rem rename new file to standard format that I prefer

"C:\Program Files\brc_64\brc64.exe" /DIR:%dldir% /PATTERN:"*.m2ts *.avi" /CHANGECASE:L /REPLACECI:s01e:1 /REPLACECI:_:. /REPLACECI:s02e:2 /REPLACECI:s03e:3 /REPLACECI:s04e:4 /REPLACECI:S05E:5 /REPLACECI:s06e:6 /REPLACECI:s07e:7 /REPLACECI:s08e:8 /REPLACECI:s09e:9 /REPLACECI:s10e:10 /REMOVEWORDS:".720p .dvdrip .hddvd .internal .repack .x264 .ws .pdtv .dsr .xvid .hdtv .dts .us .bluray .2010 -hv -runner aaf- -reptile -saints -sfm -2hd -fqm -sys -bajskorv -lol -bia -dimension -orenji -ctu -sitv -immerse -aaf -momentum -fov -ositv -gothic -cinefile" /TRIM /QUIET /EXECUTE

rem move the converted file to a new directory and clean up other files
rem if the conversion fails for some reason, this will still move the file into
rem the new directory, instead of deleting it

move %dldir%\*.m2ts %dldir%\done
move %dldir%\*.mkv %dldir%\done
move %dldir%\*.avi %dldir%\done
del %metafile%
del %media%
del %newmedia%
del %dtsfile%.dts
del %dtsfile%.ac3
del %dtsfile%*.txt
del *.idx
del %dldir%\*.nfo
del %dldir%\*.srr
del %dldir%\*.srs
del %dldir%\*.sfv
del %dldir%\*.nfo

endlocal
« Last Edit: August 22, 2010, 11:20:48 PM by musictrivianut »

Offline musictrivianut

  • Contributor
  • ***
  • Posts: 34
Re: Alt.binz Scripts - The Code!
« Reply #8 on: May 29, 2012, 10:24:19 PM »
Update on the code that I posted (above).

After running into multiple problems with files that folks uploaded (header compression, audio streams that went from 6 to 2 channels and back, audio streams in AAC format, etc), I decided to do some research into solving those and have resolved some other issues as well.  For some reason that I'm still trying to figure out, the command-line version of BRC will sometimes choke on a file and just quit with a runtime error.  Closing that dialog box will let the program continue to run, but if left unattended, you can get multiple batch files going and that's not really good.  So, I included a routine to make sure that only one batch window runs at a time.  I also sometimes ran into the program trying to process a file that altbinz was still trying to unrar, so now it checks for that and waits until that is finished.

This batch program can be set up to run after every download or you can wait until everything is done and then run it once.  You will obviously have to cater it to your system (making changes to any directories and downloading the programs that are needed), but it definitely works for me.

As always, comments welcome and if you have any question on why I did something the way I did, please ask.  I'll do my best to remember where I found it and point you to it.

Code: [Select]
@echo off
setlocal ENABLEEXTENSIONS

:: this batch file converts a downloaded file from an mkv container to m2ts
:: it uses mediainfo command line interface to read video and audio track numbers
:: tsmuxer to demux dts tracks and remux files to m2ts format
:: eac3to to convert dts tracks to ac3 format
:: besweet fixes ac3 streams that are mixed 2/6 channels

::check to see if batch program is already running

for /f "delims= " %%A in ('tasklist /V /FI "IMAGENAME eq cmd.exe" ^2^> NUL ^| find /I /C "C:\Windows\system32\cmd.exe"') do set windows=%%A
if %windows% == 2 goto :exit

:: set the download directory and change to it

set dldir=C:\temp
cd %dldir%

::set variables for program directories

set muxdir=C:\Program Files (x86)\tsMuxeR
set eacdir=C:\Program Files (x86)\eac3to
set mkvmerge=C:\Program Files (x86)\MKVtoolnix
set besweet=C:\Program Files (x86)\BeSweet
set brc=C:\Program Files\brc_64

:: if there are no mkv files, clean up and quit

if not exist %dldir%\*.mkv goto :end

:: Bulk Rename line that follows will remove spaces from all of the mkv files to be processed

"%brc%\brc64.exe" /DIR:%dldir% /PATTERN:"*.mkv" /CHANGECASE:L /REPLACECI:" ":.  /REPLACECI:_:. /TRIM /QUIET /EXECUTE

:start

:: the next command finds the name of the last mkv file alphabetically

for /f "delims=" %%A in ('forfiles /m *.mkv /c "cmd /c echo @fname"') do set filename=%%A
set filename=%filename:"=%

:: set remaining variables

set metafile=%dldir%\%filename%.meta
set media=%dldir%\%filename%.mediainfo.txt
set newmedia=%dldir%\%filename%.media.new.txt
set mkvinfo=%dldir%\%filename%.mkvinfo.txt
set audioformat=A_AC3

:dllcheck

:: check to see if altbinz is unraring a file
:: if it is, then the program waits because
:: if batch file tries to process the file being
:: uncompressed it will cause errors

Listdlls altbinz > %dldir%\dlls.txt

findstr /I unrar %dldir%\dlls.txt > nul
if not errorlevel 1 (goto :wait) else (goto :findvideo)

:wait

ping 127.0.0.1 -n 6 > nul
goto :dllcheck

:findvideo

:: need to determine which track is video and which is audio, since they are not
:: always consistent.  if the settings are not correct, tsmuxer will fail

c:\mediainfo.cli\mediainfo --Inform %filename%.mkv > %media%

find /i "id " %media% > %newmedia%

:: mediainfo always writes the video track information first, so the first ID will
:: always be that one.  setting a counter will let us skip over the video lines to
:: find the audio track number.  not interested in anything after that.

set line=1

for /f "tokens=1,2 delims=:" %%G in (%newmedia%) do (
set /a line+=1
if "%%G"=="ID                               " (
   set videotrack=%%H
   goto :findaudio)
)

:findaudio

set videotrack=%videotrack: =%
set /a line+=1

for /f "tokens=1,2 delims=: skip=%line%" %%G in (%newmedia%) do (
set /a line+=1
if "%%G"=="ID                               " (
   set audiotrack=%%H
   goto :audioformat)
)

:audioformat

set audiotrack=%audiotrack: =%

for /f "tokens=1,2 delims=: skip=%line%" %%G in (%newmedia%) do (
set /a line+=1
if "%%G"=="Codec ID                         " (
   set audioformat=%%H
   goto :setframes)
)

:setframes

set audioformat=%audioformat: =%

for /f "tokens=1,2 delims=:" %%G in (%media%) do (
if "%%G"=="Frame rate                       " set frames=%%H
)

set frames=%frames:fps=%
set frames=%frames: =%

:: check for header compression
:: if header is compressed, tsmuxer will fail

"%mkvmerge%\mkvinfo.exe" %filename%.mkv > %mkvinfo%
findstr /i "header removal" %mkvinfo%
if not errorlevel 1 (goto :fixstream) else (goto :checkdts)

:fixstream

:: this simply tries to remux the file with no header compression

"%mkvmerge%\mkvmerge.exe" -o "%dldir%\%filename%.fixed.mkv" --default-track 0:yes --forced-track 0:no --compression 0:none --default-track 1:yes --forced-track 1:no --compression 1:none -S -T --no-global-tags --no-chapters "%dldir%\%filename%.mkv"

:: if remuxing with no compression fails, then the audio stream is probably
:: a mixture of 2 and 6 channels, so fix that

if not errorlevel 0 (goto :fixac3)

del %dldir%\%filename%.mkv
set filename=%filename%.fixed

:: AC3 is preferable to DTS, so convert that

:checkdts

findstr /I dts %media%
if not errorlevel 1 (goto :dts) else (goto :writemeta)

:dts

:: write meta file demuxing dts track

echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --demux --vbv-len=500 > %metafile%
echo A_DTS, "%dldir%\%filename%.mkv", track=%audiotrack% >> %metafile%

:: demux audio

"%muxdir%\tsMuxeR.exe" "%metafile%" %dldir%

:: get name of dts file

for /f "delims=" %%A in ('forfiles /m *.dts /c "cmd /c echo @fname"') do set dtsfile=%%A
set dtsfile=%dtsfile:"=%

:: check for demuxing error

if not exist %dtsfile%.dts goto :failed
for /f %%A in ("%dldir%\%dtsfile%.dts") do set size=%%~zA
if %size%==0 goto :failed

:: convert dts to ac3

"%eacdir%\eac3to.exe" %dtsfile%.dts %dtsfile%.ac3 -640

:: write new meta file for m2ts container

echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbv-len=500 > %metafile%
echo V_MPEG4/ISO/AVC, "%dldir%\%filename%.mkv", insertSEI, contSPS, fps=%frames%, track=%videotrack% >> %metafile%
echo A_AC3, "%dldir%\%dtsfile%.ac3" >> %metafile%

goto :mux

:writemeta

echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbv-len=500 > %metafile%
echo V_MPEG4/ISO/AVC, %dldir%\%filename%.mkv, insertSEI, contSPS, fps=%frames%, track=%videotrack% >> %metafile%
echo %audioformat%, %dldir%\%filename%.mkv, track=%audiotrack% >> %metafile%

:mux

"%muxdir%\tsMuxeR.exe" %metafile% %dldir%\%filename%.m2ts

:: if conversion was successful, delete downloaded file and clean up
:: otherwise, note the failure, clean up and quit

if not errorlevel 0 goto :fixac3

if not exist %filename%.m2ts goto :failed
for /f %%A IN ("%filename%.m2ts") do set size=%%~zA
if %size%==0 goto :failed

:: remove downloaded file, leaving converted file

del %dldir%\%filename%.mkv

goto :end

:fixac3

:: sometimes the ac3 file will have both 2 channels and 5.1 channels
:: this routine will correct that and leave a 2 channel ac3 file
:: and will then remux both video and audio into an m2ts container

if %audiotrack%=="2" (
"%mkvmerge%\mkvextract.exe" --ui-language en tracks "%dldir%\%filename%.mkv" 0:"%dldir%\%filename%.video.h264" 1:"%dldir%\%filename%.audio.ac3"
)
else (
"%mkvmerge%\mkvextract.exe" --ui-language en tracks "%dldir%\%filename%.mkv" 0:"%dldir%\%filename%.audio.ac3" 1:"%dldir%\%filename%.video.h264"
)
"%besweet%\BeSweet.exe" -core( -input "%dldir%\%filename%.audio.ac3" -output "%dldir%\%filename%.audio.fixed.ac3" -logfilea "%besweet%\BeSweet.log" ) -azid( -s stereo -g 1 ) -ac3enc( -b 384 ) -profile( ~~~~~ Default Profile ~~~~~ )

echo MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbv-len=500 > %metafile%
echo V_MPEG4/ISO/AVC, %dldir%\%filename%.video.h264, insertSEI, contSPS, fps=%frames%, track=%videotrack% >> %metafile%
echo A_AC3, %dldir%\%filename%.audio.fixed.ac3, track=%audiotrack% >> %metafile%

"%muxdir%\tsMuxeR.exe" %metafile% %dldir%\%filename%.m2ts

if not exist %filename%.m2ts goto :failed
for /f %%A IN ("%filename%.m2ts") do set size=%%~zA
if %size%==0 (goto :failed) else (
del %dldir%\%filename%.mkv
goto :end
)

:failed

:: delete the failed conversion file and rename the downloaded file to note failure

del %dldir%\%filename%.m2ts
ren %dldir%\%filename%.mkv %filename%.conversion.failed.mkv

:end

:: rename new file to standard format that I prefer

"C:\Program Files\brc_64\brc64.exe" /DIR:%dldir% /PATTERN:"*.m2ts *.avi *.mp4" /CHANGECASE:L /REPLACECI:s01e:1 /REPLACECI:_:. /REPLACECI:s02e:2 /REPLACECI:s03e:3 /REPLACECI:s04e:4 /REPLACECI:S05E:5 /REPLACECI:s06e:6 /REPLACECI:s07e:7 /REPLACECI:s08e:8 /REPLACECI:s09e:9 /REPLACECI:s10e:10 /REPLACECI:s11e:11 /REPLACECI:s12e:12 /REPLACECI:s13e:13 /REPLACECI:s15e:15 /REPLACECI:s16e:16 /REPLACECI:s17e:17 /REPLACECI:s18e:18 /REMOVEWORDS:".720p .dvdrip .hddvd .internal .hr .repack .2009 .2010 .2011 .divx .x264 .hdrip .h.264 .web-dl .ws .real .pdtv .dsr .xvid .eng .saints .hdtv .webrip .dvd5 .dvd9 .dd5.1 .dts5.1 .dts .sub .us .fixed .bluray .track1 .2010 _track1 infinite- tpz- aaf- avchd- halcyon- runner- -etp -lmao -wide -ffndvd -t00ng0d -dvdrip -shortbrehd -omicron -gnarly -phase -nmbstv -nodlabs -diverge -river -paramount -transience -tns -haggis -w4f -xvid -nbs -premier -hoodbag -dah -qcf -dirty -hv -crimson -dbo -angelic -blind -ftp -ingot -spunx -ebp -runner -xii -shotv -reward -sinners -rpk -unit3d -reptile -dhd -saints -fty -macro -sfm -2hd -fqm -sys -bajskorv -lol -tla -compulsion -p0w4 -yestv -avs -bia -dimension -orenji -ctu -sitv -immerse -aaf -sprinter -momentum -fov -ositv -gothic -ctrlhd -cinefile" /TRIM /QUIET /EXECUTE

:: move the converted file to a new directory and clean up other files
:: if the conversion fails for some reason, this will still move the file into
:: the new directory, instead of deleting it

move %dldir%\*.m2ts %dldir%\done
move %dldir%\*.failed.mkv %dldir%\done
move %dldir%\*.avi %dldir%\done
move %dldir%\*.mp4 %dldir%\done
del %metafile%
del %media%
del %newmedia%
del %mkvinfo%
del *.dts
del *.ac3
del *.h264
del %dtsfile%*.txt
del %dldir%\dlls.txt
del %dldir%\*.idx
del %dldir%\*.nfo
del %dldir%\*.srr
del %dldir%\*.srs
del %dldir%\*.sfv

if exist %dldir%\*.mkv goto :start

:exit

endlocal

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #9 on: October 26, 2015, 11:18:27 PM »
Guys,

I need some help here. Some of the filenames are sometimes obfuscated and after unrar, I would like to just rename it with the collection name, which is usually the filename un-obfuscated  8)

It must be quite easy but variables for filename and collection  name are needed!  :( what are they?
and then just issue some command like rename %filename %collection_name or something?

Sorry I feel like a noob here, any hint would be cool thanks

« Last Edit: October 26, 2015, 11:20:26 PM by domdom »

Offline Rdl

  • Administrator
  • *****
  • Posts: 3918
Re: Alt.binz Scripts - The Code!
« Reply #10 on: October 26, 2015, 11:49:00 PM »
I'll just add here that there is another parameter there besides documented 2:
  • $d - collection download path
  • $u - collection unrar path
  • $col - collection name

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #11 on: October 26, 2015, 11:52:44 PM »
Great  8)
and filename would be %filename% right? if I read previous post correctly  ;D

and BTW one more question: is it possible to test script without downloading anything?  ???
« Last Edit: October 26, 2015, 11:56:38 PM by domdom »

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #12 on: October 27, 2015, 12:09:36 AM »
So I tested this
rename %2\%filename%.mkv %2\%3.mkv

within "C:\Install\Altbinz\cleanup.bat" "$d" "$u" "$col"

not working :(

Offline Hecks

  • Contributor
  • ***
  • Posts: 2011
  • naughty cop
Re: Alt.binz Scripts - The Code!
« Reply #13 on: October 27, 2015, 01:18:13 AM »
So I tested this
rename %2\%filename%.mkv %2\%3.mkv

within "C:\Install\Altbinz\cleanup.bat" "$d" "$u" "$col"

not working :(

Post your whole script, and define "not working".

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #14 on: October 27, 2015, 08:49:43 AM »
Here is the script

del %2\*.nfo
del %2\*.jpg
del %2\*.ssr
del %2\*.nzb
del %2\*.srs
del %2\*.php
del %2\*.url
del %2\*.rar
rename %2\%filename%.mkv %2\%3.mkv
exit

and I am trying to rename the downloaded filename to the collection name, which is useful when the filename is obfuscated
the del part works but what doesnt work is the obfuscated filename doesnt get renamed  :-[