🐛
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import requests, imdb, discord, json, math, time
|
import requests, imdb, discord, json, math, time, asyncio
|
||||||
from funcs import logThis
|
from funcs import logThis
|
||||||
|
|
||||||
radarrURL = "http://localhost:7878/api/v3/"
|
radarrURL = "http://localhost:7878/api/v3/"
|
||||||
@ -163,12 +163,15 @@ class BedreNetflix():
|
|||||||
await channel.send("Something went wrong")
|
await channel.send("Something went wrong")
|
||||||
logThis(str(r.status_code)+" "+r.reason)
|
logThis(str(r.status_code)+" "+r.reason)
|
||||||
|
|
||||||
async def downloading(self,ctx):
|
#Generates a list of all torrents and returns formatted list and whether all torrents are downloaded
|
||||||
|
async def genDownloadList(self):
|
||||||
|
logThis("Generating torrent list")
|
||||||
response = requests.get(qbittorrentURL+"torrents/info")
|
response = requests.get(qbittorrentURL+"torrents/info")
|
||||||
|
|
||||||
torrentList = response.json()
|
torrentList = response.json()
|
||||||
|
|
||||||
message = []
|
message = []
|
||||||
|
allDownloaded = True
|
||||||
|
|
||||||
for torrent in torrentList:
|
for torrent in torrentList:
|
||||||
torrentName = torrent["name"]
|
torrentName = torrent["name"]
|
||||||
@ -179,6 +182,8 @@ class BedreNetflix():
|
|||||||
torrentName = torrentName[:27]+"..."
|
torrentName = torrentName[:27]+"..."
|
||||||
if torrent["size"] == 0:
|
if torrent["size"] == 0:
|
||||||
downloadedRatio = 0
|
downloadedRatio = 0
|
||||||
|
elif torrent["amount_left"] == 0:
|
||||||
|
downloadedRatio = 1
|
||||||
else:
|
else:
|
||||||
downloadedRatio = min(torrent["downloaded"]/torrent["size"],1)
|
downloadedRatio = min(torrent["downloaded"]/torrent["size"],1)
|
||||||
progressBar = "|"+("█"*math.floor(downloadedRatio*20))
|
progressBar = "|"+("█"*math.floor(downloadedRatio*20))
|
||||||
@ -210,7 +215,35 @@ class BedreNetflix():
|
|||||||
if not (downloadedRatio == 1 and torrent["added_on"] < time.time()-86400):
|
if not (downloadedRatio == 1 and torrent["added_on"] < time.time()-86400):
|
||||||
message.append(torrentInfo)
|
message.append(torrentInfo)
|
||||||
|
|
||||||
|
if downloadedRatio < 1: allDownloaded = False
|
||||||
|
|
||||||
messageText = "```"+"\n".join(message)+"```"
|
messageText = "```"+"\n".join(message)+"```"
|
||||||
if messageText == "``````":
|
if messageText == "``````":
|
||||||
messageText = "There are no torrents downloading right. If the torrent you're looking for was added more than 24 hours ago, it might already be on Bedre Netflix."
|
messageText = "There are no torrents downloading right. If the torrent you're looking for was added more than 24 hours ago, it might already be on Bedre Netflix."
|
||||||
await ctx.send(messageText)
|
return messageText, allDownloaded
|
||||||
|
|
||||||
|
async def downloading(self,ctx):
|
||||||
|
messageText, allDownloaded = await self.genDownloadList()
|
||||||
|
updatesLeft = 20
|
||||||
|
messageText = messageText[:-3]+"\nThis message will update once a minute for "+str(updatesLeft)+" more minutes\n```"
|
||||||
|
|
||||||
|
oldMessage = await ctx.send(messageText)
|
||||||
|
|
||||||
|
while ((not allDownloaded) and updatesLeft > 0):
|
||||||
|
await asyncio.sleep(60)
|
||||||
|
updatesLeft -= 1
|
||||||
|
messageText, allDownloaded = await self.genDownloadList()
|
||||||
|
messageText = messageText[:-3]+"\nThis message will update once a minute for "+str(updatesLeft)+" more minutes\n```"
|
||||||
|
await oldMessage.edit(content = messageText)
|
||||||
|
|
||||||
|
messageText, allDownloaded = await self.genDownloadList()
|
||||||
|
|
||||||
|
if allDownloaded:
|
||||||
|
messageText = messageText[:-3]+"\nThis message will not update because all torrents are downloaded.\n```"
|
||||||
|
logThis("All torrents are downloaded")
|
||||||
|
else:
|
||||||
|
messageText = messageText[:-3]+"\nThis message will not update anymore\n```"
|
||||||
|
logThis("The message updated 20 times")
|
||||||
|
|
||||||
|
await oldMessage.edit(content = messageText)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user