mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Fixed a few bugs and made a few more improvements
This commit is contained in:
parent
3db20ab072
commit
2be1873cad
3 changed files with 39 additions and 39 deletions
|
@ -44,17 +44,16 @@ CONFIG_TV_FILE = None
|
|||
SYS_ENCODING = None
|
||||
SYS_ARGV = None
|
||||
|
||||
# version constants
|
||||
AUTO_UPDATE = None
|
||||
NZBTOMEDIA_VERSION = None
|
||||
NEWEST_VERSION = None
|
||||
NEWEST_VERSION_STRING = None
|
||||
VERSION_NOTIFY = None
|
||||
|
||||
GIT_PATH = None
|
||||
GIT_USER = None
|
||||
GIT_BRANCH = None
|
||||
GIT_REPO = None
|
||||
FORCE_CLEAN = None
|
||||
|
||||
NZB_CLIENTAGENT = None
|
||||
SABNZBDHOST = None
|
||||
|
@ -82,7 +81,6 @@ DELUGEUSR = None
|
|||
DELUGEPWD = None
|
||||
|
||||
COMPRESSEDCONTAINER = None
|
||||
MEDIAEXTENSIONS = None
|
||||
MEDIACONTAINER = None
|
||||
METACONTAINER = None
|
||||
MINSAMPLESIZE = None
|
||||
|
@ -105,6 +103,7 @@ OUTPUTSUBTITLECODEC = None
|
|||
OUTPUTFASTSTART = None
|
||||
OUTPUTQUALITYPERCENT = None
|
||||
NICENESS = None
|
||||
|
||||
USER_SCRIPT_CATEGORIES = None
|
||||
USER_SCRIPT_MEDIAEXTENSIONS = None
|
||||
USER_SCRIPT = None
|
||||
|
@ -130,7 +129,7 @@ def initialize(section=None):
|
|||
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
|
||||
DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, \
|
||||
OUTPUTVIDEOBITRATE, OUTPUTAUDIOCODEC, OUTPUTAUDIOBITRATE, OUTPUTSUBTITLECODEC, OUTPUTFASTSTART, OUTPUTQUALITYPERCENT, \
|
||||
NICENESS, MEDIAEXTENSIONS, LOG_DEBUG
|
||||
NICENESS, LOG_DEBUG, FORCE_CLEAN
|
||||
|
||||
if __INITIALIZED__:
|
||||
return False
|
||||
|
@ -190,7 +189,7 @@ def initialize(section=None):
|
|||
sys.exit(-1)
|
||||
|
||||
# load newly migrated config
|
||||
logger.info("Loading config from %s" % CONFIG_FILE)
|
||||
logger.info("Loading config from [%s]" % (CONFIG_FILE))
|
||||
CFG = config()
|
||||
|
||||
# Enable/Disable DEBUG Logging
|
||||
|
@ -200,10 +199,11 @@ def initialize(section=None):
|
|||
NZBTOMEDIA_VERSION = '9.3'
|
||||
VERSION_NOTIFY = int(CFG['General']['version_notify'])
|
||||
AUTO_UPDATE = int(CFG['General']['auto_update'])
|
||||
GIT_REPO = 'nzbToMedia'
|
||||
GIT_PATH = CFG['General']['git_path']
|
||||
GIT_USER = CFG['General']['git_user'] or 'clinton-hall'
|
||||
GIT_BRANCH = CFG['General']['git_branch'] or 'dev'
|
||||
GIT_REPO = 'nzbToMedia'
|
||||
FORCE_CLEAN = CFG["General"]["force_clean"]
|
||||
|
||||
# Check for updates via GitHUB
|
||||
if versionCheck.CheckVersion().check_for_new_version():
|
||||
|
@ -247,11 +247,11 @@ def initialize(section=None):
|
|||
DELUGEPWD = CFG["Torrent"]["DelugePWD"] # mysecretpwr
|
||||
|
||||
COMPRESSEDCONTAINER = (CFG["Extensions"]["compressedExtensions"]) # .zip,.rar,.7z
|
||||
MEDIAEXTENSIONS = [ 'mkv', 'avi', 'divx', 'xvid', 'mov', 'wmv','mp4', 'mpg', 'mpeg', 'iso' ]
|
||||
MEDIACONTAINER = (CFG["Extensions"]["mediaExtensions"]) # .mkv,.avi,.divx
|
||||
METACONTAINER = (CFG["Extensions"]["metaExtensions"]) # .nfo,.sub,.srt
|
||||
MINSAMPLESIZE = int(CFG["Extensions"]["minSampleSize"]) # 200 (in MB)
|
||||
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
||||
|
||||
TRANSCODE = int(CFG["Transcoder"]["transcode"])
|
||||
DUPLICATE = int(CFG["Transcoder"]["duplicate"])
|
||||
IGNOREEXTENSIONS = (CFG["Transcoder"]["ignoreExtensions"])
|
||||
|
@ -267,14 +267,6 @@ def initialize(section=None):
|
|||
OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"])
|
||||
NICENESS = int(CFG["Transcoder"]["niceness"])
|
||||
|
||||
# check for script-defied section and if None set to allow sections
|
||||
SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
||||
if section:
|
||||
SECTIONS = (section,)
|
||||
|
||||
SUBSECTIONS = CFG[SECTIONS]
|
||||
CATEGORIES += SUBSECTIONS.sections
|
||||
|
||||
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"]
|
||||
if not "NONE" in USER_SCRIPT_CATEGORIES:
|
||||
USER_SCRIPT_MEDIAEXTENSIONS = (CFG["UserScript"]["user_script_mediaExtensions"])
|
||||
|
@ -285,6 +277,13 @@ def initialize(section=None):
|
|||
USER_DELAY = int(CFG["UserScript"]["delay"])
|
||||
USER_SCRIPT_RUNONCE = int(CFG["UserScript"]["user_script_runOnce"])
|
||||
|
||||
# check for script-defied section and if None set to allow sections
|
||||
SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
||||
if section:SECTIONS = (section,)
|
||||
|
||||
SUBSECTIONS = CFG[SECTIONS]
|
||||
CATEGORIES += SUBSECTIONS.sections
|
||||
|
||||
__INITIALIZED__ = True
|
||||
return True
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
|||
|
||||
try:
|
||||
inputCategory = list(set(pathlist) & set(categories))[-1] # assume last match is most relevant category.
|
||||
logger.debug("SEARCH: Found Category: %s in directory structure", inputCategory)
|
||||
logger.debug("SEARCH: Found Category: %s in directory structure" % (inputCategory))
|
||||
except IndexError:
|
||||
inputCategory = ""
|
||||
logger.debug("SEARCH: Could not find a category in the directory structure")
|
||||
|
@ -53,17 +53,17 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
|||
logger.info(
|
||||
"SEARCH: Found category directory %s in input directory directory %s" % (inputCategory, inputDirectory))
|
||||
inputDirectory = os.path.join(inputDirectory, inputCategory)
|
||||
logger.info("SEARCH: Setting inputDirectory to %s", inputDirectory)
|
||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
||||
if inputName and os.path.isdir(os.path.join(inputDirectory, inputName)):
|
||||
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (inputName, inputDirectory))
|
||||
inputDirectory = os.path.join(inputDirectory, inputName)
|
||||
logger.info("SEARCH: Setting inputDirectory to %s", inputDirectory)
|
||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
||||
tordir = True
|
||||
if inputName and os.path.isdir(os.path.join(inputDirectory, safeName(inputName))):
|
||||
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (
|
||||
safeName(inputName), inputDirectory))
|
||||
inputDirectory = os.path.join(inputDirectory, safeName(inputName))
|
||||
logger.info("SEARCH: Setting inputDirectory to %s", inputDirectory)
|
||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
||||
tordir = True
|
||||
|
||||
imdbid = [item for item in pathlist if '.cp(tt' in item] # This looks for the .cp(tt imdb id in the path.
|
||||
|
@ -76,14 +76,14 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
|||
index = pathlist.index(inputCategory)
|
||||
if index + 1 < len(pathlist):
|
||||
tordir = True
|
||||
logger.info("SEARCH: Found a unique directory %s in the category directory", pathlist[index + 1])
|
||||
logger.info("SEARCH: Found a unique directory %s in the category directory" % (pathlist[index + 1]))
|
||||
if not inputName: inputName = pathlist[index + 1]
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if inputName and not tordir:
|
||||
if inputName in pathlist or safeName(inputName) in pathlist:
|
||||
logger.info("SEARCH: Found torrent directory %s in the directory structure", inputName)
|
||||
logger.info("SEARCH: Found torrent directory %s in the directory structure" % (inputName))
|
||||
tordir = True
|
||||
else:
|
||||
root = 1
|
||||
|
@ -155,7 +155,7 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination):
|
|||
|
||||
|
||||
def flatten(outputDestination):
|
||||
logger.info("FLATTEN: Flattening directory: %s", outputDestination)
|
||||
logger.info("FLATTEN: Flattening directory: %s" % (outputDestination))
|
||||
for dirpath, dirnames, filenames in os.walk(
|
||||
outputDestination): # Flatten out the directory to make postprocessing easier
|
||||
if dirpath == outputDestination:
|
||||
|
@ -166,12 +166,12 @@ def flatten(outputDestination):
|
|||
try:
|
||||
shutil.move(source, target)
|
||||
except:
|
||||
logger.error("FLATTEN: Could not flatten %s", source)
|
||||
logger.error("FLATTEN: Could not flatten %s" % (source))
|
||||
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
||||
|
||||
|
||||
def removeEmptyFolders(path):
|
||||
logger.info("REMOVER: Removing empty folders in: %s", path)
|
||||
logger.info("REMOVER: Removing empty folders in: %s" % (path))
|
||||
if not os.path.isdir(path):
|
||||
return
|
||||
|
||||
|
@ -186,7 +186,7 @@ def removeEmptyFolders(path):
|
|||
# If folder empty, delete it
|
||||
files = os.listdir(path)
|
||||
if len(files) == 0:
|
||||
logger.debug("REMOVER: Removing empty folder: %s", path)
|
||||
logger.debug("REMOVER: Removing empty folder: %s" % (path))
|
||||
os.rmdir(path)
|
||||
|
||||
|
||||
|
@ -195,7 +195,7 @@ def remove_read_only(path):
|
|||
return
|
||||
for dirpath, dirnames, filenames in os.walk(path):
|
||||
for filename in filenames:
|
||||
logger.debug("Removing Read Only Flag for: %s", filename)
|
||||
logger.debug("Removing Read Only Flag for: %s" % (filename))
|
||||
os.chmod(os.path.join(dirpath, filename), stat.S_IWRITE)
|
||||
|
||||
|
||||
|
@ -234,23 +234,23 @@ def WakeUp():
|
|||
wake = int(nzbtomedia.CFG["WakeOnLan"]["wake"])
|
||||
if wake == 0: # just return if we don't need to wake anything.
|
||||
return
|
||||
logger.info(("Loading WakeOnLan config from %s", nzbtomedia.CONFIG_FILE))
|
||||
logger.info(("Loading WakeOnLan config from %s" % (nzbtomedia.CONFIG_FILE)))
|
||||
host = nzbtomedia.CFG["WakeOnLan"]["host"]
|
||||
port = int(nzbtomedia.CFG["WakeOnLan"]["port"])
|
||||
mac = nzbtomedia.CFG["WakeOnLan"]["mac"]
|
||||
|
||||
i = 1
|
||||
while TestCon(host, port) == "Down" and i < 4:
|
||||
logger.info(("Sending WakeOnLan Magic Packet for mac: %s", mac))
|
||||
logger.info(("Sending WakeOnLan Magic Packet for mac: %s" % (mac)))
|
||||
WakeOnLan(mac)
|
||||
time.sleep(20)
|
||||
i = i + 1
|
||||
|
||||
if TestCon(host, port) == "Down": # final check.
|
||||
logger.warning("System with mac: %s has not woken after 3 attempts. Continuing with the rest of the script.",
|
||||
mac)
|
||||
logger.warning("System with mac: %s has not woken after 3 attempts. Continuing with the rest of the script." % (
|
||||
mac))
|
||||
else:
|
||||
logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac)
|
||||
logger.info("System with mac: %s has been woken. Continuing with the rest of the script." % (mac))
|
||||
|
||||
|
||||
def convert_to_ascii(nzbName, dirName):
|
||||
|
@ -375,7 +375,7 @@ def get_dirnames(section, subsections=None):
|
|||
watch_dir = None
|
||||
|
||||
try:
|
||||
outputDirectory = os.path.join(nzbtomedia.CFG["Torrent"]["outputDirectory"], subsection)
|
||||
outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection)
|
||||
if not os.path.exists(outputDirectory):
|
||||
outputDirectory = None
|
||||
except:
|
||||
|
@ -414,11 +414,11 @@ def get_dirnames(section, subsections=None):
|
|||
|
||||
|
||||
def delete(dirName):
|
||||
logger.info("Deleting %s", dirName)
|
||||
logger.info("Deleting %s" % (dirName))
|
||||
try:
|
||||
shutil.rmtree(dirName, True)
|
||||
except:
|
||||
logger.error("Unable to delete folder %s", dirName)
|
||||
logger.error("Unable to delete folder %s" % (dirName))
|
||||
|
||||
|
||||
def cleanup_directories(inputCategory, processCategories, result, directory):
|
||||
|
@ -433,14 +433,14 @@ def cleanup_directories(inputCategory, processCategories, result, directory):
|
|||
num_files_new += 1
|
||||
file_list.append(file)
|
||||
if num_files_new is 0 or int(nzbtomedia.CFG["General"]["force_clean"]) == 1:
|
||||
logger.info("All files have been processed. Cleaning directory %s", directory)
|
||||
logger.info("All files have been processed. Cleaning directory %s" % (directory))
|
||||
shutil.rmtree(directory)
|
||||
else:
|
||||
logger.info(
|
||||
"Directory %s still contains %s media and/or meta files. This directory will not be removed." % (
|
||||
directory, num_files_new))
|
||||
for item in file_list:
|
||||
logger.debug("media/meta file found: %s", item)
|
||||
logger.debug("media/meta file found: %s" % (item))
|
||||
|
||||
|
||||
def create_torrent_class(clientAgent):
|
||||
|
@ -516,7 +516,7 @@ def resume_torrent(clientAgent, TorrentClass, inputHash, inputID, result, inputN
|
|||
def find_download(clientAgent, download_id):
|
||||
tc = create_torrent_class(clientAgent)
|
||||
|
||||
logger.debug("Searching for Download on %s ...", clientAgent)
|
||||
logger.debug("Searching for Download on %s ..." % (clientAgent))
|
||||
if clientAgent == 'utorrent':
|
||||
torrents = tc.list()[1]['torrents']
|
||||
for torrent in torrents:
|
||||
|
@ -581,7 +581,7 @@ def isMediaFile(filename):
|
|||
if re.search('extras?$', sepFile[0], re.I):
|
||||
return False
|
||||
|
||||
if sepFile[2].lower() in nzbtomedia.MEDIAEXTENSIONS:
|
||||
if sepFile[2].lower() in [i.replace(".","") for i in nzbtomedia.MEDIACONTAINER]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -2,10 +2,11 @@ import os
|
|||
import sys
|
||||
import nzbtomedia
|
||||
import TorrentToMedia
|
||||
from nzbtomedia.nzbToMediaUtil import find_download, clean_nzbname, listMediaFiles
|
||||
from nzbtomedia.nzbToMediaUtil import find_download, isMediaFile
|
||||
|
||||
nzbtomedia.initialize()
|
||||
|
||||
test = isMediaFile('test.mp4')
|
||||
download_id = 'SABnzbd_nzo_qhoQ7m'
|
||||
if find_download('sabnzbd', download_id):
|
||||
print 'found'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue