Extract multipart .rar while download

2

1

let's say, I have a download of a multipart .rar file, one file inside.

Earlier on Windows with winrar, I opened part01.rar, and started extraction. It was extracting until the end of the last part, that already has been downloaded, and then prompted me for the next part. So I could watch the video, for example, and just hit "repeat" in WinRAR as the next parts had been finished.

Is there a way on ubuntu like this? I would even prefer an automatic command line solution... like one process waiting for new .rar files and then sending the "repeat" to the other process...

I hope, it's not too hard to understand :)

David.

davidbaumann

Posted 2015-04-15T07:51:24.270

Reputation: 2 089

Edited the tags since WinRAR obviously doesn't (directly) run on Ubuntu. Speaking of which, have you tried running it via Wine? – Karan – 2015-04-15T08:26:30.830

I want to solve this with onboard-Tools, not wine or proprietary software (except unrar-nonfree)... – davidbaumann – 2015-04-15T09:01:20.720

1Have you tried unrar x filename.part1.rar? – Albin – 2018-10-25T11:50:02.113

The command rar x filename.part1.rar will extract all the filename.part*.rar into a filename file. – GAD3R – 2018-10-25T13:25:08.443

Try to extract everything up to the missing part by unrar x -kb myfile.rar.01. Where -kb stands for "Keep broken extracted files". – harrymc – 2018-10-25T17:53:13.183

Is Hastur's answer not acceptable? I could try to come up with something else but the script he / she provided seems like it would do what you need. – Layne Bernardo – 2018-11-01T05:24:24.923

Answers

2

A cozy script or simply unrar -kb

Unrar itself provides an option (-kb) to keep broken (or incomplete) extracted files.
The thing to notice here is the exit code (3) that, different from 0, states the occurrence of an error 8-).
So you can simply make a script trying to extract the file until it will succeed (exit code 0).

Reading its help with man unrar (it 's never harmful to give a couple of man at day), you may notice at least a couple of other options useful for the script, namely -o+ and -inul to force the overwriting of the file(s) and to suppress the output.

If the script is named go.sh you may make it executable (chmod u+x ./go.sh) and then execute ./go.sh Myfile.part01.rar. Note you can change the values for the sleeping time and the maximum number of allowed iterations.

#!/bin/bash
MaxCounter=5       # Max number of iteration before it exits 
TimeToSleep=10m    # Time to sleep between 2 iteractions
COUNTER=0

until [ $COUNTER -gt $MaxCounter  ] 
 do 
   printf "### Attempt $COUNTER on $MaxCounter\t"
   unrar x "$@" -kb -inul -o+ \
     && { printf "\n\n### Extraction completed\n\n ### DONE ###\n\n"; exit 0; }\  
     || echo "### Extraction Not completed"
   let COUNTER+=1  
   sleep $TimeToSleep
 done
printf "\n\n### $MaxCounter iterations reached \n\n ### ERROR ### \n"

Note: As disadvantage it will overwrite each time the file... but it was what you were doing with winrar too... The good thing is that it is enough high the probability that the file is in some cache buffer and it will not be really overwritten each time...
If you are able to find a version of unrar (or another program, as e.g. 7z...) that continues the extraction it will be more efficient without overwriting.

Hastur

Posted 2015-04-15T07:51:24.270

Reputation: 15 043

It's not sure that one can overwrite the existing file while it's being viewed in the player. Or another problem, the player may need to close and re-open the video to read the addition, and will then restart from the beginning of the video. Or still another, if reopening is strangely not required, the player may become confused with data that suddenly changed. – harrymc – 2018-10-31T07:54:35.450

@harrymc Yes usually you can. Vlc, e.g., allows to read the file even meanwhile you are still creating it (so not yet closed by the process that is writing, and of course not owned by vlc). Moreover it updates even the time to the end... Players, in my experience, are not confused: or they are able to see the new file or they remain stuck with the old one cached... BTW how to make a player aware that the file is changed is another question (and even player dependent). :-) – Hastur – 2018-10-31T14:06:44.913

0

The command for unrar to extract everything possible and ignore missing pieces in a multi-part RAR archive is :

 unrar x -kb myfile.rar.01

Where -kb stands for "Keep broken extracted files".

This should extract the video up to the missing part and stop, thus letting you continue to watch the video from the part before.

Unfortunately, it doesn't wait for missing pieces. A solution that uses a script to feed pieces to unrar and wait, unfortunately cannot work as well, since FIFO (first-in-first-out) streams like /dev/stdin are not seekable, and that's apparently what unrar needs to be able to process the archive.

harrymc

Posted 2015-04-15T07:51:24.270

Reputation: 306 093

Have you verified this yourself or used information you found on the internet? If it's the latter it would be nice if you can provide the source... and thanks anyway for you're research! : ) – Albin – 2018-10-26T18:46:17.200