r/Piracy•
MethaCat

Help to get a script/command to uncompress different types of movie files on their own folder.

Question

Hi, after getting tired of very slow or unresponsive VLC performance with compressed files I decided to uncompress my entire movie library (500 + titles on a network drive), but ran into some problems (I'm on Windows 10 btw):

  1. They have different format endings, which makes filtering difficult (some are .rar some are .r01 and some are .001). And to make matters worse some have a .rar file with the compressed subs and a .r01 .... .r40 file with the movie in the same folder.
  2. I want them all to be uncompressed on the same folder.
  3. I would love to be able to do this without using any 3rd party software, any cmd, powershell or windows explorer trick will do, however if there is just no other way, I'll go for that.

So far I've tried several scripts and tricks such as:

a. Doing a *.rar search on the file explorer and just right click and select extract here (which fails since it either extracts it in root or in the single folder where I right click).

b. This power shell script: Get-ChildItem -Filter *.rar -Recurse "D:\MovieFolder\" | % { $_.FullName } | Split-Path | % { cd $_ ; &'C:\Program Files\WinRAR\WinRAR.exe' x *.rar -o*}

Which also fail as it behaves inconsistently, extracts some and some others it just won't.

c. This batch script:

for /r C:\MovieFolder %%a in (filename.r*) do ( 7z e %%a -o%%a_Extracted del %%a /f /q )

Which also behaves inconsistently or messes up the locations where it extracts the files.

Any help or comments are appreciated, thanks for reading.

Posted Sep 7, 2020, 7:19 AM UTC

012
Chuhc •

Dunno if I got your explanation right. find . -type f -exec 7z e {}\; finds all files in the current directory and its subdirectories and extracts them all to the current directory.

2
MethaCatOP •

Thanks for your reply, it doesn't seem to work with split files, as 7zip just won't like them, I have to use the rar.exe command version which is the only one that will kind of work with split files.

1
Chuhc •

You have to understand what the scripts is doing and rewrite it to your preferences.

Instead of using 7z on every file like we did in my proposal we can loop through the found files with a for loop. That way we can check the file extension before doing something with it.

#!/bin/bash
for i in $(find . -type f)
do
    if [[ "$i" =~ .rar$ ]];then
        echo $i
    fi
done

The script I posted above searches all files recursively in a folder and only echoes files that end with .rar. You can change echo $ito unrar x $i or unrar e $i which would extract all rar files to the current directory.

2
MethaCatOP •

Thank you again, this I think should also work once I change it to a .bat, although I guess I would have to run this loop at least one more time to search for .001 type of files.

Guess I'm still kind of wondering if you can't just assign the for loop to look for "winrar archive" type of files (which include all .rar, .r01 and .001 types) .... guess you just define those at the beginning? I'm not sure about the cmd syntax for that, guess I'll look into that.

1
Chuhc •

You can use Bash in Windows either by using WSL or MinGW. Those simple scripts should run without an issue.

Guess I'm still kind of wondering if you can't just assign the for loop to look for "winrar archive" type of files (which include all .rar, .r01 and .001 typed) .... guess you just define those at the beginning? I'm not sure about the cmd syntax for that, guess I'll look into that.

You could extend the script by adding additional if statements that check for .rXX or .XXX. This way you can treat each file type in a different way.

#!/bin/bash
for i in $(find . -type f)
do
    if [[ "$i" =~ .rar$ ]];then
        echo $i # Will echo all rar files recursively
    fi
    if [[ "$i" =~ .r[0-9]{1,}$ ]];then
        echo $i # Will echo all rXX files recursively
    fi
    if [[ "$i" =~ .[0-9]{1,}$ ]];then
        echo $i # Will echo all XXX files recursively
    fi
done

Or you put it in a single if statement if you want to extract all of them with the same application.

#!/bin/bash
for i in $(find . -type f)
do
    if [[ "$i" =~ .rar$ || "$i" =~ .r[0-9]{1,}$ || "$i" =~ .[0-9]{1,}$ ]];then
        echo $i # Will echo all rar, rXX, XXX files recursively
    fi
done
2
gandraw •

You have an obvious error in your Powershell, instead of

Split-Path

it needs to be

Split-Path -Parent

in order to return the parent directory

2
gandraw •

Actually you're not really allowed to have two % in a single pipe either. Try something like

Get-ChildItem -Filter *.rar -Recurse "D:\MovieFolder\" | % { cd (Split-Path $_ -Parent); &'C:\Program Files\WinRAR\WinRAR.exe' x *.rar -o*}
2
MethaCatOP •

Get-ChildItem -Filter *.rar -Recurse "D:\MovieFolder\" | % { cd (Split-Path $_ -Parent); &'C:\Program Files\WinRAR\WinRAR.exe' x *.rar -o*}

The previous code was kind of working, with this one it just can't find any files.

Although after tinkering with this option for a while I guess I will have to abandon it, as I run into a serious problem using -filter or get-unique, as there are folders where there are 2 files, one called movie.rar with the subtitles and another which starts the split files of the movie called movie.r00. No matter how much I change either the powershell or the rar cmd it only extracts the first one.

Anyways, thanks a lot for all the help.

1
MethaCatOP •

Get-ChildItem -Filter *.rar -Recurse "D:\MovieFolder\" | % { $_.FullName } | Split-Path -Parent | % { cd $_ ; &'C:\Program Files\WinRAR\WinRAR.exe' x *.rar -o*}

Thank you for that, that seems to take work with both .rar and .r00 type of files now I just have to find a way to work with the .001 type of files.

1