Skip to content

Commit

Permalink
restore pairwise for older python 3 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Aug 27, 2023
1 parent ccc8242 commit 3a447e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = cleanvid
version = 1.5.2
version = 1.5.3
author = Seth Grover
author_email = [email protected]
description = cleanvid is a little script to mute profanity in video files.
Expand Down
2 changes: 1 addition & 1 deletion src/cleanvid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""cleanvid is a little script to mute profanity in video files."""

__version__ = "1.5.2"
__version__ = "1.5.3"
__author__ = "Seth Grover <[email protected]>"
__all__ = []

Expand Down
12 changes: 9 additions & 3 deletions src/cleanvid/cleanvid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import chardet
import codecs
import errno
import itertools
import json
import os
import shutil
Expand Down Expand Up @@ -34,6 +33,13 @@
PLEX_AUTO_SKIP_DEFAULT_CONFIG = '{"markers":{},"offsets":{},"tags":{},"allowed":{"users":[],"clients":[],"keys":[]},"blocked":{"users":[],"clients":[],"keys":[]},"clients":{},"mode":{}}'


# thanks https://docs.python.org/3/library/itertools.html#recipes
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return zip(a, b)


######## GetFormatAndStreamInfo ###############################################
def GetFormatAndStreamInfo(vidFileSpec):
result = None
Expand Down Expand Up @@ -335,7 +341,7 @@ def CreateCleanSubAndMuteList(self):
# OR if the previous text contained profanity and lies within the pad ...
# then include the subtitle in the new set
prevNaughtySub = None
for sub, subPeek in itertools.pairwise(subs):
for sub, subPeek in pairwise(subs):
newText = replacer.sub(lambda x: self.swearsMap[x.group()], sub.text)
newTextPeek = (
replacer.sub(lambda x: self.swearsMap[x.group()], subPeek.text) if (subPeek is not None) else None
Expand Down Expand Up @@ -422,7 +428,7 @@ def CreateCleanSubAndMuteList(self):
plexDict["markers"][self.plexAutoSkipId] = []
plexDict["mode"][self.plexAutoSkipId] = "volume"

for timePair, timePairPeek in itertools.pairwise(newTimestampPairs):
for timePair, timePairPeek in pairwise(newTimestampPairs):
lineStart = (
(timePair[0].hour * 60.0 * 60.0)
+ (timePair[0].minute * 60.0)
Expand Down

0 comments on commit 3a447e0

Please sign in to comment.