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
|
@ -7,9 +7,8 @@ category = tv
|
||||||
destination = /abs/path/to/complete/tv
|
destination = /abs/path/to/complete/tv
|
||||||
|
|
||||||
[Torrent]
|
[Torrent]
|
||||||
uselink = 1
|
uselink = 0
|
||||||
unpacker = 'C:\\Program Files\\7-Zip\\7z.exe'
|
extractiontool = 'C:\\Program Files\\7-Zip\\7z.exe'
|
||||||
parcheck = /abs/path/to/par2
|
|
||||||
|
|
||||||
[Notes]
|
[Notes]
|
||||||
copy = 0 will create hard links to your original download.
|
copy = 0 will create hard links to your original download.
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys
|
|
||||||
import autoProcessMovie
|
import autoProcessMovie
|
||||||
import autoProcessTV
|
import autoProcessTV
|
||||||
import ConfigParser
|
import sys, os, glob, ConfigParser
|
||||||
import os
|
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
import glob
|
|
||||||
|
|
||||||
|
|
||||||
##You can use the following parameters (UTORRENT):
|
##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
|
status = 0
|
||||||
packed = 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")
|
||||||
|
@ -60,17 +55,12 @@ if not os.path.isfile(configFilename):
|
||||||
|
|
||||||
config.read(configFilename)
|
config.read(configFilename)
|
||||||
|
|
||||||
Movie_Cat = config.get("CouchPotato", "category")
|
|
||||||
TV_Cat = config.get("SickBeard", "category")
|
TV_Cat = config.get("SickBeard", "category")
|
||||||
|
|
||||||
Movie_dest = config.get("CouchPotato", "destination")
|
|
||||||
TV_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"))
|
useLink = int(config.get("Torrent", "uselink"))
|
||||||
packed = config.get("Torrent", "packed")
|
extractionTool = config.get("Torrent", "extractiontool")
|
||||||
unpacker = config.get("Torrent", "unpacker")
|
|
||||||
|
|
||||||
parcheck = config.get("Torrent", "parcheck")
|
|
||||||
|
|
||||||
if Category == Movie_Cat:
|
if Category == Movie_Cat:
|
||||||
destination = Movie_dest
|
destination = Movie_dest
|
||||||
|
@ -79,84 +69,69 @@ 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"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 "Found compressed archives, extracting"
|
||||||
packed = 1
|
packed = 1
|
||||||
|
|
||||||
test = os.path.join(destination, '*.par2')
|
## TODO: Check that files actully is .mkv / .avi etc, and not packed files or anything else
|
||||||
if glob.glob(test):
|
if useLink == 1 and packed == 0: ## symlinks
|
||||||
print "par2 files detected"
|
print "Copying all files from", Directory, "to", destination
|
||||||
par2 = 1
|
shutil.copytree(Directory, destination)
|
||||||
|
|
||||||
## QUESTION: Do we need this? PAR check is only for usenet?
|
elif useLink == 0 and packed == 0: ## hardlink
|
||||||
if par2:
|
print "Creating hard link from", Directory, "to", destination
|
||||||
#parcheck here
|
shutil.copytree(src, dst, copy_function=os.link)
|
||||||
#parcheck
|
|
||||||
|
elif useLink == 0 and packed == 1: ## unpack
|
||||||
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 = [extractionTool, 'x']
|
||||||
ext_7zip = [".rar",
|
ext_7zip = [".rar",".zip",".tar.gz","tgz",".tar.bz2", ".tbz",".tar.lzma", ".tlz",".7z", ".xz"]
|
||||||
".zip",
|
|
||||||
".tar.gz", "tgz",
|
|
||||||
".tar.bz2", ".tbz",
|
|
||||||
".tar.lzma", ".tlz",
|
|
||||||
".7z", ".xz"]
|
|
||||||
EXTRACT_COMMANDS = dict.fromkeys(ext_zip, cmd_7zip)
|
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)) ]
|
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:
|
||||||
if ext[1] in EXTRACT_COMMANDS:
|
if ext[1] in EXTRACT_COMMANDS:
|
||||||
cmd = EXTRACT_COMMANDS[ext[1]]
|
cmd = EXTRACT_COMMANDS[ext[1]]
|
||||||
else:
|
else:
|
||||||
print("unknown file type: %s", ext[1])
|
print("ERROR: Unknown file type: %s", ext[1])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
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(destination, 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)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print("cant create destination folder: %s", e)
|
print("ERROR: Not possible to create destination folder: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
print("extracting to %s", dest)
|
print("extracting to %s", dest)
|
||||||
def on_extract_success(result):
|
def on_extract_success(result):
|
||||||
print("extract was successful for %s")
|
print("Extract was successful for %s")
|
||||||
|
|
||||||
def on_extract_failed(result, torrent_id):
|
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)
|
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:
|
else:
|
||||||
## TODO: Check that files actully is .mkv / .avi etc, and not packed files
|
print "Didn't find any compressed archives or media files to process, exiting"
|
||||||
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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue