Progressbar during parsing of scanned videos no longer shows the filename because it created newline per element. Scanning videos for a given path shows progressbar based on the number of outer folders walked throught
This commit is contained in:
87
src/core.py
87
src/core.py
@@ -111,50 +111,55 @@ def scan_videos(path):
|
|||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
raise ValueError('Path is not a directory')
|
raise ValueError('Path is not a directory')
|
||||||
|
|
||||||
# walk the path
|
# setup progress bar
|
||||||
videos = []
|
with click.progressbar(length=len(os.listdir(path)), label='Searching for videos') as bar:
|
||||||
for dirpath, dirnames, filenames in os.walk(path):
|
|
||||||
logging.debug('Walking directory %r', dirpath)
|
|
||||||
|
|
||||||
# remove badly encoded and hidden dirnames
|
# walk the path
|
||||||
for dirname in list(dirnames):
|
videos = []
|
||||||
if dirname.startswith('.'):
|
for dirpath, dirnames, filenames in os.walk(path):
|
||||||
logging.debug('Skipping hidden dirname %r in %r', dirname, dirpath)
|
logging.debug('Walking directory %r', dirpath)
|
||||||
dirnames.remove(dirname)
|
|
||||||
|
|
||||||
# scan for videos
|
# remove badly encoded and hidden dirnames
|
||||||
for filename in filenames:
|
for dirname in list(dirnames):
|
||||||
# filter on videos and archives
|
if dirname.startswith('.'):
|
||||||
if not (filename.endswith(VIDEO_EXTENSIONS)):
|
logging.debug('Skipping hidden dirname %r in %r', dirname, dirpath)
|
||||||
logging.debug('Skipping non-video file %s', filename)
|
dirnames.remove(dirname)
|
||||||
continue
|
|
||||||
|
|
||||||
# skip hidden files
|
# scan for videos
|
||||||
if filename.startswith('.'):
|
for filename in filenames:
|
||||||
logging.debug('Skipping hidden filename %r in %r', filename, dirpath)
|
# filter on videos and archives
|
||||||
continue
|
if not (filename.endswith(VIDEO_EXTENSIONS)):
|
||||||
|
logging.debug('Skipping non-video file %s', filename)
|
||||||
# reconstruct the file path
|
|
||||||
filepath = os.path.join(dirpath, filename)
|
|
||||||
|
|
||||||
# skip links
|
|
||||||
if os.path.islink(filepath):
|
|
||||||
logging.debug('Skipping link %r in %r', filename, dirpath)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# scan
|
|
||||||
if filename.endswith(VIDEO_EXTENSIONS): # video
|
|
||||||
try:
|
|
||||||
video = scan_video(filepath)
|
|
||||||
except ValueError: # pragma: no cover
|
|
||||||
logging.exception('Error scanning video')
|
|
||||||
continue
|
continue
|
||||||
else: # pragma: no cover
|
|
||||||
raise ValueError('Unsupported file %r' % filename)
|
|
||||||
|
|
||||||
videos.append(video)
|
# skip hidden files
|
||||||
|
if filename.startswith('.'):
|
||||||
|
logging.debug('Skipping hidden filename %r in %r', filename, dirpath)
|
||||||
|
continue
|
||||||
|
|
||||||
return videos
|
# reconstruct the file path
|
||||||
|
filepath = os.path.join(dirpath, filename)
|
||||||
|
|
||||||
|
# skip links
|
||||||
|
if os.path.islink(filepath):
|
||||||
|
logging.debug('Skipping link %r in %r', filename, dirpath)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# scan
|
||||||
|
if filename.endswith(VIDEO_EXTENSIONS): # video
|
||||||
|
try:
|
||||||
|
video = scan_video(filepath)
|
||||||
|
except ValueError: # pragma: no cover
|
||||||
|
logging.exception('Error scanning video')
|
||||||
|
continue
|
||||||
|
else: # pragma: no cover
|
||||||
|
raise ValueError('Unsupported file %r' % filename)
|
||||||
|
|
||||||
|
videos.append(video)
|
||||||
|
|
||||||
|
bar.update(1)
|
||||||
|
|
||||||
|
return videos
|
||||||
|
|
||||||
|
|
||||||
def organize_files(path):
|
def organize_files(path):
|
||||||
@@ -220,10 +225,6 @@ def scan_folder(path):
|
|||||||
errored_paths = []
|
errored_paths = []
|
||||||
logging.debug('Collecting path %s', path)
|
logging.debug('Collecting path %s', path)
|
||||||
|
|
||||||
content_count = 0
|
|
||||||
for _ in os.listdir(path):
|
|
||||||
content_count += 1
|
|
||||||
|
|
||||||
# non-existing
|
# non-existing
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
try:
|
try:
|
||||||
@@ -247,7 +248,7 @@ def scan_folder(path):
|
|||||||
logging.exception('Unexpected error while collecting directory path %s', path)
|
logging.exception('Unexpected error while collecting directory path %s', path)
|
||||||
errored_paths.append(path)
|
errored_paths.append(path)
|
||||||
|
|
||||||
with click.progressbar(scanned_videos, label='Parsing found videos', item_show_function=lambda v: os.path.split(v.name)[1] if v is not None else '') as bar:
|
with click.progressbar(scanned_videos, label='Parsing found videos') as bar:
|
||||||
for v in bar:
|
for v in bar:
|
||||||
v.subtitle_languages |= set(search_external_subtitles(v.name,
|
v.subtitle_languages |= set(search_external_subtitles(v.name,
|
||||||
directory=path).values())
|
directory=path).values())
|
||||||
|
|||||||
Reference in New Issue
Block a user