def Transcode_directory(dirName): if platform.system() == 'Windows': bitbucket = open('NUL') else: bitbucket = open('/dev/null') if not nzbtomedia.FFMPEG: return 1 logger.info("Checking for files to be transcoded") final_result = 0 # initialize as successful if nzbtomedia.OUTPUTVIDEOPATH: newDir = nzbtomedia.OUTPUTVIDEOPATH makeDir(newDir) else: newDir = dirName for file in nzbtomedia.listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False): if os.path.splitext(file)[1] in nzbtomedia.IGNOREEXTENSIONS: continue command = buildCommands(file, newDir) newfilePath = command[-1] 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) os.remove(newfilePath) except OSError, e: if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist logger.debug("Error when removing transcoding target: %s" % (e)) except Exception, e: logger.debug("Error when removing transcoding target: %s" % (e))
def Transcode_directory(dirName): if not nzbtomedia.FFMPEG: return 1, dirName logger.info("Checking for files to be transcoded") final_result = 0 # initialize as successful if nzbtomedia.OUTPUTVIDEOPATH: newDir = nzbtomedia.OUTPUTVIDEOPATH makeDir(newDir) else: newDir = dirName if platform.system() == 'Windows': bitbucket = open('NUL') else: bitbucket = open('/dev/null') movieName = os.path.splitext(os.path.split(dirName)[1])[0] List = nzbtomedia.listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False) List, remList, newList, success = processList(List, newDir, bitbucket) if not success: bitbucket.close() return 1, dirName for file in List: if isinstance(file, str) and os.path.splitext( file)[1] in nzbtomedia.IGNOREEXTENSIONS: continue command = buildCommands(file, newDir, movieName, bitbucket) newfilePath = command[-1] # transcoding files may remove the original file, so make sure to extract subtitles first if nzbtomedia.SEXTRACT and isinstance(file, str): extract_subs(file, newfilePath, bitbucket) 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) os.remove(newfilePath) except OSError, e: if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist logger.debug("Error when removing transcoding target: %s" % (e)) except Exception, e: logger.debug("Error when removing transcoding target: %s" % (e))
def Transcode_directory(dirName): if not nzbtomedia.FFMPEG: return 1, dirName logger.info("Checking for files to be transcoded") final_result = 0 # initialize as successful if nzbtomedia.OUTPUTVIDEOPATH: newDir = nzbtomedia.OUTPUTVIDEOPATH makeDir(newDir) else: newDir = dirName if platform.system() == 'Windows': bitbucket = open('NUL') else: bitbucket = open('/dev/null') movieName = os.path.splitext(os.path.split(dirName)[1])[0] List = nzbtomedia.listMediaFiles(dirName, media=True, audio=False, meta=False, archives=False) List, remList, newList, success = processList(List, newDir, bitbucket) if not success: bitbucket.close() return 1, dirName for file in List: if isinstance(file, str) and os.path.splitext(file)[1] in nzbtomedia.IGNOREEXTENSIONS: continue command = buildCommands(file, newDir, movieName, bitbucket) newfilePath = command[-1] # transcoding files may remove the original file, so make sure to extract subtitles first if nzbtomedia.SEXTRACT and isinstance(file, str): extract_subs(file, newfilePath, bitbucket) 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) os.remove(newfilePath) except OSError, e: if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist logger.debug("Error when removing transcoding target: %s" % (e)) except Exception, e: logger.debug("Error when removing transcoding target: %s" % (e))
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent): status = 1 # 1 = failed | 0 = success root = 0 foundFile = 0 if clientAgent != 'manual' and not nzbtomedia.DOWNLOADINFO: logger.debug( 'Adding TORRENT download info for directory %s to database' % (inputDirectory)) myDB = nzbToMediaDB.DBConnection() controlValueDict = {"input_directory": unicode(inputDirectory)} newValueDict = { "input_name": unicode(inputName), "input_hash": unicode(inputHash), "input_id": unicode(inputID), "client_agent": unicode(clientAgent), "status": 0, "last_update": datetime.date.today().toordinal() } myDB.upsert("downloads", newValueDict, controlValueDict) logger.debug("Received Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) inputDirectory, inputName, inputCategory, root = nzbtomedia.category_search( inputDirectory, inputName, inputCategory, root, nzbtomedia.CATEGORIES ) # Confirm the category by parsing directory structure logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) # auto-detect section section = nzbtomedia.CFG.findsection(inputCategory).isenabled() if section is None: logger.error( 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for teh appropriate section in your autoProcessMedia.cfg and try again.' % (inputCategory)) return -1 if len(section) > 1: logger.error( 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % (inputCategory, section.keys())) return -1 if section: sectionName = section.keys()[0] logger.info('Auto-detected SECTION:%s' % (sectionName)) else: logger.error( "Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % (inputCategory)) return -1 try: Torrent_NoLink = int(section[inputCategory]["Torrent_NoLink"]) except: Torrent_NoLink = 0 try: extract = int(section[inputCategory]['extract']) except: extract = 0 if not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES: try: nzbtomedia.USER_SCRIPT_MEDIAEXTENSIONS = ( nzbtomedia.CFG[sectionName][inputCategory] ["user_script_mediaExtensions"]) except: nzbtomedia.USER_SCRIPT_MEDIAEXTENSIONS = None try: nzbtomedia.USER_SCRIPT = nzbtomedia.CFG[sectionName][ inputCategory]["user_script_path"] except: nzbtomedia.USER_SCRIPT = None try: nzbtomedia.USER_SCRIPT_PARAM = ( nzbtomedia.CFG[sectionName][inputCategory]["user_script_param"] ) except: nzbtomedia.USER_SCRIPT_PARAM = None try: nzbtomedia.USER_SCRIPT_SUCCESSCODES = ( nzbtomedia.CFG[sectionName][inputCategory] ["user_script_successCodes"]) except: nzbtomedia.USER_SCRIPT_SUCCESSCODES = 0 try: nzbtomedia.USER_SCRIPT_CLEAN = int( nzbtomedia.CFG[sectionName][inputCategory] ["user_script_clean"]) except: nzbtomedia.USER_SCRIPT_CLEAN = 1 try: nzbtomedia.USER_SCRIPT_RUNONCE = int( nzbtomedia.CFG[sectionName][inputCategory] ["user_script_runOnce"]) except: nzbtomedia.USER_SCRIPT_RUNONCE = 1 if clientAgent != 'manual': nzbtomedia.pause_torrent(clientAgent, inputHash, inputID, inputName) processCategories = nzbtomedia.CATEGORIES processOnly = processCategories if inputCategory == "": inputCategory = "UNCAT" outputDestination = os.path.normpath( nzbtomedia.os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory, nzbtomedia.sanitizeName(inputName))) logger.info("Output directory set to: %s" % (outputDestination)) if nzbtomedia.SAFE_MODE and outputDestination == nzbtomedia.TORRENT_DEFAULTDIR: logger.error( 'The output directory:[%s] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting' % (inputDirectory)) return -1 if not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES: # if None, we only process the 5 listed. if "ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES: # All defined categories processOnly = nzbtomedia.CATEGORIES processOnly.extend( nzbtomedia.USER_SCRIPT_CATEGORIES ) # Adds all categories to be processed by userscript. if not inputCategory in processOnly: logger.info("No processing to be done for category: %s. Exiting" % (inputCategory)) return logger.debug("Scanning files in directory: %s" % (inputDirectory)) if sectionName == 'HeadPhones': nzbtomedia.NOFLATTEN.extend( inputCategory ) # Make sure we preserve folder structure for HeadPhones. now = datetime.datetime.now() inputFiles = nzbtomedia.listMediaFiles(inputDirectory) logger.debug("Found %s files in %s" % (str(len(inputFiles)), inputDirectory)) for inputFile in inputFiles: filePath = os.path.dirname(inputFile) fileName, fileExt = os.path.splitext(os.path.basename(inputFile)) if fileExt in nzbtomedia.EXT_REPLACE: fullFileName = fileName + nzbtomedia.EXT_REPLACE[fileExt] else: fullFileName = os.path.basename(inputFile) targetFile = nzbtomedia.os.path.join(outputDestination, fullFileName) if inputCategory in nzbtomedia.NOFLATTEN: if not os.path.basename(filePath) in outputDestination: targetFile = nzbtomedia.os.path.join( nzbtomedia.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName) logger.debug( "Setting outputDestination to %s to preserve folder structure" % (os.path.dirname(targetFile))) if root == 1: if not foundFile: logger.debug("Looking for %s in: %s" % (inputName, inputFile)) if (nzbtomedia.sanitizeName(inputName) in nzbtomedia.sanitizeName(inputFile)) or ( nzbtomedia.sanitizeName(fileName) in nzbtomedia.sanitizeName(inputName)): foundFile = True logger.debug("Found file %s that matches Torrent Name %s" % (fullFileName, inputName)) else: continue if root == 2: mtime_lapse = now - datetime.datetime.fromtimestamp( os.path.getmtime(inputFile)) ctime_lapse = now - datetime.datetime.fromtimestamp( os.path.getctime(inputFile)) if not foundFile: logger.debug( "Looking for files with modified/created dates less than 5 minutes old." ) if (mtime_lapse < datetime.timedelta(minutes=5)) or ( ctime_lapse < datetime.timedelta(minutes=5)): foundFile = True logger.debug( "Found file %s with date modifed/created less than 5 minutes ago." % (fullFileName)) else: continue # This file has not been recently moved or created, skip it if Torrent_NoLink == 0: try: nzbtomedia.copy_link(inputFile, targetFile, nzbtomedia.USELINK) nzbtomedia.rmReadOnly(targetFile) except: logger.error("Failed to link: %s to %s" % (inputFile, targetFile)) if not inputCategory in nzbtomedia.NOFLATTEN: #don't flatten hp in case multi cd albums, and we need to copy this back later. nzbtomedia.flatten(outputDestination) if extract == 1: logger.debug('Checking for archives to extract in directory: %s' % (outputDestination)) nzbtomedia.extractFiles(outputDestination) # Now check if video files exist in destination: if sectionName in ["SickBeard", "NzbDrone", "CouchPotato"]: numVideos = len( nzbtomedia.listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False)) if numVideos > 0: logger.info("Found %s media files in %s" % (numVideos, outputDestination)) status = 0 elif extract != 1: logger.info( "Found no media files in %s. Sending to %s to process" % (outputDestination, sectionName)) status = 0 else: logger.warning("Found no media files in %s" % outputDestination) # Only these sections can handling failed downloads so make sure everything else gets through without the check for failed if not sectionName in ['CouchPotato', 'SickBeard', 'NzbDrone']: status = 0 result = 0 if (inputCategory in nzbtomedia.USER_SCRIPT_CATEGORIES and not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES) or ( "ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES and not inputCategory in processCategories): logger.info("Processing user script %s." % (nzbtomedia.USER_SCRIPT)) result = external_script(outputDestination, inputName, inputCategory) elif status != 0: logger.error("Something failed! Please check logs. Exiting") return status logger.info("Calling %s:%s to post-process:%s" % (sectionName, inputCategory, inputName)) if sectionName == 'CouchPotato': result = nzbtomedia.autoProcessMovie().process(sectionName, outputDestination, inputName, status, clientAgent, inputHash, inputCategory) elif sectionName in ['SickBeard', 'NzbDrone']: result = nzbtomedia.autoProcessTV().processEpisode( sectionName, outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'HeadPhones': result = nzbtomedia.autoProcessMusic().process(sectionName, outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'Mylar': result = nzbtomedia.autoProcessComics().processEpisode( sectionName, outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'Gamez': result = nzbtomedia.autoProcessGames().process(sectionName, outputDestination, inputName, status, clientAgent, inputCategory) if result != 0: if clientAgent != 'manual': logger.error( "A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding" ) nzbtomedia.resume_torrent(clientAgent, inputHash, inputID, inputName) else: if clientAgent != 'manual': # update download status in our DB nzbtomedia.update_downloadInfoStatus(inputName, 1) # remove torrent nzbtomedia.remove_torrent(clientAgent, inputHash, inputID, inputName) # cleanup our processing folders of any misc unwanted files and empty directories nzbtomedia.cleanDir(outputDestination, sectionName, inputCategory) return result
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent): status = 1 # 1 = failed | 0 = success root = 0 foundFile = 0 uniquePath = 1 if clientAgent != 'manual' and not nzbtomedia.DOWNLOADINFO: logger.debug('Adding TORRENT download info for directory %s to database' % (inputDirectory)) myDB = nzbToMediaDB.DBConnection() encoded, inputDirectory1 = CharReplace(inputDirectory) encoded, inputName1 = CharReplace(inputName) controlValueDict = {"input_directory": unicode(inputDirectory1)} newValueDict = {"input_name": unicode(inputName1), "input_hash": unicode(inputHash), "input_id": unicode(inputID), "client_agent": unicode(clientAgent), "status": 0, "last_update": datetime.date.today().toordinal() } myDB.upsert("downloads", newValueDict, controlValueDict) logger.debug("Received Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) inputDirectory, inputName, inputCategory, root = nzbtomedia.category_search(inputDirectory, inputName, inputCategory, root, nzbtomedia.CATEGORIES) # Confirm the category by parsing directory structure if inputCategory == "": inputCategory = "UNCAT" usercat = inputCategory try: inputName = inputName.encode(nzbtomedia.SYS_ENCODING) except: pass try: inputDirectory = inputDirectory.encode(nzbtomedia.SYS_ENCODING) except: pass logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) # auto-detect section section = nzbtomedia.CFG.findsection(inputCategory).isenabled() if section is None: section = nzbtomedia.CFG.findsection("ALL").isenabled() if section is None: logger.error( 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % ( inputCategory)) return [-1, ""] else: usercat = "ALL" if len(section) > 1: logger.error( 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( usercat, section.keys())) return [-1, ""] if section: sectionName = section.keys()[0] logger.info('Auto-detected SECTION:%s' % (sectionName)) else: logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % ( inputCategory)) return [-1, ""] try: Torrent_NoLink = int(section[usercat]["Torrent_NoLink"]) except: Torrent_NoLink = 0 try: extract = int(section[usercat]['extract']) except: extract = 0 try: uniquePath = int(section[usercat]["unique_path"]) except: uniquePath = 1 if clientAgent != 'manual': nzbtomedia.pause_torrent(clientAgent, inputHash, inputID, inputName) if uniquePath: outputDestination = os.path.normpath( nzbtomedia.os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory, nzbtomedia.sanitizeName(inputName))) else: outputDestination = os.path.normpath( nzbtomedia.os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory)) try: outputDestination = outputDestination.encode(nzbtomedia.SYS_ENCODING) except: pass logger.info("Output directory set to: %s" % (outputDestination)) if nzbtomedia.SAFE_MODE and outputDestination == nzbtomedia.TORRENT_DEFAULTDIR: logger.error( 'The output directory:[%s] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting' % ( inputDirectory)) return [-1, ""] logger.debug("Scanning files in directory: %s" % (inputDirectory)) if sectionName == 'HeadPhones': nzbtomedia.NOFLATTEN.extend( inputCategory) # Make sure we preserve folder structure for HeadPhones. now = datetime.datetime.now() inputFiles = nzbtomedia.listMediaFiles(inputDirectory) logger.debug("Found %s files in %s" % (str(len(inputFiles)), inputDirectory)) for inputFile in inputFiles: filePath = os.path.dirname(inputFile) fileName, fileExt = os.path.splitext(os.path.basename(inputFile)) fullFileName = os.path.basename(inputFile) targetFile = nzbtomedia.os.path.join(outputDestination, fullFileName) if inputCategory in nzbtomedia.NOFLATTEN: if not os.path.basename(filePath) in outputDestination: targetFile = nzbtomedia.os.path.join( nzbtomedia.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName) logger.debug( "Setting outputDestination to %s to preserve folder structure" % (os.path.dirname(targetFile))) try: targetFile = targetFile.encode(nzbtomedia.SYS_ENCODING) except: pass if root == 1: if not foundFile: logger.debug("Looking for %s in: %s" % (inputName, inputFile)) if (nzbtomedia.sanitizeName(inputName) in nzbtomedia.sanitizeName(inputFile)) or ( nzbtomedia.sanitizeName(fileName) in nzbtomedia.sanitizeName(inputName)): foundFile = True logger.debug("Found file %s that matches Torrent Name %s" % (fullFileName, inputName)) else: continue if root == 2: mtime_lapse = now - datetime.datetime.fromtimestamp(os.path.getmtime(inputFile)) ctime_lapse = now - datetime.datetime.fromtimestamp(os.path.getctime(inputFile)) if not foundFile: logger.debug("Looking for files with modified/created dates less than 5 minutes old.") if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)): foundFile = True logger.debug("Found file %s with date modifed/created less than 5 minutes ago." % (fullFileName)) else: continue # This file has not been recently moved or created, skip it if Torrent_NoLink == 0: try: nzbtomedia.copy_link(inputFile, targetFile, nzbtomedia.USELINK) nzbtomedia.rmReadOnly(targetFile) except: logger.error("Failed to link: %s to %s" % (inputFile, targetFile)) inputName, outputDestination = convert_to_ascii(inputName, outputDestination) if extract == 1: logger.debug('Checking for archives to extract in directory: %s' % (outputDestination)) nzbtomedia.extractFiles(outputDestination) if not inputCategory in nzbtomedia.NOFLATTEN: #don't flatten hp in case multi cd albums, and we need to copy this back later. nzbtomedia.flatten(outputDestination) # Now check if video files exist in destination: if sectionName in ["SickBeard", "NzbDrone", "CouchPotato"]: numVideos = len( nzbtomedia.listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False)) if numVideos > 0: logger.info("Found %s media files in %s" % (numVideos, outputDestination)) status = 0 elif extract != 1: logger.info("Found no media files in %s. Sending to %s to process" % (outputDestination, sectionName)) status = 0 else: logger.warning("Found no media files in %s" % outputDestination) # Only these sections can handling failed downloads so make sure everything else gets through without the check for failed if not sectionName in ['CouchPotato', 'SickBeard', 'NzbDrone']: status = 0 logger.info("Calling %s:%s to post-process:%s" % (sectionName, usercat, inputName)) result = [ 0, "" ] if sectionName == 'UserScript': result = external_script(outputDestination, inputName, inputCategory, section[usercat]) elif sectionName == 'CouchPotato': result = nzbtomedia.autoProcessMovie().process(sectionName,outputDestination, inputName, status, clientAgent, inputHash, inputCategory) elif sectionName in ['SickBeard','NzbDrone']: result = nzbtomedia.autoProcessTV().processEpisode(sectionName,outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'HeadPhones': result = nzbtomedia.autoProcessMusic().process(sectionName,outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'Mylar': result = nzbtomedia.autoProcessComics().processEpisode(sectionName,outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'Gamez': result = nzbtomedia.autoProcessGames().process(sectionName,outputDestination, inputName, status, clientAgent, inputCategory) if result[0] != 0: if clientAgent != 'manual': logger.error( "A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding") nzbtomedia.resume_torrent(clientAgent, inputHash, inputID, inputName) else: if clientAgent != 'manual': # update download status in our DB nzbtomedia.update_downloadInfoStatus(inputName, 1) # remove torrent nzbtomedia.remove_torrent(clientAgent, inputHash, inputID, inputName) if not sectionName == 'UserScript': # for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN # cleanup our processing folders of any misc unwanted files and empty directories nzbtomedia.cleanDir(outputDestination, sectionName, inputCategory) return result
def Transcode_directory(dirName): if platform.system() == 'Windows': bitbucket = open('NUL') else: bitbucket = open('/dev/null') if not nzbtomedia.FFMPEG: return 1 logger.info("Checking for files to be transcoded") final_result = 0 # initialize as successful for file in nzbtomedia.listMediaFiles(dirName): name, ext = os.path.splitext(file) if ext in [i.replace(".","") for i in nzbtomedia.MEDIACONTAINER]: 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 = [nzbtomedia.FFMPEG, '-loglevel', 'warning', '-i', file, '-map', '0'] # -map 0 takes all input streams if platform.system() != 'Windows': command = ['nice', '-%d' % nzbtomedia.NICENESS] + command if len(nzbtomedia.OUTPUTVIDEOCODEC) > 0: command.append('-c:v') command.append(nzbtomedia.OUTPUTVIDEOCODEC) if nzbtomedia.OUTPUTVIDEOCODEC == 'libx264' and nzbtomedia.OUTPUTVIDEOPRESET: command.append('-pre') 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) os.remove(newfilePath) except OSError, e: if e.errno != errno.ENOENT: # Ignore the error if it's just telling us that the file doesn't exist logger.debug("Error when removing transcoding target: %s" % (e)) except Exception, e: logger.debug("Error when removing transcoding target: %s" % (e))