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

Offline Rdl

  • Administrator
  • *****
  • Posts: 3935
Re: Alt.binz Scripts - The Code!
« Reply #15 on: October 27, 2015, 12:32:19 PM »
Few things are wrong here:

- use code tags for code :)
- %filename%, what is that? I doubt that will automagically fill with file you want, you have to search for files in specified folder
- RENAME or REN can't take destination path as second parameter, only target filename

Here's quick and dirty fix for your code:
Code: [Select]
DEL "%~f2\*.nfo"
DEL "%~f2\*.jpg"
DEL "%~f2\*.ssr"
DEL "%~f2\*.nzb"
DEL "%~f2\*.srs"
DEL "%~f2\*.php"
DEL "%~f2\*.url"
DEL "%~f2\*.rar"
FOR %%f IN ("%~f2\*.mkv") DO REN "%%f" "%~3.mkv"
FOR %%f IN ("%~f2\*.mp4") DO REN "%%f" "%~3.mp4"

So, little explanation:
- %~f2 is full expanded path of %2 without "" so we included "" ourselves
- %~3 is eqv. to %3 but without ""
- this whole with "" and withouth "" gymnastics is needed for paths that include " " (space)
- %%f is variable used in batch files (eqv. to %f from command line)
- FOR loop is there to search for mkv files in ("%~f2\*.mkv") and put them in %%f variable (it's full filepath without "") and then execute REN "%%f" "%~3.mkv"
« Last Edit: October 27, 2015, 12:34:46 PM by Rdl »

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #16 on: October 27, 2015, 02:20:26 PM »
Very nice, thanks a lot  :) :) :). This is really useful I will test tonight  8)
BTW, where do you get this syntax? what kind of language is it?

Offline Rdl

  • Administrator
  • *****
  • Posts: 3935
Re: Alt.binz Scripts - The Code!
« Reply #17 on: October 27, 2015, 03:11:34 PM »
https://technet.microsoft.com/en-us/library/bb490890.aspx

Standard command line tools from Win XP and up.

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #18 on: October 27, 2015, 07:46:20 PM »
OK some feedback here.

The script seems fine but renaming occured but not on the right files  :P :P :-[
I dont know exactly how the "downloaded file" was selected (did a test on a small video file), but it picked the wrong one and renamed it with the "expected" collection name.

We are almmost there, the script should just pick the correct file(s) downloaded during the current session
FYI I always have some remaining files in the target directory (%3) with the correct filenames (in clear or deobfuscated) > script should not apply to them (it may be difficult to select just the files downloaded during most recent session)

Offline Hecks

  • Contributor
  • ***
  • Posts: 2011
  • naughty cop
Re: Alt.binz Scripts - The Code!
« Reply #19 on: October 27, 2015, 08:18:04 PM »
OK some feedback here.

The script seems fine but renaming occured but not on the right files  :P :P :-[
I dont know exactly how the "downloaded file" was selected (did a test on a small video file), but it picked the wrong one and renamed it with the "expected" collection name.

We are almmost there, the script should just pick the correct file(s) downloaded during the current session
FYI I always have some remaining files in the target directory (%3) with the correct filenames (in clear or deobfuscated) > script should not apply to them (it may be difficult to select just the files downloaded during most recent session)

Again, more info needed from you about what the "wrong" file was. What exactly are you doing, what do you expect to happen, what does actually happen? For instance, are you downloading to individual folders per NZB, or just all in one base folder?

And here's more info about how variable expansion works in batch files:

http://cplusplus.bordoon.com/cmd_exe_variables.html

So %~nI will convert a full file path to the filename without extension only. You can check that conditionally if needed (see the example scripts in this thread). Use the echo command liberally to report what the script is doing.
« Last Edit: October 27, 2015, 08:23:15 PM by Hecks »

Offline Rdl

  • Administrator
  • *****
  • Posts: 3935
Re: Alt.binz Scripts - The Code!
« Reply #20 on: October 27, 2015, 08:57:58 PM »
OK some feedback here.

The script seems fine but renaming occured but not on the right files  :P :P :-[
I dont know exactly how the "downloaded file" was selected (did a test on a small video file), but it picked the wrong one and renamed it with the "expected" collection name.

We are almmost there, the script should just pick the correct file(s) downloaded during the current session
FYI I always have some remaining files in the target directory (%3) with the correct filenames (in clear or deobfuscated) > script should not apply to them (it may be difficult to select just the files downloaded during most recent session)
For this script there are no right or wrong file. Every mkv and mp4 file gets renamed.
Typical posted release on usenet has multiple par2 sets. Usually subs gets downloaded first and then the rest. At that moment script triggers and deletes rar file of the main par2 set. You should also think about that.
%3 is not target directory, it's collection name. How should script know what is in clear or deobfuscated and what is obfuscated?

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #21 on: October 27, 2015, 09:11:31 PM »
Lets forget just for 1 second about the clean up part of my script, so far, its working or not needed.
What I am intrested in is renaming obfuscated filenames, and since its hard to know whether it is or not, it would be ok to always rename the filename (obfuscated or not) with the collection name.

Right now all my (new) files go into the same unrar directory, and they stay there until I have seen these TV eps. So 1 objective basically: only rename the most recent download/unrared file with the collection name just after the unrar process, without necessarily rename all the existing files in that folder.
Maybe the right way would be to do this in a separate empty "unrar" folder, perform the rename and then move renamed file into the final target destination.

Let me investigate but feel free to add your useful comments, I think I need to find the "move" (or copy delete) command  8)

Offline Hecks

  • Contributor
  • ***
  • Posts: 2011
  • naughty cop
Re: Alt.binz Scripts - The Code!
« Reply #22 on: October 27, 2015, 09:32:29 PM »
OK, some more thoughts. I rarely dl obfuscated files so I haven't scripted it myself yet, but in your situation I would:

1. Write a script that can be run just as easily outside Alt.Binz
2. Use Powershell rather than cmd.exe (it's quicker and easier, but ofc another language to learn)

So I would probably: create a base destination folder for all unrars like Z:\unrared, then enable option in Alt.Binz to create subfolders in that based on NZB name (in Setup > Unrar).

Then I would have a base folder populated with folders named after collections/NZBs, and inside those folders any final files associated with that NZB, some of which may be obfuscated. This is a good starting point for a script - iterate through each folder in Z:\unrar, and then iterate through each file and decide what to do with it. Renaming can now be based on folder name instead of a variable passed by Alt.Binz. I could then move the renamed files wherever I wanted, so I should end up with an empty Z:\unrared.

That's how I'd probably approach it, anyways. For one thing, it's a lot easier to test this way, and to run manually if for some reason Alt.Binz doesn't do as expected ;)
« Last Edit: October 27, 2015, 09:34:40 PM by Hecks »

Offline Rdl

  • Administrator
  • *****
  • Posts: 3935
Re: Alt.binz Scripts - The Code!
« Reply #23 on: October 27, 2015, 09:34:03 PM »
Lets forget just for 1 second about the clean up part of my script, so far, its working or not needed.
What I am intrested in is renaming obfuscated filenames, and since its hard to know whether it is or not, it would be ok to always rename the filename (obfuscated or not) with the collection name.

Right now all my (new) files go into the same unrar directory, and they stay there until I have seen these TV eps. So 1 objective basically: only rename the most recent download/unrared file with the collection name just after the unrar process, without necessarily rename all the existing files in that folder.
Maybe the right way would be to do this in a separate empty "unrar" folder, perform the rename and then move renamed file into the final target destination.

Let me investigate but feel free to add your useful comments, I think I need to find the "move" (or copy delete) command  8)
Terrible idea to use same unrar dir. Use nzb name, target file based on size, rename (move) to right folder and then deleteunrar folder (based on nzb name)

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #24 on: October 27, 2015, 10:22:47 PM »
This is useful, by just unraring to specific folders based on NZBname, rename was performed successfully, now on to moving these to final target directory and deleting empty unrared folders.  8)
thanks

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #25 on: October 27, 2015, 10:35:56 PM »
I did it  8) thanks to you Guys!
Unrar to a specific folder named after NZB
then running script

