diff --git a/delojza.py b/delojza.py index 7c534c9..4515e38 100755 --- a/delojza.py +++ b/delojza.py @@ -279,15 +279,15 @@ class DelojzaBot: break abs_paths = [os.path.join(self.out_dir, dir, file) for file in files] abs_files = list(filter(os.path.isfile, abs_paths)) - audio_cnt = len([match for match in map(filetype.audio, abs_files) if match is not None]) - video_cnt = len([match for match in map(filetype.video, abs_files) if match is not None]) - image_cnt = len([match for match in map(filetype.image, abs_files) if match is not None]) - rest_cnt = len(files) - audio_cnt - video_cnt - image_cnt + # mimes = [magic.from_file(path, mime=True).split("/")[0] for path in abs_files] + # mime_counts = [(mime, mimes.count(mime)) for mime in set(mimes)] + exts = [ext[1:] for ext in [os.path.splitext(path)[1] for path in abs_files] if len(ext) > 0] + ext_counts = [(ext, exts.count(ext)) for ext in set(exts)] dir_cnt = len(abs_paths) - len(abs_files) - details = ", ".join(["{} {}".format(cnt, desc) for cnt, desc in - [(image_cnt, "images"), (video_cnt, "videos"), (audio_cnt, "audios"), - (rest_cnt, "unknown files"), (dir_cnt, "directories")] if cnt > 0]) - if any([len(abs_paths) == cnt for cnt in [audio_cnt, video_cnt, image_cnt, rest_cnt, dir_cnt]]): + type_counts = ext_counts + ([("directorie", dir_cnt)] if dir_cnt > 0 else []) + details = ", ".join(["{} {}s".format(cnt, mime) for mime, cnt in + sorted(type_counts, key=itemgetter(1), reverse=True)]) + if len(type_counts) == 1: reply += "{}: {}\n".format(dir, details) else: reply += "{}: {} files ({})\n".format(dir, len(files), details)