srtsync icon indicating copy to clipboard operation
srtsync copied to clipboard

Fix source file type detection, argument not iterable error

Open Tarnyko opened this issue 6 years ago • 1 comments

When detecting a .srt file type, we can only rely on the UnicodeDecodeError exception; but this won't work if we allowed a non-Unicode file (with "encoding='latin-1'" e.g.) Work around this by trying video type first.

On Win32, directly using [audio] will produce a "TypeError: argument of type 'WindowsPath' is not iterable" error. Fix this by using [str(audio)].

Signed-off-by: Tarnyko [email protected]

Tarnyko avatar Jan 22 '19 04:01 Tarnyko

Let me explain the patch better:

In some cases, we need to allow a non-Unicode (ISO-8859-1 e.g.) .srt file, because it may be the only format the player recognizes. In this case, we will modify "srt.py", line 13: return pysrt.open(srtfile, encoding='latin-1') but if we do this, the following check won't work anymore:

def is_srt(file):
 ...
 except UnicodeDecodeError:
    return False

as a video (.avi) file will succeed and pass as .srt! pysrt doesn't seem provide a reliable exception. We should probably detect ourselves if it is a text file. I simply work around it by reversing test order.

Tarnyko avatar Jan 22 '19 04:01 Tarnyko