Here is the code  ;D
Code: [Select]
DEL "%~f2\*.nfo"
DEL "%~f2\*.jpg"
DEL "%~f2\*.ssr"
DEL "%~f2\*.nzb"
DEL "%~f2\*.srs"
DEL "%~f2\*.php"
DEL "%~f2\*.url"
DEL "%~f2\*.rar"
FOR %%f IN ("%~f2\*.mkv") DO REN "%%f" "%~3.mkv"
FOR %%f IN ("%~f2\*.mkv") DO MOVE "%%f" "\\NAS\new episodes\"
RMDIR "%~f2"

Thanks a lot.

Offline Rdl

  • Administrator
  • *****
  • Posts: 3935
Re: Alt.binz Scripts - The Code!
« Reply #26 on: October 27, 2015, 10:51:34 PM »
This one:
Code: [Select]
FOR %%f IN ("%~f2\*.mkv") DO REN "%%f" "%~3.mkv"
FOR %%f IN ("%~f2\*.mkv") DO MOVE "%%f" "\\NAS\new episodes\"

can go in 1 line:
Code: [Select]
FOR %%f IN ("%~f2\*.mkv") DO MOVE "%%f" "\\NAS\new episodes\%~3.mkv"

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #27 on: October 27, 2015, 10:56:33 PM »
Done, thanks Rdl

One final question:
I use sometimes a specific unrar directory through RSS customization (when I want to archive it for later, straight into its own directory)
SeriesName* | A | | specific_unrar_directory

So it would be nice in my script to move the final renamed file to this "specific_unrar_directory" rather than the usual "static" one
I am sure you see what I mean.
Should I use another script for this case where the target directory would be %~3?
Code: [Select]
FOR %%f IN ("%~f2\*.mkv") DO MOVE "%%f" "\\NAS\%~3.mkv"
if I do that, where do I process the script? since RSS unrar_directory superseeds general ALTBINZ option?!  :o :o
« Last Edit: October 27, 2015, 11:03:16 PM by domdom »

Offline Hecks

  • Contributor
  • ***
  • Posts: 2011
  • naughty cop
Re: Alt.binz Scripts - The Code!
« Reply #28 on: October 27, 2015, 11:04:37 PM »
You also don't need any of that cleanup, since you're just moving everything you want out anyway. So just delete everything at the end with:

Code: [Select]
rmdir /s /q "%~f2"

Offline domdom

  • Contributor
  • ***
  • Posts: 110
Re: Alt.binz Scripts - The Code!
« Reply #29 on: October 27, 2015, 11:05:26 PM »
You also don't need any of that cleanup, since you're just moving everything you want out anyway. So just delete everything at the end:

Code: [Select]
rmdir /s /q "%~f2"

So true  8)