mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 05:13:16 -07:00
A lot happened here.
Added additional tests for movie files. Ensured follow-through of each test etc. Changed formatting and generally tidied up.
This commit is contained in:
parent
05d12c782c
commit
fcd27f1a9f
1 changed files with 94 additions and 78 deletions
|
@ -2,43 +2,51 @@
|
||||||
|
|
||||||
import autoProcessMovie
|
import autoProcessMovie
|
||||||
import autoProcessTV
|
import autoProcessTV
|
||||||
import sys, os, glob, ConfigParser
|
import sys, os, ConfigParser
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
|
|
||||||
##You can use the following parameters (UTORRENT):
|
|
||||||
##
|
|
||||||
##%F - Name of downloaded file (for single file torrents)
|
|
||||||
##%D - Directory where files are saved
|
|
||||||
##%N - Title of torrent
|
|
||||||
##%P - Previous state of torrent
|
|
||||||
##%L - Label
|
|
||||||
##%T - Tracker
|
|
||||||
##%M - Status message string (same as status column)
|
|
||||||
##%I - hex encoded info-hash
|
|
||||||
##%S - State of torrent
|
|
||||||
##%K - kind of torrent (single|multi)
|
|
||||||
##
|
|
||||||
##Where State is one of:
|
|
||||||
##
|
|
||||||
##Error - 1
|
|
||||||
##Checked - 2
|
|
||||||
##Paused - 3
|
|
||||||
##Super seeding - 4
|
|
||||||
##Seeding - 5
|
|
||||||
##Downloading - 6
|
|
||||||
##Super seed [F] - 7
|
|
||||||
##Seeding [F] - 8
|
|
||||||
##Downloading [F] - 9
|
|
||||||
##Queued seed - 10
|
|
||||||
##Finished - 11
|
|
||||||
##Queued - 12
|
|
||||||
##Stopped - 13
|
|
||||||
|
|
||||||
## We will pass in %D, %N, %L from uTorrent
|
print "TorrentToMedia v 4.1"
|
||||||
Directory = sys.argv[1] ## %D -- Example output: F:\path\to\dir\My.Series.S01E01.720p.HDTV.x264-2HD
|
if len(sys.argv) == 4
|
||||||
Name = sys.argv[2] ## %N -- Example output: My.Series.S01E01.720p.HDTV.x264-2HD
|
##You can use the following parameters (UTORRENT):
|
||||||
Category = sys.argv[3] ## %L -- Example output: tvseries ## This is the label in uTorrent
|
##
|
||||||
|
##%F - Name of downloaded file (for single file torrents)
|
||||||
|
##%D - Directory where files are saved
|
||||||
|
##%N - Title of torrent
|
||||||
|
##%P - Previous state of torrent
|
||||||
|
##%L - Label
|
||||||
|
##%T - Tracker
|
||||||
|
##%M - Status message string (same as status column)
|
||||||
|
##%I - hex encoded info-hash
|
||||||
|
##%S - State of torrent
|
||||||
|
##%K - kind of torrent (single|multi)
|
||||||
|
##
|
||||||
|
##Where State is one of:
|
||||||
|
##
|
||||||
|
##Error - 1
|
||||||
|
##Checked - 2
|
||||||
|
##Paused - 3
|
||||||
|
##Super seeding - 4
|
||||||
|
##Seeding - 5
|
||||||
|
##Downloading - 6
|
||||||
|
##Super seed [F] - 7
|
||||||
|
##Seeding [F] - 8
|
||||||
|
##Downloading [F] - 9
|
||||||
|
##Queued seed - 10
|
||||||
|
##Finished - 11
|
||||||
|
##Queued - 12
|
||||||
|
##Stopped - 13
|
||||||
|
|
||||||
|
## We will pass in %D, %N, %L from uTorrent
|
||||||
|
Directory = sys.argv[1] ## %D -- Example output: F:\path\to\dir\My.Series.S01E01.720p.HDTV.x264-2HD
|
||||||
|
Name = sys.argv[2] ## %N -- Example output: My.Series.S01E01.720p.HDTV.x264-2HD
|
||||||
|
Category = sys.argv[3] ## %L -- Example output: tvseries ## This is the label in uTorrent
|
||||||
|
|
||||||
|
else:
|
||||||
|
##test for Transmission here.
|
||||||
|
print "currently only supports uTorrent. Exiting"
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
status = 0
|
status = 0
|
||||||
packed = 0
|
packed = 0
|
||||||
|
@ -46,12 +54,11 @@ packed = 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 "torrentToMedia v 4.1"
|
|
||||||
print "INFO: Loading config from", configFilename
|
print "INFO: Loading config from", configFilename
|
||||||
|
|
||||||
if not os.path.isfile(configFilename):
|
if not os.path.isfile(configFilename):
|
||||||
print "ERROR: You need an autoProcessMovie.cfg file - did you rename and edit the .sample?"
|
print "ERROR: You need a TorrentToMedia.cfg file - did you rename and edit the .sample?"
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
config.read(configFilename)
|
config.read(configFilename)
|
||||||
|
|
||||||
|
@ -63,27 +70,34 @@ useLink = int(config.get("Torrent", "uselink"))
|
||||||
extractionTool = config.get("Torrent", "extractiontool")
|
extractionTool = config.get("Torrent", "extractiontool")
|
||||||
|
|
||||||
if Category == Movie_Cat:
|
if Category == Movie_Cat:
|
||||||
destination = Movie_dest
|
destination = Movie_dest
|
||||||
elif Category == TV_Cat:
|
elif Category == TV_Cat:
|
||||||
destination = TV_dest
|
destination = TV_dest
|
||||||
else;
|
else;
|
||||||
print "INFO: Not assigned a label of either", Movie_Cat, "or", TV_Cat, ". Exiting"
|
print "INFO: Not assigned a label of either", Movie_Cat, "or", TV_Cat, ". Exiting"
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
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);
|
||||||
|
test2 = re.compile('^(.*)\.(mkv|avi|divx|xvid|mov|wmv)$', re.IGNORECASE|re.UNICODE);
|
||||||
if test.match(Directory):
|
if test.match(Directory):
|
||||||
print "INFO: Found compressed archives, extracting"
|
print "INFO: Found compressed archives, extracting"
|
||||||
packed = 1
|
packed = 1
|
||||||
|
## Check that files actully is .mkv / .avi etc, and not packed files or anything else
|
||||||
## TODO: Check that files actully is .mkv / .avi etc, and not packed files or anything else
|
elif test2.match(Directory):
|
||||||
if useLink == 1 and packed == 0: ## symlinks
|
print "INFO: Found media files, moving"
|
||||||
|
else:
|
||||||
|
print "INFO: Didn't find any compressed archives or media files to process, exiting"
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
if useLink == 0 and packed == 0: ## copy
|
||||||
print "INFO: Copying all files from", Directory, "to", destination
|
print "INFO: Copying all files from", Directory, "to", destination
|
||||||
shutil.copytree(Directory, destination)
|
shutil.copytree(Directory, destination)
|
||||||
|
|
||||||
elif useLink == 0 and packed == 0: ## hardlink
|
elif useLink == 1 and packed == 0: ## hardlink
|
||||||
print "INFO: Creating hard link from", Directory, "to", destination
|
print "INFO: Creating hard link from", Directory, "to", destination
|
||||||
shutil.copytree(src, dst, copy_function=os.link)
|
shutil.copytree(Directory, destination, copy_function=os.link)
|
||||||
|
|
||||||
elif useLink == 0 and packed == 1: ## unpack
|
elif packed == 1: ## unpack
|
||||||
## Using Windows?
|
## Using Windows?
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
cmd_7zip = [extractionTool, 'x -y']
|
cmd_7zip = [extractionTool, 'x -y']
|
||||||
|
@ -117,45 +131,47 @@ elif useLink == 0 and packed == 1: ## unpack
|
||||||
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])[1] == ".tar":
|
||||||
cmd = EXTRACT_COMMANDS[".tar" + ext[1]]
|
cmd = EXTRACT_COMMANDS[".tar" + ext[1]]
|
||||||
|
else:
|
||||||
|
if ext[1] in EXTRACT_COMMANDS:
|
||||||
|
cmd = EXTRACT_COMMANDS[ext[1]]
|
||||||
else:
|
else:
|
||||||
if ext[1] in EXTRACT_COMMANDS:
|
print("ERROR: Unknown file type: %s", ext[1])
|
||||||
cmd = EXTRACT_COMMANDS[ext[1]]
|
continue
|
||||||
else:
|
|
||||||
print("ERROR: Unknown file type: %s", ext[1])
|
fp = os.path.join(destination, os.path.normpath(f["path"]))
|
||||||
continue
|
|
||||||
fp = os.path.join(destination, 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("ERROR: Not possible to create destination folder: %s", e)
|
print("ERROR: Not possible to create destination folder: %s", e)
|
||||||
return
|
return
|
||||||
|
|
||||||
print("INFO: Extracting to %s", dest)
|
print("INFO: Extracting to %s", dest)
|
||||||
def on_extract_success(result):
|
|
||||||
print("INFO: Extraction was successful for %s")
|
|
||||||
|
|
||||||
def on_extract_failed(result):
|
|
||||||
print("ERROR: Extraction failed for %s")
|
|
||||||
|
|
||||||
## Running..
|
## Running..
|
||||||
print("INFO: Extracting %s %s %s %s", cmd[0], cmd[1], fp, dest)
|
print("INFO: Extracting %s %s %s %s", cmd[0], cmd[1], fp, dest)
|
||||||
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:
|
|
||||||
print "INFO: Didn't find any compressed archives or media files to process, exiting"
|
|
||||||
|
|
||||||
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:
|
||||||
autoProcessTV.processEpisode(destination, Name, status)
|
autoProcessTV.processEpisode(destination, Name, status)
|
||||||
|
|
||||||
|
def on_extract_success(result):
|
||||||
|
print("INFO: Extraction was successful for %s")
|
||||||
|
status = 0
|
||||||
|
|
||||||
|
def on_extract_failed(result):
|
||||||
|
print("ERROR: Extraction failed for %s")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue