Because we read subtitles from mkv containers a check for if subtitle file exists was added so not to try move a sub file within a mkv container.

This commit is contained in:
2018-09-23 22:38:26 +02:00
parent 03902eeecb
commit 66f7ea3e24

View File

@@ -9,6 +9,7 @@ from guessit import guessit
from babelfish import Language, LanguageReverseError from babelfish import Language, LanguageReverseError
import hashlib import hashlib
import os, errno import os, errno
import shutil
import logging import logging
import re import re
import tvdb_api import tvdb_api
@@ -60,7 +61,7 @@ def search_external_subtitles(path, directory=None):
language = langdetect.detect(filecontent) language = langdetect.detect(filecontent)
f.close() f.close()
subtitles[p] = language subtitles[os.path.join(dirpath, p)] = language
logger.debug('Found subtitles %r', subtitles) logger.debug('Found subtitles %r', subtitles)
return subtitles return subtitles
@@ -122,7 +123,7 @@ def scan_subtitle(path):
def subtitle_path(sibling, subtitle): def subtitle_path(sibling, subtitle):
parent_path = os.path.dirname(sibling) parent_path = os.path.dirname(sibling)
return os.path.join(parent_path, subtitle) return os.path.join(parent_path, os.path.basename(subtitle))
def scan_videos(path): def scan_videos(path):
"""Scan `path` for videos and their subtitles. """Scan `path` for videos and their subtitles.
@@ -311,9 +312,12 @@ def moveHome(video):
logger.info("Moving video file from: '{}' to: '{}'".format(video.name, video.home)) logger.info("Moving video file from: '{}' to: '{}'".format(video.name, video.home))
shutil.move(video.name, video.home) shutil.move(video.name, video.home)
for sub in video.subtitles: for sub in video.subtitles:
sub_home = subtitle_path(sub) if not os.path.isfile(sub):
logger.info("Moving subtitle file from: '{}' to: '{}'".format(sub, sub_home)) continue
shutil.move(sub, sub_home) oldpath = sub
newpath = subtitle_path(video.home, sub)
logger.info("Moving subtitle file from: '{}' to: '{}'".format(oldpath, newpath))
shutil.move(oldpath, newpath)
def main(): def main():
path = '/mnt/mainframe/' path = '/mnt/mainframe/'