mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Improved code in Transcoder class.
Video files are now checked for corruption befoer being sent for post-processing by either SickBeard, NzbDrone, or CouchPotato. Added ffmpeg_path option to Transcoder section allowing end-user to set where there ffmpeg is located.
This commit is contained in:
parent
8652d281f6
commit
b8ebf0cb64
6 changed files with 193 additions and 128 deletions
|
@ -9,6 +9,7 @@ import nzbtomedia
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
from nzbtomedia.Transcoder import Transcoder
|
||||||
from nzbtomedia.autoProcess.autoProcessComics import autoProcessComics
|
from nzbtomedia.autoProcess.autoProcessComics import autoProcessComics
|
||||||
from nzbtomedia.autoProcess.autoProcessGames import autoProcessGames
|
from nzbtomedia.autoProcess.autoProcessGames import autoProcessGames
|
||||||
from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
||||||
|
@ -16,7 +17,7 @@ from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||||
from nzbtomedia.extractor import extractor
|
from nzbtomedia.extractor import extractor
|
||||||
from nzbtomedia.nzbToMediaUtil import category_search, sanitizeFileName, is_sample, copy_link, parse_args, flatten, get_dirnames, \
|
from nzbtomedia.nzbToMediaUtil import category_search, sanitizeFileName, is_sample, copy_link, parse_args, flatten, get_dirnames, \
|
||||||
remove_read_only, cleanup_directories, create_torrent_class, pause_torrent, resume_torrent
|
remove_read_only, cleanup_directories, create_torrent_class, pause_torrent, resume_torrent, listMediaFiles
|
||||||
from nzbtomedia import logger
|
from nzbtomedia import logger
|
||||||
|
|
||||||
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
|
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
|
||||||
|
@ -49,8 +50,14 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
if nzbtomedia.CFG["SickBeard"][inputCategory]:
|
if nzbtomedia.CFG["SickBeard"][inputCategory]:
|
||||||
Torrent_NoLink = int(nzbtomedia.CFG["SickBeard"][inputCategory]["Torrent_NoLink"]) # 0
|
Torrent_NoLink = int(nzbtomedia.CFG["SickBeard"][inputCategory]["Torrent_NoLink"]) # 0
|
||||||
if Torrent_NoLink == 1:
|
if Torrent_NoLink == 1:
|
||||||
|
status = 0
|
||||||
|
# Check video files for corruption
|
||||||
|
for video in listMediaFiles(inputDirectory):
|
||||||
|
if not nzbtomedia.FFPROBE and Transcoder().isVideoGood(video):
|
||||||
|
status = 1
|
||||||
|
|
||||||
logger.info("Calling autoProcessTV to post-process: %s",inputName)
|
logger.info("Calling autoProcessTV to post-process: %s",inputName)
|
||||||
result = autoProcessTV().processEpisode(inputDirectory, inputName, 0, clientAgent=clientAgent, inputCategory=inputCategory)
|
result = autoProcessTV().processEpisode(inputDirectory, inputName, status, clientAgent=clientAgent, inputCategory=inputCategory)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
logger.error("A problem was reported in the autoProcessTV script.")
|
logger.error("A problem was reported in the autoProcessTV script.")
|
||||||
|
|
||||||
|
@ -187,10 +194,20 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
|
|
||||||
result = 0
|
result = 0
|
||||||
if nzbtomedia.CFG['CouchPotato'][inputCategory]:
|
if nzbtomedia.CFG['CouchPotato'][inputCategory]:
|
||||||
|
# Check video files for corruption
|
||||||
|
for video in listMediaFiles(inputDirectory):
|
||||||
|
if not nzbtomedia.FFPROBE and Transcoder().isVideoGood(video):
|
||||||
|
status = 1
|
||||||
|
|
||||||
logger.info("Calling CouchPotato:" + inputCategory + " to post-process: %s" % (inputName))
|
logger.info("Calling CouchPotato:" + inputCategory + " to post-process: %s" % (inputName))
|
||||||
download_id = inputHash
|
download_id = inputHash
|
||||||
result = autoProcessMovie().process(outputDestination, inputName, status, clientAgent, download_id, inputCategory)
|
result = autoProcessMovie().process(outputDestination, inputName, status, clientAgent, download_id, inputCategory)
|
||||||
elif nzbtomedia.CFG['SickBeard'][inputCategory]:
|
elif nzbtomedia.CFG['SickBeard'][inputCategory]:
|
||||||
|
# Check video files for corruption
|
||||||
|
for video in listMediaFiles(inputDirectory):
|
||||||
|
if not nzbtomedia.FFPROBE and Transcoder().isVideoGood(video):
|
||||||
|
status = 1
|
||||||
|
|
||||||
logger.info("Calling Sick-Beard:" + inputCategory + " to post-process: %s" % (inputName))
|
logger.info("Calling Sick-Beard:" + inputCategory + " to post-process: %s" % (inputName))
|
||||||
result = autoProcessTV().processEpisode(outputDestination, inputName, status, clientAgent, inputCategory)
|
result = autoProcessTV().processEpisode(outputDestination, inputName, status, clientAgent, inputCategory)
|
||||||
elif nzbtomedia.CFG['NzbDrone'][inputCategory]:
|
elif nzbtomedia.CFG['NzbDrone'][inputCategory]:
|
||||||
|
|
|
@ -169,6 +169,8 @@
|
||||||
|
|
||||||
[Transcoder]
|
[Transcoder]
|
||||||
transcode = 0
|
transcode = 0
|
||||||
|
# Set ffmpeg_path to the location where ffmpeg is located
|
||||||
|
ffmpeg_path =
|
||||||
###### duplicate =1 will cretae a new file. =0 will replace the original
|
###### duplicate =1 will cretae a new file. =0 will replace the original
|
||||||
duplicate = 1
|
duplicate = 1
|
||||||
# Only works on Linux. Highest priority is -20, lowest priority is 19.
|
# Only works on Linux. Highest priority is -20, lowest priority is 19.
|
||||||
|
|
|
@ -276,18 +276,17 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import nzbtomedia
|
import nzbtomedia
|
||||||
|
from nzbtomedia.Transcoder import Transcoder
|
||||||
from nzbtomedia.autoProcess.autoProcessComics import autoProcessComics
|
from nzbtomedia.autoProcess.autoProcessComics import autoProcessComics
|
||||||
from nzbtomedia.autoProcess.autoProcessGames import autoProcessGames
|
from nzbtomedia.autoProcess.autoProcessGames import autoProcessGames
|
||||||
from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
||||||
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||||
from nzbtomedia.nzbToMediaUtil import get_dirnames, cleanup_directories
|
from nzbtomedia.nzbToMediaUtil import get_dirnames, cleanup_directories, listMediaFiles
|
||||||
from nzbtomedia import logger
|
from nzbtomedia import logger
|
||||||
|
|
||||||
# post-processing
|
# post-processing
|
||||||
def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
|
def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
|
||||||
result = 0
|
|
||||||
|
|
||||||
# auto-detect section
|
# auto-detect section
|
||||||
section = nzbtomedia.CFG.findsection(inputCategory)
|
section = nzbtomedia.CFG.findsection(inputCategory)
|
||||||
if section:
|
if section:
|
||||||
|
@ -296,8 +295,16 @@ def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=
|
||||||
logger.error("We could not find a section with containing a download category labeled %s in your autoProcessMedia.cfg, Exiting!" % inputCategory)
|
logger.error("We could not find a section with containing a download category labeled %s in your autoProcessMedia.cfg, Exiting!" % inputCategory)
|
||||||
|
|
||||||
if nzbtomedia.CFG["CouchPotato"][inputCategory]:
|
if nzbtomedia.CFG["CouchPotato"][inputCategory]:
|
||||||
|
# Check video files for corruption
|
||||||
|
for video in listMediaFiles(nzbDir):
|
||||||
|
if not nzbtomedia.FFPROBE and Transcoder().isVideoGood(video):
|
||||||
|
status = 1
|
||||||
result = autoProcessMovie().process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)
|
result = autoProcessMovie().process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)
|
||||||
elif nzbtomedia.CFG["SickBeard", "NzbDrone"][inputCategory]:
|
elif nzbtomedia.CFG["SickBeard", "NzbDrone"][inputCategory]:
|
||||||
|
# Check video files for corruption
|
||||||
|
for video in listMediaFiles(nzbDir):
|
||||||
|
if not nzbtomedia.FFPROBE and Transcoder().isVideoGood(video):
|
||||||
|
status = 1
|
||||||
result = autoProcessTV().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
result = autoProcessTV().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
elif nzbtomedia.CFG["HeadPhones"][inputCategory]:
|
elif nzbtomedia.CFG["HeadPhones"][inputCategory]:
|
||||||
result = autoProcessMusic().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
result = autoProcessMusic().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
|
@ -305,6 +312,8 @@ def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=
|
||||||
result = autoProcessComics().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
result = autoProcessComics().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
elif nzbtomedia.CFG["Gamez"][inputCategory]:
|
elif nzbtomedia.CFG["Gamez"][inputCategory]:
|
||||||
result = autoProcessGames().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
result = autoProcessGames().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
|
else:
|
||||||
|
result = -1
|
||||||
|
|
||||||
if result == 0:
|
if result == 0:
|
||||||
# Clean up any leftover files
|
# Clean up any leftover files
|
||||||
|
|
|
@ -1,121 +1,120 @@
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
import sys
|
import platform
|
||||||
import nzbtomedia
|
import nzbtomedia
|
||||||
from subprocess import call
|
from subprocess import call, Popen
|
||||||
|
from lib import guessit
|
||||||
from nzbtomedia import logger
|
from nzbtomedia import logger
|
||||||
|
from nzbToMediaUtil import listMediaFiles
|
||||||
|
|
||||||
class Transcoder:
|
class Transcoder:
|
||||||
def Transcode_directory(self, dirName):
|
def isVideoGood(self, videofile):
|
||||||
if os.name == 'nt':
|
if platform.system() == 'Windows':
|
||||||
ffmpeg = os.path.join(os.path.dirname(sys.argv[0]), 'ffmpeg\\bin\\ffmpeg.exe') # note, will need to package in this dir.
|
bitbucket = open('NUL')
|
||||||
useNiceness = False
|
|
||||||
if not os.path.isfile(ffmpeg): # problem
|
|
||||||
logger.error("ffmpeg not found. ffmpeg needs to be located at: %s" % (ffmpeg))
|
|
||||||
logger.info("Cannot transcode files in folder %s" % (dirName))
|
|
||||||
return 1 # failure
|
|
||||||
else:
|
else:
|
||||||
if call(['which', 'ffmpeg']) != 0:
|
bitbucket = open('/dev/null')
|
||||||
res = call([os.path.join(os.path.dirname(sys.argv[0]),'getffmpeg.sh')])
|
|
||||||
if res or call(['which', 'ffmpeg']) != 0: # did not install or ffmpeg still not found.
|
|
||||||
logger.error("Failed to install ffmpeg. Please install manually")
|
|
||||||
logger.info("Cannot transcode files in folder %s" % (dirName))
|
|
||||||
return 1 # failure
|
|
||||||
else:
|
|
||||||
ffmpeg = 'ffmpeg'
|
|
||||||
else:
|
|
||||||
ffmpeg = 'ffmpeg'
|
|
||||||
useNiceness = True
|
|
||||||
|
|
||||||
niceness = None
|
command = [nzbtomedia.FFPROBE, videofile]
|
||||||
if useNiceness:niceness = nzbtomedia.NICENESS
|
try:
|
||||||
|
logger.info('Checking if %s has any corruption, please stand by ...' % (videofile))
|
||||||
|
result = call(command, stdout=bitbucket, stderr=bitbucket)
|
||||||
|
except:
|
||||||
|
logger.error("Checking video %s for corruption has failed" % (videofile))
|
||||||
|
return False
|
||||||
|
|
||||||
map(lambda ext: ext.strip(), nzbtomedia.MEDIACONTAINER)
|
if result == 0:
|
||||||
map(lambda ext: ext.strip(), nzbtomedia.IGNOREEXTENSIONS)
|
logger.info("Video %s has no corruption." % (videofile))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.error("Video %s is corrupted!" % (videofile))
|
||||||
|
return False
|
||||||
|
|
||||||
|
def Transcode_directory(self, dirName):
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
bitbucket = open('NUL')
|
||||||
|
else:
|
||||||
|
bitbucket = open('/dev/null')
|
||||||
|
|
||||||
logger.info("Checking for files to be transcoded")
|
logger.info("Checking for files to be transcoded")
|
||||||
final_result = 0 # initialize as successful
|
final_result = 0 # initialize as successful
|
||||||
for dirpath, dirnames, filenames in os.walk(dirName):
|
for file in listMediaFiles(dirName):
|
||||||
for file in filenames:
|
name, ext = os.path.splitext(file)
|
||||||
filePath = os.path.join(dirpath, file)
|
if ext in [i.replace(".","") for i in nzbtomedia.MEDIACONTAINER]:
|
||||||
name, ext = os.path.splitext(filePath)
|
continue
|
||||||
if ext in nzbtomedia.MEDIACONTAINER: # If the file is a video file
|
if ext == nzbtomedia.OUTPUTVIDEOEXTENSION: # we need to change the name to prevent overwriting itself.
|
||||||
if ext in nzbtomedia.IGNOREEXTENSIONS:
|
nzbtomedia.OUTPUTVIDEOEXTENSION = '-transcoded' + nzbtomedia.OUTPUTVIDEOEXTENSION # adds '-transcoded.ext'
|
||||||
logger.info("No need to transcode video type %s" % (ext))
|
|
||||||
continue
|
|
||||||
if ext == nzbtomedia.OUTPUTVIDEOEXTENSION: # we need to change the name to prevent overwriting itself.
|
|
||||||
nzbtomedia.OUTPUTVIDEOEXTENSION = '-transcoded' + nzbtomedia.OUTPUTVIDEOEXTENSION # adds '-transcoded.ext'
|
|
||||||
newfilePath = os.path.normpath(name + nzbtomedia.OUTPUTVIDEOEXTENSION)
|
|
||||||
|
|
||||||
command = [ffmpeg, '-loglevel', 'warning', '-i', filePath, '-map', '0'] # -map 0 takes all input streams
|
newfilePath = os.path.normpath(name + nzbtomedia.OUTPUTVIDEOEXTENSION)
|
||||||
|
|
||||||
if useNiceness:
|
command = [nzbtomedia.FFMPEG, '-loglevel', 'warning', '-i', file, '-map', '0'] # -map 0 takes all input streams
|
||||||
command = ['nice', '-%d' % niceness] + command
|
if platform.system() != 'Windows':
|
||||||
|
|
||||||
if len(nzbtomedia.OUTPUTVIDEOCODEC) > 0:
|
command = ['nice', '-%d' % nzbtomedia.NICENESS] + command
|
||||||
command.append('-c:v')
|
|
||||||
command.append(nzbtomedia.OUTPUTVIDEOCODEC)
|
|
||||||
if nzbtomedia.OUTPUTVIDEOCODEC == 'libx264' and nzbtomedia.OUTPUTVIDEOPRESET:
|
|
||||||
command.append('-preset')
|
|
||||||
command.append(nzbtomedia.OUTPUTVIDEOPRESET)
|
|
||||||
else:
|
|
||||||
command.append('-c:v')
|
|
||||||
command.append('copy')
|
|
||||||
if len(nzbtomedia.OUTPUTVIDEOFRAMERATE) > 0:
|
|
||||||
command.append('-r')
|
|
||||||
command.append(str(nzbtomedia.OUTPUTVIDEOFRAMERATE))
|
|
||||||
if len(nzbtomedia.OUTPUTVIDEOBITRATE) > 0:
|
|
||||||
command.append('-b:v')
|
|
||||||
command.append(str(nzbtomedia.OUTPUTVIDEOBITRATE))
|
|
||||||
if len(nzbtomedia.OUTPUTAUDIOCODEC) > 0:
|
|
||||||
command.append('-c:a')
|
|
||||||
command.append(nzbtomedia.OUTPUTAUDIOCODEC)
|
|
||||||
if nzbtomedia.OUTPUTAUDIOCODEC == 'aac': # Allow users to use the experimental AAC codec that's built into recent versions of ffmpeg
|
|
||||||
command.append('-strict')
|
|
||||||
command.append('-2')
|
|
||||||
else:
|
|
||||||
command.append('-c:a')
|
|
||||||
command.append('copy')
|
|
||||||
if len(nzbtomedia.OUTPUTAUDIOBITRATE) > 0:
|
|
||||||
command.append('-b:a')
|
|
||||||
command.append(str(nzbtomedia.OUTPUTAUDIOBITRATE))
|
|
||||||
if nzbtomedia.OUTPUTFASTSTART > 0:
|
|
||||||
command.append('-movflags')
|
|
||||||
command.append('+faststart')
|
|
||||||
if nzbtomedia.OUTPUTQUALITYPERCENT > 0:
|
|
||||||
command.append('-q:a')
|
|
||||||
command.append(str(nzbtomedia.OUTPUTQUALITYPERCENT))
|
|
||||||
if len(nzbtomedia.OUTPUTSUBTITLECODEC) > 0: # Not every subtitle codec can be used for every video container format!
|
|
||||||
command.append('-c:s')
|
|
||||||
command.append(nzbtomedia.OUTPUTSUBTITLECODEC) # http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options
|
|
||||||
else:
|
|
||||||
command.append('-sn') # Don't copy the subtitles over
|
|
||||||
command.append(newfilePath)
|
|
||||||
|
|
||||||
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
|
if len(nzbtomedia.OUTPUTVIDEOCODEC) > 0:
|
||||||
os.remove(newfilePath)
|
command.append('-c:v')
|
||||||
except OSError, e:
|
command.append(nzbtomedia.OUTPUTVIDEOCODEC)
|
||||||
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
|
if nzbtomedia.OUTPUTVIDEOCODEC == 'libx264' and nzbtomedia.OUTPUTVIDEOPRESET:
|
||||||
logger.debug("Error when removing transcoding target: %s" % (e))
|
command.append('-preset')
|
||||||
except Exception, e:
|
command.append(nzbtomedia.OUTPUTVIDEOPRESET)
|
||||||
logger.debug("Error when removing transcoding target: %s" % (e))
|
else:
|
||||||
|
command.append('-c:v')
|
||||||
|
command.append('copy')
|
||||||
|
if len(nzbtomedia.OUTPUTVIDEOFRAMERATE) > 0:
|
||||||
|
command.append('-r')
|
||||||
|
command.append(str(nzbtomedia.OUTPUTVIDEOFRAMERATE))
|
||||||
|
if len(nzbtomedia.OUTPUTVIDEOBITRATE) > 0:
|
||||||
|
command.append('-b:v')
|
||||||
|
command.append(str(nzbtomedia.OUTPUTVIDEOBITRATE))
|
||||||
|
if len(nzbtomedia.OUTPUTAUDIOCODEC) > 0:
|
||||||
|
command.append('-c:a')
|
||||||
|
command.append(nzbtomedia.OUTPUTAUDIOCODEC)
|
||||||
|
if nzbtomedia.OUTPUTAUDIOCODEC == 'aac': # Allow users to use the experimental AAC codec that's built into recent versions of ffmpeg
|
||||||
|
command.append('-strict')
|
||||||
|
command.append('-2')
|
||||||
|
else:
|
||||||
|
command.append('-c:a')
|
||||||
|
command.append('copy')
|
||||||
|
if len(nzbtomedia.OUTPUTAUDIOBITRATE) > 0:
|
||||||
|
command.append('-b:a')
|
||||||
|
command.append(str(nzbtomedia.OUTPUTAUDIOBITRATE))
|
||||||
|
if nzbtomedia.OUTPUTFASTSTART > 0:
|
||||||
|
command.append('-movflags')
|
||||||
|
command.append('+faststart')
|
||||||
|
if nzbtomedia.OUTPUTQUALITYPERCENT > 0:
|
||||||
|
command.append('-q:a')
|
||||||
|
command.append(str(nzbtomedia.OUTPUTQUALITYPERCENT))
|
||||||
|
if len(nzbtomedia.OUTPUTSUBTITLECODEC) > 0: # Not every subtitle codec can be used for every video container format!
|
||||||
|
command.append('-c:s')
|
||||||
|
command.append(nzbtomedia.OUTPUTSUBTITLECODEC) # http://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/subtitle_options
|
||||||
|
else:
|
||||||
|
command.append('-sn') # Don't copy the subtitles over
|
||||||
|
command.append(newfilePath)
|
||||||
|
|
||||||
logger.info("Transcoding video: %s" % (file))
|
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
|
||||||
cmd = ""
|
os.remove(newfilePath)
|
||||||
for item in command:
|
except OSError, e:
|
||||||
cmd = cmd + " " + item
|
if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist
|
||||||
logger.debug("calling command:%s" % (cmd))
|
logger.debug("Error when removing transcoding target: %s" % (e))
|
||||||
result = 1 # set result to failed in case call fails.
|
except Exception, e:
|
||||||
try:
|
logger.debug("Error when removing transcoding target: %s" % (e))
|
||||||
result = call(command)
|
|
||||||
except:
|
logger.info("Transcoding video: %s" % (file))
|
||||||
logger.error("Transcoding of video %s has failed" % (filePath))
|
cmd = ""
|
||||||
if result == 0:
|
for item in command:
|
||||||
logger.info("Transcoding of video %s to %s succeeded" % (filePath, newfilePath))
|
cmd = cmd + " " + item
|
||||||
if nzbtomedia.DUPLICATE == 0: # we get rid of the original file
|
logger.debug("calling command:%s" % (cmd))
|
||||||
os.unlink(filePath)
|
result = 1 # set result to failed in case call fails.
|
||||||
else:
|
try:
|
||||||
logger.error("Transcoding of video %s to %s failed" % (filePath, newfilePath))
|
result = call(command, stdout=bitbucket, stderr=bitbucket)
|
||||||
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
|
except:
|
||||||
final_result = final_result + result
|
logger.error("Transcoding of video %s has failed" % (file))
|
||||||
|
if result == 0:
|
||||||
|
logger.info("Transcoding of video %s to %s succeeded" % (file, newfilePath))
|
||||||
|
if nzbtomedia.DUPLICATE == 0: # we get rid of the original file
|
||||||
|
os.unlink(file)
|
||||||
|
else:
|
||||||
|
logger.error("Transcoding of video %s to %s failed" % (file, newfilePath))
|
||||||
|
# this will be 0 (successful) it all are successful, else will return a positive integer for failure.
|
||||||
|
final_result = final_result + result
|
||||||
return final_result
|
return final_result
|
||||||
|
|
|
@ -94,6 +94,7 @@ SECTIONS = []
|
||||||
SUBSECTIONS = {}
|
SUBSECTIONS = {}
|
||||||
|
|
||||||
TRANSCODE = None
|
TRANSCODE = None
|
||||||
|
FFMPEG_PATH = None
|
||||||
DUPLICATE = None
|
DUPLICATE = None
|
||||||
IGNOREEXTENSIONS = None
|
IGNOREEXTENSIONS = None
|
||||||
OUTPUTVIDEOEXTENSION = None
|
OUTPUTVIDEOEXTENSION = None
|
||||||
|
@ -106,6 +107,8 @@ OUTPUTAUDIOBITRATE = None
|
||||||
OUTPUTSUBTITLECODEC = None
|
OUTPUTSUBTITLECODEC = None
|
||||||
OUTPUTFASTSTART = None
|
OUTPUTFASTSTART = None
|
||||||
OUTPUTQUALITYPERCENT = None
|
OUTPUTQUALITYPERCENT = None
|
||||||
|
FFMPEG = None
|
||||||
|
FFPROBE = None
|
||||||
NICENESS = None
|
NICENESS = None
|
||||||
|
|
||||||
USER_SCRIPT_CATEGORIES = None
|
USER_SCRIPT_CATEGORIES = None
|
||||||
|
@ -132,7 +135,7 @@ def initialize(section=None):
|
||||||
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
|
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
|
||||||
DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, \
|
DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, \
|
||||||
OUTPUTVIDEOBITRATE, OUTPUTAUDIOCODEC, OUTPUTAUDIOBITRATE, OUTPUTSUBTITLECODEC, OUTPUTFASTSTART, OUTPUTQUALITYPERCENT, \
|
OUTPUTVIDEOBITRATE, OUTPUTAUDIOCODEC, OUTPUTAUDIOBITRATE, OUTPUTSUBTITLECODEC, OUTPUTFASTSTART, OUTPUTQUALITYPERCENT, \
|
||||||
NICENESS, LOG_DEBUG, FORCE_CLEAN
|
NICENESS, LOG_DEBUG, FORCE_CLEAN, FFMPEG_PATH, FFMPEG, FFPROBE
|
||||||
|
|
||||||
if __INITIALIZED__:
|
if __INITIALIZED__:
|
||||||
return False
|
return False
|
||||||
|
@ -242,6 +245,7 @@ def initialize(section=None):
|
||||||
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
||||||
|
|
||||||
TRANSCODE = int(CFG["Transcoder"]["transcode"])
|
TRANSCODE = int(CFG["Transcoder"]["transcode"])
|
||||||
|
FFMPEG_PATH = CFG["Transcoder"]["ffmpeg_path"]
|
||||||
DUPLICATE = int(CFG["Transcoder"]["duplicate"])
|
DUPLICATE = int(CFG["Transcoder"]["duplicate"])
|
||||||
IGNOREEXTENSIONS = (CFG["Transcoder"]["ignoreExtensions"])
|
IGNOREEXTENSIONS = (CFG["Transcoder"]["ignoreExtensions"])
|
||||||
OUTPUTVIDEOEXTENSION = CFG["Transcoder"]["outputVideoExtension"].strip()
|
OUTPUTVIDEOEXTENSION = CFG["Transcoder"]["outputVideoExtension"].strip()
|
||||||
|
@ -256,6 +260,40 @@ def initialize(section=None):
|
||||||
OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"])
|
OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"])
|
||||||
NICENESS = int(CFG["Transcoder"]["niceness"])
|
NICENESS = int(CFG["Transcoder"]["niceness"])
|
||||||
|
|
||||||
|
# Setup FFMPEG and FFPROBE locations
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg.exe')
|
||||||
|
FFPROBE = os.path.join(FFMPEG_PATH, 'ffprobe.exe')
|
||||||
|
if TRANSCODE and not os.path.isfile(FFMPEG): # problem
|
||||||
|
logger.error("%s not found, insure that it does exist and that you've set the correct ffmpeg_path in your autoProcessMedia.cfg" % FFMPEG)
|
||||||
|
logger.error("Cannot transcode files, disabling transcoding!")
|
||||||
|
TRANSCODE = 0
|
||||||
|
FFMPEG = None
|
||||||
|
|
||||||
|
if not os.path.isfile(FFPROBE): # problem
|
||||||
|
logger.error(
|
||||||
|
"%s not found, insure that it does exist and that you've set the correct ffmpeg_path in your autoProcessMedia.cfg" % FFPROBE)
|
||||||
|
logger.error("Cannot detect corrupt video files, disabling!")
|
||||||
|
FFPROBE = None
|
||||||
|
|
||||||
|
else:
|
||||||
|
FFMPEG = 'ffmpeg'
|
||||||
|
FFPROBE = 'ffprobe'
|
||||||
|
if subprocess.call(['which', 'ffmpeg']) != 0:
|
||||||
|
res = subprocess.call([os.path.join(PROGRAM_DIR, 'getffmpeg.sh')])
|
||||||
|
if res or subprocess.call(['which', 'ffmpeg']) != 0: # did not install or ffmpeg still not found.
|
||||||
|
logger.error("Failed to install ffmpeg. Please install manually")
|
||||||
|
logger.info("Cannot transcode video files, disabling transcoding!")
|
||||||
|
TRANSCODE = 0
|
||||||
|
FFMPEG = None
|
||||||
|
|
||||||
|
if subprocess.call(['which', 'ffprobe']) != 0:
|
||||||
|
res = subprocess.call([os.path.join(PROGRAM_DIR, 'getffmpeg.sh')])
|
||||||
|
if res or subprocess.call(['which', 'ffprobe']) != 0:
|
||||||
|
logger.error("Failed to install ffprobe. Please install manually")
|
||||||
|
logger.info("Cannot detect corrupt video files, disabling corrupt video detection!")
|
||||||
|
FFPROBE = None
|
||||||
|
|
||||||
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"]
|
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"]
|
||||||
if not "NONE" in USER_SCRIPT_CATEGORIES:
|
if not "NONE" in USER_SCRIPT_CATEGORIES:
|
||||||
USER_SCRIPT_MEDIAEXTENSIONS = (CFG["UserScript"]["user_script_mediaExtensions"])
|
USER_SCRIPT_MEDIAEXTENSIONS = (CFG["UserScript"]["user_script_mediaExtensions"])
|
||||||
|
|
|
@ -67,20 +67,20 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
|
||||||
if not inputName: inputName = os.path.split(os.path.normpath(inputDirectory))[1]
|
if not inputName: inputName = os.path.split(os.path.normpath(inputDirectory))[1]
|
||||||
return inputDirectory, inputName, inputCategory, root, single
|
return inputDirectory, inputName, inputCategory, root, single
|
||||||
|
|
||||||
if inputCategory and os.path.isdir(os.path.join(inputDirectory, inputCategory)):
|
if inputCategory and os.path.isdir(os.path.join(inputDirectory, inputCategory).replace("\\","/")):
|
||||||
logger.info(
|
logger.info(
|
||||||
"SEARCH: Found category directory %s in input directory directory %s" % (inputCategory, inputDirectory))
|
"SEARCH: Found category directory %s in input directory directory %s" % (inputCategory, inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, inputCategory)
|
inputDirectory = os.path.join(inputDirectory, inputCategory).replace("\\","/")
|
||||||
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)):
|
if inputName and os.path.isdir(os.path.join(inputDirectory, inputName).replace("\\","/")):
|
||||||
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (inputName, inputDirectory))
|
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (inputName, inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, inputName)
|
inputDirectory = os.path.join(inputDirectory, inputName).replace("\\","/")
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
||||||
tordir = True
|
tordir = True
|
||||||
if inputName and os.path.isdir(os.path.join(inputDirectory, sanitizeFileName(inputName))):
|
if inputName and os.path.isdir(os.path.join(inputDirectory, sanitizeFileName(inputName)).replace("\\","/")):
|
||||||
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (
|
logger.info("SEARCH: Found torrent directory %s in input directory directory %s" % (
|
||||||
sanitizeFileName(inputName), inputDirectory))
|
sanitizeFileName(inputName), inputDirectory))
|
||||||
inputDirectory = os.path.join(inputDirectory, sanitizeFileName(inputName))
|
inputDirectory = os.path.join(inputDirectory, sanitizeFileName(inputName).replace("\\","/"))
|
||||||
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
logger.info("SEARCH: Setting inputDirectory to %s" % (inputDirectory))
|
||||||
tordir = True
|
tordir = True
|
||||||
|
|
||||||
|
@ -179,8 +179,8 @@ def flatten(outputDestination):
|
||||||
if dirpath == outputDestination:
|
if dirpath == outputDestination:
|
||||||
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
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
source = os.path.join(dirpath, filename)
|
source = os.path.join(dirpath, filename).replace("\\","/")
|
||||||
target = os.path.join(outputDestination, filename)
|
target = os.path.join(outputDestination, filename).replace("\\","/")
|
||||||
try:
|
try:
|
||||||
shutil.move(source, target)
|
shutil.move(source, target)
|
||||||
except:
|
except:
|
||||||
|
@ -197,7 +197,7 @@ def removeEmptyFolders(path):
|
||||||
files = os.listdir(path)
|
files = os.listdir(path)
|
||||||
if len(files):
|
if len(files):
|
||||||
for f in files:
|
for f in files:
|
||||||
fullpath = os.path.join(path, f)
|
fullpath = os.path.join(path, f).replace("\\","/")
|
||||||
if os.path.isdir(fullpath):
|
if os.path.isdir(fullpath):
|
||||||
removeEmptyFolders(fullpath)
|
removeEmptyFolders(fullpath)
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ def remove_read_only(path):
|
||||||
for dirpath, dirnames, filenames in os.walk(path):
|
for dirpath, dirnames, filenames in os.walk(path):
|
||||||
for filename in filenames:
|
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)
|
os.chmod(os.path.join(dirpath, filename).replace("\\","/"), stat.S_IWRITE)
|
||||||
|
|
||||||
|
|
||||||
#Wake function
|
#Wake function
|
||||||
|
@ -389,7 +389,7 @@ def get_dirnames(section, subsections=None):
|
||||||
watch_dir = None
|
watch_dir = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection)
|
outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection).replace("\\","/")
|
||||||
if not os.path.exists(outputDirectory):
|
if not os.path.exists(outputDirectory):
|
||||||
outputDirectory = None
|
outputDirectory = None
|
||||||
except:
|
except:
|
||||||
|
@ -400,26 +400,26 @@ def get_dirnames(section, subsections=None):
|
||||||
for mediafile in listMediaFiles(watch_dir):
|
for mediafile in listMediaFiles(watch_dir):
|
||||||
parentDir = os.path.dirname(mediafile)
|
parentDir = os.path.dirname(mediafile)
|
||||||
if parentDir == watch_dir:
|
if parentDir == watch_dir:
|
||||||
p = os.path.join(parentDir, (os.path.splitext(os.path.splitext(mediafile)[0])[0]))
|
p = os.path.join(parentDir, (os.path.splitext(os.path.splitext(mediafile)[0])[0])).replace("\\","/")
|
||||||
if not os.path.exists(p):
|
if not os.path.exists(p):
|
||||||
os.mkdir(p)
|
os.mkdir(p)
|
||||||
shutil.move(mediafile, p)
|
shutil.move(mediafile, p)
|
||||||
|
|
||||||
dirNames.extend([os.path.join(watch_dir, o) for o in os.listdir(watch_dir) if
|
dirNames.extend([os.path.join(watch_dir, o).replace("\\","/") for o in os.listdir(watch_dir) if
|
||||||
os.path.isdir(os.path.join(watch_dir, o))])
|
os.path.isdir(os.path.join(watch_dir, o).replace("\\","/"))])
|
||||||
|
|
||||||
if outputDirectory:
|
if outputDirectory:
|
||||||
# search for single files and move them into there own folder for post-processing
|
# search for single files and move them into there own folder for post-processing
|
||||||
for mediafile in listMediaFiles(outputDirectory):
|
for mediafile in listMediaFiles(outputDirectory):
|
||||||
parentDir = os.path.dirname(mediafile)
|
parentDir = os.path.dirname(mediafile)
|
||||||
if parentDir == outputDirectory:
|
if parentDir == outputDirectory:
|
||||||
p = os.path.join(parentDir, (os.path.splitext(os.path.splitext(mediafile)[0])[0]))
|
p = os.path.join(parentDir, (os.path.splitext(os.path.splitext(mediafile)[0])[0]).replace("\\","/"))
|
||||||
if not os.path.exists(p):
|
if not os.path.exists(p):
|
||||||
os.mkdir(p)
|
os.mkdir(p)
|
||||||
shutil.move(mediafile, p)
|
shutil.move(mediafile, p)
|
||||||
|
|
||||||
dirNames.extend([os.path.join(outputDirectory, o) for o in os.listdir(outputDirectory) if
|
dirNames.extend([os.path.join(outputDirectory, o).replace("\\","/") for o in os.listdir(outputDirectory) if
|
||||||
os.path.isdir(os.path.join(outputDirectory, o))])
|
os.path.isdir(os.path.join(outputDirectory, o).replace("\\","/"))])
|
||||||
|
|
||||||
if not dirNames:
|
if not dirNames:
|
||||||
logger.warning("%s:%s has no directories identified for post-processing" % (section, subsection))
|
logger.warning("%s:%s has no directories identified for post-processing" % (section, subsection))
|
||||||
|
@ -441,7 +441,7 @@ def cleanup_directories(inputCategory, processCategories, result, directory):
|
||||||
file_list = []
|
file_list = []
|
||||||
for dirpath, dirnames, filenames in os.walk(directory):
|
for dirpath, dirnames, filenames in os.walk(directory):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
filePath = os.path.join(dirpath, file)
|
filePath = os.path.join(dirpath, file).replace("\\","/")
|
||||||
fileName, fileExtension = os.path.splitext(file)
|
fileName, fileExtension = os.path.splitext(file)
|
||||||
if fileExtension in nzbtomedia.MEDIACONTAINER or fileExtension in nzbtomedia.METACONTAINER:
|
if fileExtension in nzbtomedia.MEDIACONTAINER or fileExtension in nzbtomedia.METACONTAINER:
|
||||||
num_files_new += 1
|
num_files_new += 1
|
||||||
|
@ -607,7 +607,7 @@ def listMediaFiles(path):
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
for curFile in os.listdir(path):
|
for curFile in os.listdir(path):
|
||||||
fullCurFile = os.path.join(path, curFile)
|
fullCurFile = os.path.join(path, curFile).replace("\\","/")
|
||||||
|
|
||||||
# if it's a folder do it recursively
|
# if it's a folder do it recursively
|
||||||
if os.path.isdir(fullCurFile) and not curFile.startswith('.') and not curFile == 'Extras':
|
if os.path.isdir(fullCurFile) and not curFile.startswith('.') and not curFile == 'Extras':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue