Bad downloaded file/folder names

Come up with a useful post-processing script? Share it here!
Post Reply
staffdd
Newbie
Newbie
Posts: 3
Joined: October 26th, 2015, 6:19 am

Bad downloaded file/folder names

Post by staffdd »

Hi and a pre-thanks for reading. I need some help with my windows post processing script. So far everything works with sonarr/sabnzbd with my post processing script except for a few issues when trying to run handbrake. Most of the time handbrake runs after the download completes just fine. I have noticed that sometimes the file downloaded has an additional level of folders in it, or the .mkv file is for some reason not named the same as the .nzb. This is hell for my basic scripting knowledge to deal with.

This causes my script to bomb out when it tries to convert it in handbrake; it cant find the .mkv file! I know i'm not the only one with this problem, how does everyone else deal with the different named files or the extra folder in the download?

My basic script with a few echos/garbage left out.

Code: Select all

set HandBrakeCLI="C:\Program Files\Handbrake\HandBrakeCLI.exe"

cd /d %1

if exist %3.m4v (
	Move /y %3.m4v "e:\downloads\ready for plex\tv\"
)

if exist %3.mkv (
	%HandBrakeCLI% --input %3.mkv --output %3.mp4 --preset "High Profile"
)

if exist %3.mp4 (
	Move /y %3.mp4 "e:\downloads\ready for plex\tv\"
)

ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

Re: Bad downloaded file/folder names

Post by ALbino »

I dealt with the subdirectory problem in a really ugly way. I just moved ALL of the files to the root directory and then processed the MKV file. Here's my code:

Code: Select all

rem <-- Moving All Files Out of Subdirectories -->
rem <-- Tried flat_unpack in SABnzbd, but that didn't work -->

set MoveToFolder="%~dp2"

for /F "delims=" %%a in ('dir /b /s *.*') do move /Y "%%a" %MoveToFolder% & echo. & echo. & echo Moved %%a to %MoveToFolder% & echo. & echo.
Then I just rename the MKV:

Code: Select all

if exist *.mkv (
	for /F "delims=" %%a in ('dir /b /a-d *.mkv') do set FoundVideo="%%~fa"
        set VideoType=mkv
)

rem <-- Rename file -->
ren %FoundVideo% %3.%VideoType%

set InputVideo="%FoundVideo%"

rem <-- Process... -->
If anybody knows a better way while to deal with any of this using the limitations of Batch then I'd love to hear about it.
staffdd
Newbie
Newbie
Posts: 3
Joined: October 26th, 2015, 6:19 am

Re: Bad downloaded file/folder names

Post by staffdd »

So far I have kinda butchered it since I have no idea what I'm doing. My goal is for the batch file to find the mkv no matter what its named or how far into subfolders it is. I also want it to move mp4 and m4v into the finished folder if they are there. This is what I have come up with so far, but am still testing it. This is for Sonarr/sabnzbd. So far it looks like it works, except handbrake is bombing out when it inputs a file name with a space in it. It cuts the file name input at the space. I'm sure I need quotes in there somewhere...

Code: Select all

set HandBrakeCLI="C:\Program Files\Handbrake\HandBrakeCLI.exe"

cd /d %1

set dir=
for /f %%i in ('dir *. /s /b') do set dir=%dir% %%i

cd %dir%

if exist *.m4v (
   Move /y *.m4v "e:\downloads\ready for plex\tv\"
)

for /r %%x in (*.mkv) do set filename="%%x"

%HandBrakeCLI% --input %filename% --output %3.mp4 --preset "High Profile"

if exist *.mp4 (
   Move /y *.mp4 "e:\downloads\ready for plex\tv\"
)
Last edited by staffdd on October 27th, 2015, 6:55 am, edited 2 times in total.
ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

Re: Bad downloaded file/folder names

Post by ALbino »

You can fix the problem with Handbrake and the space by putting quotes around your variable/path, like you did for your HandBrakeCLI variable, or your move path.
staffdd
Newbie
Newbie
Posts: 3
Joined: October 26th, 2015, 6:19 am

Re: Bad downloaded file/folder names

Post by staffdd »

Looks like its complete! It will move to the Sabnzbd download folder, move up a subfolder if it exists for those pesky double folder downloads. Input the .mkv file name that is actually downloaded, not what sab/sonarr thinks it should be. Runs handbrake, and moves all .m4v, .mp4 files to Sonarr watch folder for input into plex.

Code: Select all

set HandBrakeCLI="C:\Program Files\Handbrake\HandBrakeCLI.exe"

cd /d %1

if exist *. (
	for /d %%f in (*) do cd "%%f"
)

if exist *.m4v (
   Move /y *.m4v "e:\downloads\ready for plex\tv\"
)

for /r %%x in (*.mkv) do set filename="%%x"

%HandBrakeCLI% --input %filename% --output %3.mp4 --preset "High Profile"

if exist *.mp4 (
   Move /y *.mp4 "e:\downloads\ready for plex\tv\"
)

cd\downloads\incomplete\sonarr

rd %1 /s /q
Post Reply