Since joining IPT some of the downloads come packed in rar. Where this is an issue is tv shows. Sometimes, like the DBZ I just downloaded come in a seasons folder, in the seasons folder is episodes folder, and in the episodes folders is a multipart rar file.
Example on season 1 episode 1:
/home/me/exthdd/DBZ/DBZ_SE1/DBZ_SE01_EP01/multipart.rar
Each seasons episode is in it own file in a multipart rar.
Unraring it by hand for each season->episode would take ages for 9 seasons of video files.
So, I wrote a little python script to grab all the file paths and unrar them all in succession with the "unrar" command.
On Arch, Kernel 3.15.8-1.
Depends: unrar
pacman -S unrar
Python 3 [should be installed]
# unrarpy
# By: TechB 8/8/14
import os, sys, subprocess
def unrar(fl):
rars = fl[0]
total = fl[1]
progress = 0
for r in rars:
p1, p2 = os.path.split(r)
os.chdir(p1)
#print("Progress in percent: %d" % int((progress/total)*100))
# -inul is supposed to suppress unrar output, not tested yet
#subprocess.call(["unrar", "-inul", "e", os.path.join(p1,p2)])
subprocess.call(["unrar", "e", os.path.join(p1,p2)])
progress += 1
print("All done")
def getFiles(rootdir):
rars = []
for root, dirs, files in os.walk(rootdir):
for f in files:
if ".RAR" in f.upper() and "SAMPLE.RAR" not in f.upper():
x = os.path.join(root, f)
rars.append(x)
return (rars, len(rars))
try:
rootdir = sys.argv[1]
except:
rootdir = os.getcwd()
filelist = getFiles(rootdir)
print("Total ammount to unrar: %d" % filelist[1])
ans = input("Proceed? y/n: ")
if ans == "n":
print("exiting...")
sys.exit()
elif ans == "y" or ans == "":
unrar(filelist)
print("exiting...")
else:
print("invalid answer, exiting...")
sys.exit()
Like all the code I post, very quick and dirty and does exactly what I need it to do on my own system and for a task I delegate. I wanted it to be better, like with a folder dialog and input checks and other things, but I don't really need it and was only written to extract the DBZ I downloaded. Please update it and make it more user friendly if you want. Even with quick simple mods could be used almost as is for your own personal needs.
There it is, first thing I've coded in a while and thought someone else might use it if there are in a similar situation.