Skip to content

Commit

Permalink
Merge f937b03 into 883a1a6
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandog committed Mar 27, 2018
2 parents 883a1a6 + f937b03 commit 5ccedc8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions subliminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def search_external_subtitles(path, directory=None):
subtitles = {}
for p in os.listdir(directory or dirpath):
# keep only valid subtitle filenames
if not p.startswith(fileroot) or not p.endswith(SUBTITLE_EXTENSIONS):
if not p.startswith(fileroot) or not os.path.splitext(p)[1].lower() in SUBTITLE_EXTENSIONS:
continue

# extract the potential language code
Expand Down Expand Up @@ -420,7 +420,7 @@ def scan_video(path):
raise ValueError('Path does not exist')

# check video extension
if not path.endswith(VIDEO_EXTENSIONS):
if not os.path.splitext(path)[1].lower() in VIDEO_EXTENSIONS:
raise ValueError('%r is not a valid video extension' % os.path.splitext(path)[1])

dirpath, filename = os.path.split(path)
Expand Down Expand Up @@ -468,7 +468,7 @@ def scan_archive(path):
rar = RarFile(path)

# filter on video extensions
rar_filenames = [f for f in rar.namelist() if f.endswith(VIDEO_EXTENSIONS)]
rar_filenames = [f for f in rar.namelist() if os.path.splitext(f)[1].lower() in VIDEO_EXTENSIONS]

# no video found
if not rar_filenames:
Expand Down Expand Up @@ -525,7 +525,8 @@ def scan_videos(path, age=None, archives=True):
# scan for videos
for filename in filenames:
# filter on videos and archives
if not (filename.endswith(VIDEO_EXTENSIONS) or archives and filename.endswith(ARCHIVE_EXTENSIONS)):
if not (os.path.splitext(filename)[1].lower() in VIDEO_EXTENSIONS or
archives and os.path.splitext(filename)[1].lower() in ARCHIVE_EXTENSIONS):
continue

# skip hidden files
Expand Down Expand Up @@ -553,13 +554,13 @@ def scan_videos(path, age=None, archives=True):
continue

# scan
if filename.endswith(VIDEO_EXTENSIONS): # video
if os.path.splitext(filename)[1].lower() in VIDEO_EXTENSIONS: # video
try:
video = scan_video(filepath)
except ValueError: # pragma: no cover
logger.exception('Error scanning video')
continue
elif archives and filename.endswith(ARCHIVE_EXTENSIONS): # archive
elif archives and os.path.splitext(filename)[1].lower() in ARCHIVE_EXTENSIONS: # archive
try:
video = scan_archive(filepath)
except (NotRarFile, RarCannotExec, ValueError): # pragma: no cover
Expand Down

0 comments on commit 5ccedc8

Please sign in to comment.