From cb0de3ca988d86abddb3b3d870c9dfc4c8d63ce0 Mon Sep 17 00:00:00 2001 From: Marvin Pinto Date: Mon, 3 Oct 2016 10:23:18 -0400 Subject: [PATCH 1/2] Add the ability to set octal permissions on the processed files prior to handing it off to Sickrage/Couchpotato If set, the `chmodDirectory` option instructs the nzbToMedia post-processing script to set the recursive directory permissions to the octal value specified. --- autoProcessMedia.cfg.spec | 4 ++++ core/autoProcess/autoProcessMovie.py | 6 ++++++ core/autoProcess/autoProcessTV.py | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index f1f47058..02992a4c 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -64,6 +64,8 @@ remote_path = 0 ##### Set to path where download client places completed downloads locally for this category watch_dir = + ##### Set the recursive directory permissions to the following (0 to disable) + chmodDirectory = 0 [SickBeard] #### autoProcessing for TV Series @@ -99,6 +101,8 @@ remote_path = 0 ##### Set to path where download client places completed downloads locally for this category watch_dir = + ##### Set the recursive directory permissions to the following (0 to disable) + chmodDirectory = 0 [NzbDrone] #### autoProcessing for TV Series diff --git a/core/autoProcess/autoProcessMovie.py b/core/autoProcess/autoProcessMovie.py index 7b89e40f..c0a2cd19 100644 --- a/core/autoProcess/autoProcessMovie.py +++ b/core/autoProcess/autoProcessMovie.py @@ -195,6 +195,12 @@ class autoProcessMovie(object): if result == 0: logger.debug("Transcoding succeeded for files in {0}".format(dirName), section) dirName = newDirName + + chmod_directory = int(cfg.get("chmodDirectory", 0), 8) + logger.debug("Config setting 'chmodDirectory' currently set to {0}".format(oct(chmod_directory)), section) + if chmod_directory: + logger.info("Attempting to set the octal permission of '{0}' on directory '{1}'".format(oct(chmod_directory), dirName), section) + core.rchmod(dirName, chmod_directory) else: logger.error("Transcoding failed for files in {0}".format(dirName), section) return [1, "{0}: Failed to post-process - Transcoding failed".format(section)] diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index e72b3ab0..04cd2039 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -163,12 +163,19 @@ class autoProcessTV(object): if result == 0: logger.debug("SUCCESS: Transcoding succeeded for files in {0}".format(dirName), section) dirName = newDirName + + chmod_directory = int(cfg.get("chmodDirectory", 0), 8) + logger.debug("Config setting 'chmodDirectory' currently set to {0}".format(oct(chmod_directory)), section) + if chmod_directory: + logger.info("Attempting to set the octal permission of '{0}' on directory '{1}'".format(oct(chmod_directory), dirName), section) + core.rchmod(dirName, chmod_directory) else: logger.error("FAILED: Transcoding failed for files in {0}".format(dirName), section) return [1, "{0}: Failed to post-process - Transcoding failed".format(section)] # configure SB params to pass fork_params['quiet'] = 1 + fork_params['proc_type'] = 'manual' if inputName is not None: fork_params['nzbName'] = inputName From 2c8b2fc8cf5fed3102ebc64f440fbce927209ea0 Mon Sep 17 00:00:00 2001 From: Marvin Pinto Date: Mon, 3 Oct 2016 10:47:35 -0400 Subject: [PATCH 2/2] Typecast the 'bit_rate' and 'channels' values into floats before attempting to convert them to ints Otherwise we end up in a situation where audio3[0].get("bit_rate", 0) returns the string `"192000.000000"`, which cannot be converted into an int. Example: ``` Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> int("192000.000000") Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '192000.000000' >>> int(float("192000.000000")) 192000 ``` Relevant log entry: ``` [10:50:57] [DEBUG]::TRANSCODER: ******* Specified bit rate is: 192000.000000 Traceback (most recent call last): File "/opt/nzbtomedia/nzbToSickBeard.py", line 254, in result = nzbToMedia.main(sys.argv, section) File "/opt/nzbtomedia/nzbToMedia.py", line 726, in main download_id='') File "/opt/nzbtomedia/nzbToMedia.py", line 615, in process download_id, inputCategory, failureLink) File "/opt/nzbtomedia/core/autoProcess/autoProcessTV.py", line 162, in processEpisode result, newDirName = transcoder.Transcode_directory(dirName) File "/opt/nzbtomedia/core/transcoder/transcoder.py", line 708, in Transcode_directory command = buildCommands(file, newDir, movieName, bitbucket) File "/opt/nzbtomedia/core/transcoder/transcoder.py", line 278, in buildCommands bitrate = int(audio1[0].get("bit_rate", 0)) / 1000 ValueError: invalid literal for int() with base 10: '192000.000000' Exception TypeError: "'NoneType' object is not callable" in > ignored ``` --- core/transcoder/transcoder.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/transcoder/transcoder.py b/core/transcoder/transcoder.py index cdb8b233..2ddaf909 100644 --- a/core/transcoder/transcoder.py +++ b/core/transcoder/transcoder.py @@ -268,20 +268,20 @@ def buildCommands(file, newDir, movieName, bitbucket): if audio2: # right language and codec... map_cmd.extend(['-map', '0:{index}'.format(index=audio2[0]["index"])]) a_mapped.extend([audio2[0]["index"]]) - bitrate = int(audio2[0].get("bit_rate", 0)) / 1000 - channels = int(audio2[0].get("channels", 0)) + bitrate = int(float(audio2[0].get("bit_rate", 0))) / 1000 + channels = int(float(audio2[0].get("channels", 0))) audio_cmd.extend(['-c:a:{0}'.format(used_audio), 'copy']) elif audio1: # right language wrong codec. map_cmd.extend(['-map', '0:{index}'.format(index=audio1[0]["index"])]) a_mapped.extend([audio1[0]["index"]]) - bitrate = int(audio1[0].get("bit_rate", 0)) / 1000 - channels = int(audio1[0].get("channels", 0)) + bitrate = int(float(audio1[0].get("bit_rate", 0))) / 1000 + channels = int(float(audio1[0].get("channels", 0))) audio_cmd.extend(['-c:a:{0}'.format(used_audio), core.ACODEC if core.ACODEC else 'copy']) elif audio3: # just pick the default audio track map_cmd.extend(['-map', '0:{index}'.format(index=audio3[0]["index"])]) a_mapped.extend([audio3[0]["index"]]) - bitrate = int(audio3[0].get("bit_rate", 0)) / 1000 - channels = int(audio3[0].get("channels", 0)) + bitrate = int(float(audio3[0].get("bit_rate", 0))) / 1000 + channels = int(float(audio3[0].get("channels", 0))) audio_cmd.extend(['-c:a:{0}'.format(used_audio), core.ACODEC if core.ACODEC else 'copy']) if core.ACHANNELS and channels and channels > core.ACHANNELS: @@ -305,14 +305,14 @@ def buildCommands(file, newDir, movieName, bitbucket): if audio4: # right language and codec. map_cmd.extend(['-map', '0:{index}'.format(index=audio4[0]["index"])]) a_mapped.extend([audio4[0]["index"]]) - bitrate = int(audio4[0].get("bit_rate", 0)) / 1000 - channels = int(audio4[0].get("channels", 0)) + bitrate = int(float(audio4[0].get("bit_rate", 0))) / 1000 + channels = int(float(audio4[0].get("channels", 0))) audio_cmd2.extend(['-c:a:{0}'.format(used_audio), 'copy']) elif audio1: # right language wrong codec. map_cmd.extend(['-map', '0:{index}'.format(index=audio1[0]["index"])]) a_mapped.extend([audio1[0]["index"]]) - bitrate = int(audio1[0].get("bit_rate", 0)) / 1000 - channels = int(audio1[0].get("channels", 0)) + bitrate = int(float(audio1[0].get("bit_rate", 0))) / 1000 + channels = int(float(audio1[0].get("channels", 0))) if core.ACODEC2: audio_cmd2.extend(['-c:a:{0}'.format(used_audio), core.ACODEC2]) else: @@ -320,8 +320,8 @@ def buildCommands(file, newDir, movieName, bitbucket): elif audio3: # just pick the default audio track map_cmd.extend(['-map', '0:{index}'.format(index=audio3[0]["index"])]) a_mapped.extend([audio3[0]["index"]]) - bitrate = int(audio3[0].get("bit_rate", 0)) / 1000 - channels = int(audio3[0].get("channels", 0)) + bitrate = int(float(audio3[0].get("bit_rate", 0))) / 1000 + channels = int(float(audio3[0].get("channels", 0))) if core.ACODEC2: audio_cmd2.extend(['-c:a:{0}'.format(used_audio), core.ACODEC2]) else: @@ -350,8 +350,8 @@ def buildCommands(file, newDir, movieName, bitbucket): used_audio += 1 map_cmd.extend(['-map', '0:{index}'.format(index=audio["index"])]) audio_cmd3 = [] - bitrate = int(audio.get("bit_rate", 0)) / 1000 - channels = int(audio.get("channels", 0)) + bitrate = int(float(audio.get("bit_rate", 0))) / 1000 + channels = int(float(audio.get("channels", 0))) if audio["codec_name"] in core.ACODEC3_ALLOW: audio_cmd3.extend(['-c:a:{0}'.format(used_audio), 'copy']) else: