mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-16 02:02:53 -07:00
more cleanup
This commit is contained in:
parent
501fb42657
commit
ce0d4b3f23
2 changed files with 30 additions and 56 deletions
|
@ -1,14 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import autoProcessMovie
|
||||
import autoProcessTV
|
||||
import ConfigParser
|
||||
import os
|
||||
import sys, os, glob, ConfigParser
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
import glob
|
||||
|
||||
|
||||
##You can use the following parameters (UTORRENT):
|
||||
##
|
||||
|
@ -46,7 +42,6 @@ Category = sys.argv[3] ## Example output: tvseries # this is the label in uTorre
|
|||
|
||||
status = 0
|
||||
packed = 0
|
||||
par2 = 0
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
configFilename = os.path.join(os.path.dirname(sys.argv[0]), "TorrentToMedia.cfg")
|
||||
|
@ -60,17 +55,12 @@ if not os.path.isfile(configFilename):
|
|||
|
||||
config.read(configFilename)
|
||||
|
||||
Movie_Cat = config.get("CouchPotato", "category")
|
||||
TV_Cat = config.get("SickBeard", "category")
|
||||
|
||||
Movie_dest = config.get("CouchPotato", "destination")
|
||||
TV_dest = config.get("CouchPotato", "destination")
|
||||
|
||||
Movie_dest = config.get("CouchPotato", "destination")
|
||||
Movie_Cat = config.get("CouchPotato", "category")
|
||||
useLink = int(config.get("Torrent", "uselink"))
|
||||
packed = config.get("Torrent", "packed")
|
||||
unpacker = config.get("Torrent", "unpacker")
|
||||
|
||||
parcheck = config.get("Torrent", "parcheck")
|
||||
extractionTool = config.get("Torrent", "extractiontool")
|
||||
|
||||
if Category == Movie_Cat:
|
||||
destination = Movie_dest
|
||||
|
@ -79,84 +69,69 @@ elif Category == TV_Cat:
|
|||
else;
|
||||
print "Not assigned a label of either", Movie_Cat, "or", TV_Cat, ". Exiting"
|
||||
|
||||
|
||||
|
||||
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):
|
||||
print "packed files detected"
|
||||
print "Found compressed archives, extracting"
|
||||
packed = 1
|
||||
|
||||
test = os.path.join(destination, '*.par2')
|
||||
if glob.glob(test):
|
||||
print "par2 files detected"
|
||||
par2 = 1
|
||||
|
||||
## QUESTION: Do we need this? PAR check is only for usenet?
|
||||
if par2:
|
||||
#parcheck here
|
||||
#parcheck
|
||||
|
||||
if packed:
|
||||
## TODO: Check that files actully is .mkv / .avi etc, and not packed files or anything else
|
||||
if useLink == 1 and packed == 0: ## symlinks
|
||||
print "Copying all files from", Directory, "to", destination
|
||||
shutil.copytree(Directory, destination)
|
||||
|
||||
elif useLink == 0 and packed == 0: ## hardlink
|
||||
print "Creating hard link from", Directory, "to", destination
|
||||
shutil.copytree(src, dst, copy_function=os.link)
|
||||
|
||||
elif useLink == 0 and packed == 1: ## unpack
|
||||
## 7z x test.rar ---- need to add "yes" to command
|
||||
## windows only for now, should be adapted to *nix
|
||||
cmd_7zip = [unpacker, 'x']
|
||||
ext_7zip = [".rar",
|
||||
".zip",
|
||||
".tar.gz", "tgz",
|
||||
".tar.bz2", ".tbz",
|
||||
".tar.lzma", ".tlz",
|
||||
".7z", ".xz"]
|
||||
## Windows only for now, should be adapted to *nix
|
||||
cmd_7zip = [extractionTool, 'x']
|
||||
ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2", ".tbz",".tar.lzma", ".tlz",".7z", ".xz"]
|
||||
EXTRACT_COMMANDS = dict.fromkeys(ext_zip, cmd_7zip)
|
||||
print('windows check passed')
|
||||
print('Found 7zip')
|
||||
|
||||
files = [ f for f in listdir(Directory) if isfile(join(Directory,f)) ]
|
||||
|
||||
for f in files:
|
||||
ext = os.path.splitext(f["path"])
|
||||
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":
|
||||
cmd = EXTRACT_COMMANDS[".tar" + ext[1]]
|
||||
else:
|
||||
if ext[1] in EXTRACT_COMMANDS:
|
||||
cmd = EXTRACT_COMMANDS[ext[1]]
|
||||
else:
|
||||
print("unknown file type: %s", ext[1])
|
||||
print("ERROR: Unknown file type: %s", ext[1])
|
||||
continue
|
||||
|
||||
fp = os.path.join(save_path, os.path.normpath(f["path"]))
|
||||
|
||||
## destination path
|
||||
## Destination path
|
||||
dest = os.path.join(destination, Name)
|
||||
|
||||
## create destionation folder
|
||||
## Create destionation folder
|
||||
if not os.path.exists(dest):
|
||||
try:
|
||||
os.makedirs(dest)
|
||||
except Exception, e:
|
||||
print("cant create destination folder: %s", e)
|
||||
print("ERROR: Not possible to create destination folder: %s", e)
|
||||
return
|
||||
|
||||
print("extracting to %s", dest)
|
||||
def on_extract_success(result):
|
||||
print("extract was successful for %s")
|
||||
print("Extract was successful for %s")
|
||||
|
||||
def on_extract_failed(result, torrent_id):
|
||||
print("extract failed for %s")
|
||||
print("ERROR: Extract failed for %s")
|
||||
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.addCallback(on_extract_success)
|
||||
d.addErrback(on_extract_failed)
|
||||
else:
|
||||
## TODO: Check that files actully is .mkv / .avi etc, and not packed files
|
||||
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)
|
||||
print "Didn't find any compressed archives or media files to process, exiting"
|
||||
|
||||
status = int(status)
|
||||
## Now we pass off to CouchPotato or SickBeard.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue