This commit is contained in:
Joel Kåberg 2013-02-01 09:33:08 +01:00
commit 501fb42657
2 changed files with 49 additions and 54 deletions

View file

@ -7,7 +7,7 @@ category = tv
destination = /abs/path/to/complete/tv destination = /abs/path/to/complete/tv
[Torrent] [Torrent]
copy = 1 uselink = 1
unpacker = 'C:\\Program Files\\7-Zip\\7z.exe' unpacker = 'C:\\Program Files\\7-Zip\\7z.exe'
parcheck = /abs/path/to/par2 parcheck = /abs/path/to/par2

View file

@ -10,7 +10,7 @@ from os.path import isfile, join
import glob import glob
##You can use the following parameters: ##You can use the following parameters (UTORRENT):
## ##
##%F - Name of downloaded file (for single file torrents) ##%F - Name of downloaded file (for single file torrents)
##%D - Directory where files are saved ##%D - Directory where files are saved
@ -40,14 +40,18 @@ import glob
##Stopped - 13 ##Stopped - 13
## We will pass in %D, %N, %L ## We will pass in %D, %N, %L
Directory = sys.argv[1] Directory = sys.argv[1] ## Example output: F:\path\to\dir\My.Series.S01E01.720p.HDTV.x264-2HD
Name = sys.argv[2] Name = sys.argv[2] ## Example output: My.Series.S01E01.720p.HDTV.x264-2HD
Category = sys.argv[3] Category = sys.argv[3] ## Example output: tvseries # this is the label in uTorrent
print "transmissionToMedia v 4.1"
status = 0
packed = 0
par2 = 0
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "TorrentToMedia.cfg") configFilename = os.path.join(os.path.dirname(sys.argv[0]), "TorrentToMedia.cfg")
print "transmissionToMedia v 4.1"
print "Loading config from", configFilename print "Loading config from", configFilename
if not os.path.isfile(configFilename): if not os.path.isfile(configFilename):
@ -58,11 +62,14 @@ config.read(configFilename)
Movie_Cat = config.get("CouchPotato", "category") Movie_Cat = config.get("CouchPotato", "category")
TV_Cat = config.get("SickBeard", "category") TV_Cat = config.get("SickBeard", "category")
Movie_dest = config.get("CouchPotato", "destination") Movie_dest = config.get("CouchPotato", "destination")
TV_dest = config.get("CouchPotato", "destination") TV_dest = config.get("CouchPotato", "destination")
Use_cp = int(config.get("Torrent", "copy"))
useLink = int(config.get("Torrent", "uselink"))
packed = config.get("Torrent", "packed") packed = config.get("Torrent", "packed")
unpacker = config.get("Torrent", "unpacker") unpacker = config.get("Torrent", "unpacker")
parcheck = config.get("Torrent", "parcheck") parcheck = config.get("Torrent", "parcheck")
if Category == Movie_Cat: if Category == Movie_Cat:
@ -72,37 +79,26 @@ elif Category == TV_Cat:
else; else;
print "Not assigned a label of either", Movie_Cat, "or", TV_Cat, ". Exiting" print "Not assigned a label of either", Movie_Cat, "or", TV_Cat, ". Exiting"
status = 0
packed = 0
par2 = 0
test = re.compile('^(.*)\.((zip|rar|7z|gz|bz|tar|arj)|(r[0-9]{1,3})|([0-9]{1,3}))$', re.IGNORECASE|re.UNICODE); test = re.compile('^(.*)\.((zip|rar|7z|gz|bz|tar|arj)|(r[0-9]{1,3})|([0-9]{1,3}))$', re.IGNORECASE|re.UNICODE);
if test.match(destination): if test.match(destination):
print "packed files detected" print "packed files detected"
packed = 1 packed = 1
#status = 1
test = os.path.join(destination, '*.par2') test = os.path.join(destination, '*.par2')
if glob.glob(test): if glob.glob(test):
print "par2 files detected" print "par2 files detected"
par2 = 1 par2 = 1
# QUESTION: Do we need this? PAR check is only for usenet? ## QUESTION: Do we need this? PAR check is only for usenet?
if par2: if par2:
#parcheck here #parcheck here
#parcheck #parcheck
# TODO: Check that files actully is .mkv / .avi etc, and not packed files
if Use_cp and packed == 0:
print "copying all files from", Directory, "to", destination
shutil.copytree(Directory, destination)
else:
print "creating hard link from", Directory, "to", destination
shutil.copytree(src, dst, copy_function=os.link)
if packed: if packed:
# 7z x test.rar ---- need to add "yes" to command ## 7z x test.rar ---- need to add "yes" to command
# windows only for now, should be adapted to *nix ## windows only for now, should be adapted to *nix
cmd_7zip = [unpacker, 'x'] cmd_7zip = [unpacker, 'x']
ext_7zip = [".rar", ext_7zip = [".rar",
".zip", ".zip",
@ -113,18 +109,12 @@ if packed:
EXTRACT_COMMANDS = dict.fromkeys(ext_zip, cmd_7zip) EXTRACT_COMMANDS = dict.fromkeys(ext_zip, cmd_7zip)
print('windows check passed') print('windows check passed')
# save path
if Category == Movie_Cat:
save_path = Movie_dest
elif Category == TV_Cat:
save_path = TV_dest
files = [ f for f in listdir(Directory) if isfile(join(Directory,f)) ] files = [ f for f in listdir(Directory) if isfile(join(Directory,f)) ]
for f in files: for f in files:
ext = os.path.splitext(f["path"]) ext = os.path.splitext(f["path"])
if ext[1] in (".gz", ".bz2", ".lzma"): if ext[1] in (".gz", ".bz2", ".lzma"):
# check if this is a tar ## check if this is a tar
if os.path.splitext(ext[0]) == ".tar": if os.path.splitext(ext[0]) == ".tar":
cmd = EXTRACT_COMMANDS[".tar" + ext[1]] cmd = EXTRACT_COMMANDS[".tar" + ext[1]]
else: else:
@ -136,10 +126,10 @@ if packed:
fp = os.path.join(save_path, os.path.normpath(f["path"])) fp = os.path.join(save_path, os.path.normpath(f["path"]))
# destination path ## destination path
dest = os.path.join(save_path, Name) dest = os.path.join(destination, Name)
# create destionation folder ## create destionation folder
if not os.path.exists(dest): if not os.path.exists(dest):
try: try:
os.makedirs(dest) os.makedirs(dest)
@ -155,16 +145,21 @@ if packed:
print("extract failed for %s") print("extract failed for %s")
print("hmm %s %s %s %s", cmd[0], cmd[1], fp, dest) print("hmm %s %s %s %s", cmd[0], cmd[1], fp, dest)
# running.. ## running..
d = getProcessValue(cmd[0], cmd[1].split() + [str(fp)], {}, str(dest)) d = getProcessValue(cmd[0], cmd[1].split() + [str(fp)], {}, str(dest))
d.addCallback(on_extract_success) d.addCallback(on_extract_success)
d.addErrback(on_extract_failed) d.addErrback(on_extract_failed)
else:
## TODO: Check that files actully is .mkv / .avi etc, and not packed files
status = 0 if useLink and packed == 0:
print "copying all files from", Directory, "to", destination
shutil.copytree(Directory, destination)
else:
print "creating hard link from", Directory, "to", destination
shutil.copytree(src, dst, copy_function=os.link)
status = int(status) status = int(status)
##Now we pass off to CouchPotato or SickBeard. ## Now we pass off to CouchPotato or SickBeard.
if Category == Movie_Cat: if Category == Movie_Cat:
autoProcessMovie.process(destination, Name, status) autoProcessMovie.process(destination, Name, status)
elif Category == TV_Cat: elif Category == TV_Cat: