Added progressbar based on iterations of number of files in directory.
This commit is contained in:
82
src/core.py
82
src/core.py
@@ -214,68 +214,48 @@ def save_subtitles(files, single=False, directory=None, encoding=None):
|
||||
print('Moved: %s ---> %s' % (old, newname))
|
||||
os.rename(old, newname)
|
||||
|
||||
print()
|
||||
|
||||
|
||||
# def refine(video, episode_refiners=None, movie_refiners=None, **kwargs):
|
||||
# """Refine a video using :ref:`refiners`.
|
||||
# .. note::
|
||||
# Exceptions raised in refiners are silently passed and logged.
|
||||
# :param video: the video to refine.
|
||||
# :type video: :class:`~subliminal.video.Video`
|
||||
# :param tuple episode_refiners: refiners to use for episodes.
|
||||
# :param tuple movie_refiners: refiners to use for movies.
|
||||
# :param \*\*kwargs: additional parameters for the :func:`~subliminal.refiners.refine` functions.
|
||||
# """
|
||||
# refiners = ()
|
||||
# if isinstance(video, Episode):
|
||||
# refiners = episode_refiners or ('metadata')
|
||||
# elif isinstance(video, Movie):
|
||||
# refiners = movie_refiners or ('metadata')
|
||||
# for refiner in refiners:
|
||||
# logger.info('Refining video with %s', refiner)
|
||||
# try:
|
||||
# print(refiner)
|
||||
# exit(0)
|
||||
# refiner_manager[refiner].plugin(video, **kwargs)
|
||||
# except:
|
||||
# logger.exception('Failed to refine video')
|
||||
|
||||
def scan_folder(path):
|
||||
videos = []
|
||||
ignored_videos = []
|
||||
errored_paths = []
|
||||
logging.debug('Collecting path %s', path)
|
||||
|
||||
# non-existing
|
||||
if not os.path.exists(path):
|
||||
try:
|
||||
video = Video.fromname(path)
|
||||
except:
|
||||
logging.exception('Unexpected error while collecting non-existing path %s', path)
|
||||
errored_paths.append(path)
|
||||
content_count = 0
|
||||
for _ in os.listdir(path):
|
||||
content_count += 1
|
||||
|
||||
video.subtitle_languages |= set(search_external_subtitles(video.name, directory=path).values())
|
||||
|
||||
refine(video)
|
||||
videos.append(video)
|
||||
with click.progressbar(length=content_count, label='Collecting videos') as bar:
|
||||
# non-existing
|
||||
if not os.path.exists(path):
|
||||
try:
|
||||
video = Video.fromname(path)
|
||||
except:
|
||||
logging.exception('Unexpected error while collecting non-existing path %s', path)
|
||||
errored_paths.append(path)
|
||||
|
||||
# directories
|
||||
if os.path.isdir(path):
|
||||
try:
|
||||
scanned_videos = scan_videos(path)
|
||||
except:
|
||||
print('Unexpected error while collecting directory path %s', path)
|
||||
logging.exception('Unexpected error while collecting directory path %s', path)
|
||||
errored_paths.append(path)
|
||||
|
||||
for video in scanned_videos:
|
||||
video.subtitle_languages |= set(search_external_subtitles(video.name,
|
||||
directory=path).values())
|
||||
video.subtitle_languages |= set(search_external_subtitles(video.name, directory=path).values())
|
||||
|
||||
refine(video)
|
||||
videos.append(video)
|
||||
# Increment bar to full ?
|
||||
|
||||
return videos
|
||||
# directories
|
||||
if os.path.isdir(path):
|
||||
try:
|
||||
scanned_videos = scan_videos(path)
|
||||
except:
|
||||
print('Unexpected error while collecting directory path %s', path)
|
||||
logging.exception('Unexpected error while collecting directory path %s', path)
|
||||
errored_paths.append(path)
|
||||
|
||||
for video in scanned_videos:
|
||||
video.subtitle_languages |= set(search_external_subtitles(video.name,
|
||||
directory=path).values())
|
||||
refine(video)
|
||||
videos.append(video)
|
||||
bar.update(1)
|
||||
|
||||
return videos
|
||||
|
||||
def main():
|
||||
path = '/mnt/rescue/'
|
||||
|
||||
Reference in New Issue
Block a user