From 3f9f5d5ef941598ae3213655d571571d0a58d9ce Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Wed, 1 May 2024 21:15:49 -0600 Subject: [PATCH] Added --re-encode-audio option, see #31 --- setup.cfg | 2 +- src/cleanvid/__init__.py | 2 +- src/cleanvid/cleanvid.py | 36 +++++++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/setup.cfg b/setup.cfg index 07e1a6f..fdd242b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = cleanvid -version = 1.5.6 +version = 1.5.7 author = Seth Grover author_email = mero.mero.guero@gmail.com description = cleanvid is a little script to mute profanity in video files. diff --git a/src/cleanvid/__init__.py b/src/cleanvid/__init__.py index 43ab2e0..aa9c8f2 100644 --- a/src/cleanvid/__init__.py +++ b/src/cleanvid/__init__.py @@ -1,6 +1,6 @@ """cleanvid is a little script to mute profanity in video files.""" -__version__ = "1.5.6" +__version__ = "1.5.7" __author__ = "Seth Grover " __all__ = [] diff --git a/src/cleanvid/cleanvid.py b/src/cleanvid/cleanvid.py index 1782b24..3b27c8f 100755 --- a/src/cleanvid/cleanvid.py +++ b/src/cleanvid/cleanvid.py @@ -111,9 +111,11 @@ def ExtractSubtitles(vidFileSpec, srtLanguage): subFileSpec = "" srtLanguage, srtForceIndex = SplitLanguageIfForced(srtLanguage) if (streamInfo := GetStreamSubtitleMap(vidFileSpec)) and ( - stream := next(iter([k for k, v in streamInfo.items() if (v == srtLanguage)]), None) - if not srtForceIndex - else srtForceIndex + stream := ( + next(iter([k for k, v in streamInfo.items() if (v == srtLanguage)]), None) + if not srtForceIndex + else srtForceIndex + ) ): subFileParts = os.path.splitext(vidFileSpec) subFileSpec = subFileParts[0] + "." + srtLanguage + ".srt" @@ -195,7 +197,8 @@ class VidCleaner(object): subsOnly = False edl = False hardCode = False - reEncode = False + reEncodeVideo = False + reEncodeAudio = False unalteredVideo = False subsLang = SUBTITLE_DEFAULT_LANG vParams = VIDEO_DEFAULT_PARAMS @@ -223,7 +226,8 @@ def __init__( edl=False, jsonDump=False, subsLang=SUBTITLE_DEFAULT_LANG, - reEncode=False, + reEncodeVideo=False, + reEncodeAudio=False, hardCode=False, vParams=VIDEO_DEFAULT_PARAMS, aParams=AUDIO_DEFAULT_PARAMS, @@ -262,7 +266,8 @@ def __init__( self.jsonDumpList = [] if jsonDump else None self.plexAutoSkipJson = plexAutoSkipJson self.plexAutoSkipId = plexAutoSkipId - self.reEncode = reEncode + self.reEncodeVideo = reEncodeVideo + self.reEncodeAudio = reEncodeAudio self.hardCode = hardCode self.subsLang = subsLang self.vParams = vParams @@ -496,8 +501,14 @@ def MultiplexCleanVideo(self): # - we are hard-coding (burning) subs # - we are embedding a subtitle stream # - we are not doing "subs only" or EDL mode and there more than zero mute sections - if self.reEncode or self.hardCode or self.embedSubs or ((not self.subsOnly) and (len(self.muteTimeList) > 0)): - if self.reEncode or self.hardCode: + if ( + self.reEncodeVideo + or self.reEncodeAudio + or self.hardCode + or self.embedSubs + or ((not self.subsOnly) and (len(self.muteTimeList) > 0)) + ): + if self.reEncodeVideo or self.hardCode: if self.hardCode and os.path.isfile(self.cleanSubsFileSpec): self.assSubsFileSpec = self.cleanSubsFileSpec + '.ass' subConvCmd = f"ffmpeg -hide_banner -nostats -loglevel error -y -i {self.cleanSubsFileSpec} {self.assSubsFileSpec}" @@ -622,7 +633,8 @@ def RunCleanvid(): dest='json', action='store_true', ) - parser.add_argument('-r', '--re-encode', help='Re-encode video', dest='reEncode', action='store_true') + parser.add_argument('--re-encode-video', help='Re-encode video', dest='reEncodeVideo', action='store_true') + parser.add_argument('--re-encode-audio', help='Re-encode audio', dest='reEncodeAudio', action='store_true') parser.add_argument( '-b', '--burn', help='Hard-coded subtitles (implies re-encode)', dest='hardCode', action='store_true' ) @@ -644,7 +656,8 @@ def RunCleanvid(): fullSubs=False, subsOnly=False, offline=False, - reEncode=False, + reEncodeVideo=False, + reEncodeAudio=False, hardCode=False, edl=False, ) @@ -682,7 +695,8 @@ def RunCleanvid(): args.edl, args.json, lang, - args.reEncode, + args.reEncodeVideo, + args.reEncodeAudio, args.hardCode, args.vParams, args.aParams,