This commit is contained in:
NikolajDanger
2021-02-01 22:14:45 +01:00
parent 25366f016d
commit cee03aa15b

View File

@@ -7,6 +7,10 @@ qbittorrentURL = "http://localhost:1340/api/v2/"
moviePath = "/media/plex/Server/movies/" moviePath = "/media/plex/Server/movies/"
showPath = "/media/plex/Server/Shows/" showPath = "/media/plex/Server/Shows/"
async def fileSize(fp):
print(fp[:60],end="\r")
return os.path.getsize(fp)
async def getSize(startPath,pathLength): async def getSize(startPath,pathLength):
logThis("Getting the size of "+startPath) logThis("Getting the size of "+startPath)
totalSize = 0 totalSize = 0
@@ -15,7 +19,7 @@ async def getSize(startPath,pathLength):
fp = os.path.join(dirpath, f) fp = os.path.join(dirpath, f)
# skip if it is symbolic link # skip if it is symbolic link
if not os.path.islink(fp): if not os.path.islink(fp):
totalSize += os.path.getsize(fp) totalSize += await fileSize(fp)
return totalSize return totalSize
@@ -276,7 +280,7 @@ class BedreNetflix():
async def directorySizes(self,ctx): async def directorySizes(self,ctx):
logThis("Calculating directory size") 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 = ".." startPath = ".."
pathLength = len(startPath) pathLength = len(startPath)
directories = [] directories = []
@@ -287,6 +291,17 @@ class BedreNetflix():
else: else:
size = await getSize(fp,pathLength) size = await getSize(fp,pathLength)
directories.append((str(f),size)) 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.sort(key=lambda tup: tup[1])
directories.reverse() directories.reverse()
returnText = "```" returnText = "```"
@@ -297,4 +312,5 @@ class BedreNetflix():
returnText += "\n"+directory+": "+sizeText returnText += "\n"+directory+": "+sizeText
returnText += "\nTotal: "+await formatSize(total)+"```" returnText += "\nTotal: "+await formatSize(total)+"```"
logThis("Returning final result of dirsize")
await message.edit(content=returnText) await message.edit(content=returnText)