change /stats to report extensions
This commit is contained in:
parent
4d74fb74f7
commit
78f681791f
1 changed files with 8 additions and 8 deletions
16
delojza.py
16
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 += "<b>{}:</b> {}\n".format(dir, details)
|
||||
else:
|
||||
reply += "<b>{}:</b> {} files ({})\n".format(dir, len(files), details)
|
||||
|
|
Loading…
Reference in a new issue