mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-07 13:41:12 -07:00
more logging + minor fixes
This commit is contained in:
parent
0460a5c1c7
commit
d086811270
1 changed files with 14 additions and 6 deletions
|
@ -5,6 +5,7 @@ import ConfigParser
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from subprocess import call
|
||||||
|
|
||||||
# Custom imports
|
# Custom imports
|
||||||
import linktastic.linktastic as linktastic
|
import linktastic.linktastic as linktastic
|
||||||
|
@ -81,7 +82,7 @@ def is_sample(file_path, Name):
|
||||||
# 200 MB in bytes
|
# 200 MB in bytes
|
||||||
SIZE_CUTOFF = 200 * 1024 * 1024
|
SIZE_CUTOFF = 200 * 1024 * 1024
|
||||||
# ignore 'sample' in files unless 'sample' in Torrent Name
|
# ignore 'sample' in files unless 'sample' in Torrent Name
|
||||||
if ('sample' in file_path.lower()) and (not'sample' in Name) and (os.path.getsize(file_path) < SIZE_CUTOFF)):
|
if ('sample' in file_path.lower()) and (not 'sample' in Name) and (os.path.getsize(file_path) < SIZE_CUTOFF)):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -90,20 +91,24 @@ def copy_link(source, target, useLink, destination):
|
||||||
## Create destination folder
|
## Create destination folder
|
||||||
if not os.path.exists(destination):
|
if not os.path.exists(destination):
|
||||||
try:
|
try:
|
||||||
|
Logger.debug("Creating destination folder: %s", destination)
|
||||||
os.makedirs(destination)
|
os.makedirs(destination)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
Logger.error("Not possible to create destination folder: %s", e)
|
Logger.error("Not possible to create destination folder: %s", e)
|
||||||
return False
|
return False
|
||||||
if useLink:
|
if useLink:
|
||||||
try:
|
try:
|
||||||
|
Logger.debug("Linking %s to %s", source, target)
|
||||||
linktastic.link(source, target)
|
linktastic.link(source, target)
|
||||||
except:
|
except:
|
||||||
if os.path.isfile(target):
|
if os.path.isfile(target):
|
||||||
Logger.info("something went wrong in linktastic.link, but the destination file was created")
|
Logger.info("something went wrong in linktastic.link, but the destination file was created")
|
||||||
else:
|
else:
|
||||||
Logger.info("something went wrong in linktastic.link. trying to create a copy")
|
Logger.info("something went wrong in linktastic.link. trying to create a copy")
|
||||||
|
Logger.debug("Copying %s to %s", source, target)
|
||||||
shutil.copy(source, target)
|
shutil.copy(source, target)
|
||||||
else:
|
else:
|
||||||
|
Logger.debug("Copying %s to %s", source, target)
|
||||||
shutil.copy(source, target)
|
shutil.copy(source, target)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -152,15 +157,16 @@ def unpack(dirpath, file, destination):
|
||||||
## Create destination folder
|
## Create destination folder
|
||||||
if not os.path.exists(destination):
|
if not os.path.exists(destination):
|
||||||
try:
|
try:
|
||||||
|
Logger.debug("Creating destination folder: %s", destination)
|
||||||
os.makedirs(destination)
|
os.makedirs(destination)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
Logger.error("Not possible to create destination folder: %s", e)
|
Logger.error("Not possible to create destination folder: %s", e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
Logger.info("Extracting to %s", destination)
|
Logger.info("Extracting %s to %s", fp, destination)
|
||||||
|
|
||||||
## Running..
|
## Running..
|
||||||
Logger.info("Extracting %s %s %s %s", cmd[0], cmd[1], fp, destination)
|
Logger.debug("Extracting %s %s %s %s", cmd[0], cmd[1], fp, destination)
|
||||||
pwd = os.getcwd() # Get our Present Working Directory
|
pwd = os.getcwd() # Get our Present Working Directory
|
||||||
os.chdir(destination) #not all unpack commands accept full paths, so just extract into this directory.
|
os.chdir(destination) #not all unpack commands accept full paths, so just extract into this directory.
|
||||||
if os.name == 'nt': #Windows needs quotes around directory structure
|
if os.name == 'nt': #Windows needs quotes around directory structure
|
||||||
|
@ -189,6 +195,7 @@ def unpack(dirpath, file, destination):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def flatten(destination):
|
def flatten(destination):
|
||||||
|
Logger.info("Flattening directory: %s", destination)
|
||||||
for dirpath, dirnames, filenames in os.walk(destination): #flatten out the directory to make postprocessing easier.
|
for dirpath, dirnames, filenames in os.walk(destination): #flatten out the directory to make postprocessing easier.
|
||||||
if dirpath == destination:
|
if dirpath == destination:
|
||||||
continue #no need to try and move files in the root destination directory.
|
continue #no need to try and move files in the root destination directory.
|
||||||
|
@ -200,6 +207,7 @@ def flatten(destination):
|
||||||
removeEmptyFolders(destination) #cleanup empty directories.
|
removeEmptyFolders(destination) #cleanup empty directories.
|
||||||
|
|
||||||
def removeEmptyFolders(path):
|
def removeEmptyFolders(path):
|
||||||
|
Logger.info("Removing empty folders in: %s", path)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -214,7 +222,7 @@ def removeEmptyFolders(path):
|
||||||
# if folder empty, delete it
|
# if folder empty, delete it
|
||||||
files = os.listdir(path)
|
files = os.listdir(path)
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
Logger.info("Removing empty folder: %s", path)
|
Logger.debug("Removing empty folder: %s", path)
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
|
|
||||||
if len(sys.argv) == 4:
|
if len(sys.argv) == 4:
|
||||||
|
@ -303,9 +311,9 @@ for dirpath, dirnames, filenames in os.walk(Directory):
|
||||||
if root == 1:
|
if root == 1:
|
||||||
Logger.debug("Looking for %s in filename", Name)
|
Logger.debug("Looking for %s in filename", Name)
|
||||||
if (Name in file) or (file in Name):
|
if (Name in file) or (file in Name):
|
||||||
pass
|
pass #This file does match the Torrent name
|
||||||
else:
|
else:
|
||||||
continue
|
continue #This file does not match the Torrent name. Skip it
|
||||||
file_path = os.path.join(dirpath, file)
|
file_path = os.path.join(dirpath, file)
|
||||||
file_ext = os.path.splitext(file)
|
file_ext = os.path.splitext(file)
|
||||||
if file_ext in video_files: #if the file is a video file.
|
if file_ext in video_files: #if the file is a video file.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue