From cee03aa15b40fa2d9686ec0ed6236d95b573e07c Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Mon, 1 Feb 2021 22:14:45 +0100 Subject: [PATCH] :bug: --- funcs/other/bedreNetflix.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/funcs/other/bedreNetflix.py b/funcs/other/bedreNetflix.py index cd50bbf..df352a6 100644 --- a/funcs/other/bedreNetflix.py +++ b/funcs/other/bedreNetflix.py @@ -7,6 +7,10 @@ qbittorrentURL = "http://localhost:1340/api/v2/" moviePath = "/media/plex/Server/movies/" showPath = "/media/plex/Server/Shows/" +async def fileSize(fp): + print(fp[:60],end="\r") + return os.path.getsize(fp) + async def getSize(startPath,pathLength): logThis("Getting the size of "+startPath) totalSize = 0 @@ -15,7 +19,7 @@ async def getSize(startPath,pathLength): fp = os.path.join(dirpath, f) # skip if it is symbolic link if not os.path.islink(fp): - totalSize += os.path.getsize(fp) + totalSize += await fileSize(fp) return totalSize @@ -276,7 +280,7 @@ class BedreNetflix(): async def directorySizes(self,ctx): logThis("Calculating directory size") - message = await ctx.send("Calculating directory size. This might take a while.") + message = await ctx.send("```Calculating directory size. This might take a while.```") startPath = ".." pathLength = len(startPath) directories = [] @@ -287,6 +291,17 @@ class BedreNetflix(): else: size = await getSize(fp,pathLength) directories.append((str(f),size)) + directories.sort(key=lambda tup: tup[1]) + directories.reverse() + returnText = "```Calculating directory size. This might take a while.\n" + total = 0 + for directory, size in directories: + total += size + sizeText = await formatSize(size) + returnText += "\n"+directory+": "+sizeText + returnText += "\nTotal: "+await formatSize(total)+"```" + await message.edit(content=returnText) + directories.sort(key=lambda tup: tup[1]) directories.reverse() returnText = "```" @@ -297,4 +312,5 @@ class BedreNetflix(): returnText += "\n"+directory+": "+sizeText returnText += "\nTotal: "+await formatSize(total)+"```" + logThis("Returning final result of dirsize") await message.edit(content=returnText)