Fixed merge conflict

This commit is contained in:
2018-09-23 20:10:47 +02:00
2 changed files with 24 additions and 14 deletions

View File

@@ -22,7 +22,14 @@ from subtitle import SUBTITLE_EXTENSIONS, Subtitle, get_subtitle_path
from utils import sanitize, refine from utils import sanitize, refine
logging.basicConfig(filename=env.logfile, level=logging.INFO) logging.basicConfig(filename=env.logfile, level=logging.INFO)
logger = logging.getLogger('seasonedParser_core')
fh = logging.FileHandler(env.logfile)
fh.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
def search_external_subtitles(path, directory=None): def search_external_subtitles(path, directory=None):
dirpath, filename = os.path.split(path) dirpath, filename = os.path.split(path)
@@ -40,10 +47,10 @@ def search_external_subtitles(path, directory=None):
try: try:
language = Language.fromietf(language_code) language = Language.fromietf(language_code)
except (ValueError, LanguageReverseError): except (ValueError, LanguageReverseError):
logging.error('Cannot parse language code %r', language_code) logger.error('Cannot parse language code %r', language_code)
subtitles[p] = language subtitles[p] = language
logging.debug('Found subtitles %r', subtitles) logger.debug('Found subtitles %r', subtitles)
return subtitles return subtitles
@@ -64,7 +71,7 @@ def scan_video(path):
raise ValueError('%r is not a valid video extension' % os.path.splitext(path)[1]) raise ValueError('%r is not a valid video extension' % os.path.splitext(path)[1])
dirpath, filename = os.path.split(path) dirpath, filename = os.path.split(path)
logging.info('Scanning video %r in %r', filename, dirpath) logger.info('Scanning video %r in %r', filename, dirpath)
# guess # guess
video = Video.fromguess(path, guessit(path)) video = Video.fromguess(path, guessit(path))
@@ -93,7 +100,7 @@ def scan_subtitle(path):
raise ValueError('Path does not exist') raise ValueError('Path does not exist')
dirpath, filename = os.path.split(path) dirpath, filename = os.path.split(path)
logging.info('Scanning subtitle %r in %r', filename, dirpath) logger.info('Scanning subtitle %r in %r', filename, dirpath)
# guess # guess
parent_path = path.strip(filename) parent_path = path.strip(filename)
@@ -128,30 +135,30 @@ def scan_videos(path):
# walk the path # walk the path
videos = [] videos = []
for dirpath, dirnames, filenames in os.walk(path): for dirpath, dirnames, filenames in os.walk(path):
logging.debug('Walking directory %r', dirpath) logger.debug('Walking directory %r', dirpath)
# remove badly encoded and hidden dirnames # remove badly encoded and hidden dirnames
for dirname in list(dirnames): for dirname in list(dirnames):
if dirname.startswith('.'): if dirname.startswith('.'):
logging.debug('Skipping hidden dirname %r in %r', dirname, dirpath) logger.debug('Skipping hidden dirname %r in %r', dirname, dirpath)
dirnames.remove(dirname) dirnames.remove(dirname)
# scan for videos # scan for videos
for filename in filenames: for filename in filenames:
if not (filename.endswith(VIDEO_EXTENSIONS)): if not (filename.endswith(VIDEO_EXTENSIONS)):
logging.debug('Skipping non-video file %s', filename) logger.debug('Skipping non-video file %s', filename)
continue continue
# skip hidden files # skip hidden files
if filename.startswith('.'): if filename.startswith('.'):
logging.debug('Skipping hidden filename %r in %r', filename, dirpath) logger.debug('Skipping hidden filename %r in %r', filename, dirpath)
continue continue
# reconstruct the file path # reconstruct the file path
filepath = os.path.join(dirpath, filename) filepath = os.path.join(dirpath, filename)
if os.path.islink(filepath): if os.path.islink(filepath):
logging.debug('Skipping link %r in %r', filename, dirpath) logger.debug('Skipping link %r in %r', filename, dirpath)
continue continue
# scan # scan
@@ -159,7 +166,7 @@ def scan_videos(path):
try: try:
video = scan_video(filepath) video = scan_video(filepath)
except ValueError: # pragma: no cover except ValueError: # pragma: no cover
logging.exception('Error scanning video') logger.exception('Error scanning video')
continue continue
else: # pragma: no cover else: # pragma: no cover
raise ValueError('Unsupported file %r' % filename) raise ValueError('Unsupported file %r' % filename)
@@ -232,14 +239,14 @@ def scan_folder(path):
videos = [] videos = []
ignored_videos = [] ignored_videos = []
errored_paths = [] errored_paths = []
logging.debug('Collecting path %s', path) logger.debug('Collecting path %s', path)
# non-existing # non-existing
if not os.path.exists(path): if not os.path.exists(path):
try: try:
video = Video.fromname(path) video = Video.fromname(path)
except: except:
logging.exception('Unexpected error while collecting non-existing path %s', path) logger.exception('Unexpected error while collecting non-existing path %s', path)
errored_paths.append(path) errored_paths.append(path)
video.subtitles |= set(search_external_subtitles(video.name, directory=path)) video.subtitles |= set(search_external_subtitles(video.name, directory=path))
@@ -253,7 +260,7 @@ def scan_folder(path):
try: try:
scanned_videos = scan_videos(path) scanned_videos = scan_videos(path)
except: except:
logging.exception('Unexpected error while collecting directory path %s', path) logger.exception('Unexpected error while collecting directory path %s', path)
errored_paths.append(path) errored_paths.append(path)
# Iterates over our scanned videos # Iterates over our scanned videos

View File

@@ -7,9 +7,12 @@
from guessit import guessit from guessit import guessit
import os import os
import logging
from titlecase import titlecase from titlecase import titlecase
import hashlib, tvdb_api import hashlib, tvdb_api
logger = logging.getLogger('seasonedParser_core')
#: Video extensions #: Video extensions
VIDEO_EXTENSIONS = ('.3g2', '.3gp', '.3gp2', '.3gpp', '.60d', '.ajp', '.asf', '.asx', '.avchd', '.avi', '.bik', VIDEO_EXTENSIONS = ('.3g2', '.3gp', '.3gp2', '.3gpp', '.60d', '.ajp', '.asf', '.asx', '.avchd', '.avi', '.bik',
'.bix', '.box', '.cam', '.dat', '.divx', '.dmf', '.dv', '.dvr-ms', '.evo', '.flc', '.fli', '.bix', '.box', '.cam', '.dat', '.divx', '.dmf', '.dv', '.dvr-ms', '.evo', '.flc', '.fli',
@@ -230,7 +233,7 @@ class Movie(Video):
t = hasattr(self, "title") t = hasattr(self, "title")
y = hasattr(self, "year") y = hasattr(self, "year")
if None in [t, y]: if False in [t, y] or None in [self.title, self.year]:
logger.error('{} or {} found to have none value, manual correction required'.format(self.title, self.year)) logger.error('{} or {} found to have none value, manual correction required'.format(self.title, self.year))
return False return False
if list in [type(self.title), type(self.year)]: if list in [type(self.title), type(self.year)]: