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
|
break
|
||||||
abs_paths = [os.path.join(self.out_dir, dir, file) for file in files]
|
abs_paths = [os.path.join(self.out_dir, dir, file) for file in files]
|
||||||
abs_files = list(filter(os.path.isfile, abs_paths))
|
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])
|
# mimes = [magic.from_file(path, mime=True).split("/")[0] for path in abs_files]
|
||||||
video_cnt = len([match for match in map(filetype.video, abs_files) if match is not None])
|
# mime_counts = [(mime, mimes.count(mime)) for mime in set(mimes)]
|
||||||
image_cnt = len([match for match in map(filetype.image, abs_files) if match is not None])
|
exts = [ext[1:] for ext in [os.path.splitext(path)[1] for path in abs_files] if len(ext) > 0]
|
||||||
rest_cnt = len(files) - audio_cnt - video_cnt - image_cnt
|
ext_counts = [(ext, exts.count(ext)) for ext in set(exts)]
|
||||||
dir_cnt = len(abs_paths) - len(abs_files)
|
dir_cnt = len(abs_paths) - len(abs_files)
|
||||||
details = ", ".join(["{} {}".format(cnt, desc) for cnt, desc in
|
type_counts = ext_counts + ([("directorie", dir_cnt)] if dir_cnt > 0 else [])
|
||||||
[(image_cnt, "images"), (video_cnt, "videos"), (audio_cnt, "audios"),
|
details = ", ".join(["{} {}s".format(cnt, mime) for mime, cnt in
|
||||||
(rest_cnt, "unknown files"), (dir_cnt, "directories")] if cnt > 0])
|
sorted(type_counts, key=itemgetter(1), reverse=True)])
|
||||||
if any([len(abs_paths) == cnt for cnt in [audio_cnt, video_cnt, image_cnt, rest_cnt, dir_cnt]]):
|
if len(type_counts) == 1:
|
||||||
reply += "<b>{}:</b> {}\n".format(dir, details)
|
reply += "<b>{}:</b> {}\n".format(dir, details)
|
||||||
else:
|
else:
|
||||||
reply += "<b>{}:</b> {} files ({})\n".format(dir, len(files), details)
|
reply += "<b>{}:</b> {} files ({})\n".format(dir, len(files), details)
|
||||||
|
|
Loading…
Reference in a new issue