def test_is_subtitle_filename(self): # negative tests for test in ["/foo/bar.mov", "/foo/bar", "", None]: self.assertEqual(filetypes.is_subtitle_filename(test), False) # positive tests for test in [ "/foo/bar.srt", "/foo/bar.en.srt", "/foo/bar.sub", "/foo/bar.eng.smil", "/foo/bar.cmml", "/foo/bar.ssa", "/foo/bar.ass", ]: self.assertEquals(filetypes.is_subtitle_filename(test), True)
def gather_subtitle_files(movie_path): """Given an absolute path for a video file, this returns a list of filenames of sidecar subtitle file that are in the same directory or in a subtitles directory that are associated with the video file. >>> gather_subtitles_file('/tmp/foo.ogv') [] >>> gather_subtitle_files('/tmp/bar.ogv') ['/tmp/bar.en.srt', '/tmp/bar.fr.srt'] >>> gather_subtitle_files('/tmp/baz.ogv') ['/tmp/subtitles/baz.en.sub', '/tmp/subtitles/baz.fr.sub'] """ check_f(movie_path) subtitle_files = [] if movie_path is None: return subtitle_files dirname, movie_file = os.path.split(movie_path) basename, ext = os.path.splitext(movie_file) # check for files in the current directory if os.path.exists(dirname): possible = [ os.path.join(dirname, mem) for mem in os.listdir(dirname) if mem.startswith(basename) and filetypes.is_subtitle_filename(mem) ] if len(possible) > 0: subtitle_files.extend(possible) # check for files in the subtitles/ directory subdir = os.path.join(dirname, "subtitles") if os.path.exists(subdir): possible = [ os.path.join(subdir, mem) for mem in os.listdir(subdir) if mem.startswith(basename) and filetypes.is_subtitle_filename(mem) ] if len(possible) > 0: subtitle_files.extend(possible) subtitle_files.sort() return subtitle_files
def test_is_subtitle_filename(self): # negative tests for test in ["/foo/bar.mov", "/foo/bar", "", None ]: self.assertEqual(filetypes.is_subtitle_filename(test), False) # positive tests for test in ["/foo/bar.srt", "/foo/bar.en.srt", "/foo/bar.sub", "/foo/bar.eng.smil", "/foo/bar.cmml", "/foo/bar.ssa", "/foo/bar.ass", ]: self.assertEquals(filetypes.is_subtitle_filename(test), True)