notif channel id is now settable from within the bot
also added docker files
This commit is contained in:
parent
1e81ebc381
commit
922a90be69
14
Animebyter/Dockerfile
Normal file
14
Animebyter/Dockerfile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
FROM python:alpine3.7
|
||||||
|
|
||||||
|
RUN apk add build-base
|
||||||
|
RUN apk add libffi-dev
|
||||||
|
RUN apk add openssl-dev
|
||||||
|
RUN apk add python3-dev
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
WORKDIR /app
|
||||||
|
ENV interval 300
|
||||||
|
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD python3 animebyter.py
|
@ -11,8 +11,18 @@ client = Bot('ab!')
|
|||||||
QB_URL = getenv("qbit_url")
|
QB_URL = getenv("qbit_url")
|
||||||
INTERVAL = int(getenv("INTERVAL")) if getenv("INTERVAL") else 300
|
INTERVAL = int(getenv("INTERVAL")) if getenv("INTERVAL") else 300
|
||||||
web = ClientSession()
|
web = ClientSession()
|
||||||
db = TinyDB("animebyter.json")
|
db = TinyDB(getenv("database_path","animebyter.json"))
|
||||||
chn = int(getenv("channel"))
|
path = getenv("download_path")
|
||||||
|
|
||||||
|
def get_channel_id():
|
||||||
|
res = db.search(Query().type == 'channel')
|
||||||
|
if len(res) > 0:
|
||||||
|
chn = res[0]['id']
|
||||||
|
else:
|
||||||
|
db.insert({'type':'channel','id':''})
|
||||||
|
chn = None
|
||||||
|
return chn
|
||||||
|
get_channel_id()
|
||||||
|
|
||||||
downloading = []
|
downloading = []
|
||||||
|
|
||||||
@ -49,9 +59,8 @@ async def get_airing():
|
|||||||
|
|
||||||
async def add_torrent(anime):
|
async def add_torrent(anime):
|
||||||
print("Adding episode {} of {}".format(anime.last_episode,anime.title))
|
print("Adding episode {} of {}".format(anime.last_episode,anime.title))
|
||||||
path = "/mnt/Storage/Anime"
|
|
||||||
try:
|
try:
|
||||||
res = await web.post(QB_URL+'/command/download',data={'urls':anime.torrent_link,'savepath':join(path,anime.title),'label':'Anime'})
|
res = await web.post(QB_URL+'/command/download',data={'urls':anime.torrent_link,'savepath':join(path,anime.title),'category':'Anime'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
return
|
return
|
||||||
@ -77,7 +86,7 @@ async def main():
|
|||||||
if le<i.last_episode and i.resolution in ("1080p"):
|
if le<i.last_episode and i.resolution in ("1080p"):
|
||||||
msg = await add_torrent(i)
|
msg = await add_torrent(i)
|
||||||
if msg:
|
if msg:
|
||||||
await client.get_channel(chn).send(msg)
|
await client.get_channel(get_channel_id()).send(msg)
|
||||||
db.update({'last_episode':i.last_episode},Query().title==i.title)
|
db.update({'last_episode':i.last_episode},Query().title==i.title)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
@ -90,7 +99,7 @@ async def dl_watchdog():
|
|||||||
print("Starting download watchdog")
|
print("Starting download watchdog")
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
res = await web.get(QB_URL+"/query/torrents",params={'filter':'downloading','label':'Anime'})
|
res = await web.get(QB_URL+"/query/torrents",params={'filter':'downloading'})
|
||||||
if res.status==200:
|
if res.status==200:
|
||||||
res = await res.json()
|
res = await res.json()
|
||||||
names = []
|
names = []
|
||||||
@ -104,7 +113,7 @@ async def dl_watchdog():
|
|||||||
downloading.remove(i)
|
downloading.remove(i)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
await client.get_channel(chn).send(":exclamation: <@!196224042988994560> {} has finished downloading.".format(i))
|
await client.get_channel(get_channel_id()).send(":exclamation: <@!196224042988994560> {} has finished downloading.".format(i))
|
||||||
else:
|
else:
|
||||||
print("Something went wrong with fetching downloads ({}: {})".format(res.status,await res.text()))
|
print("Something went wrong with fetching downloads ({}: {})".format(res.status,await res.text()))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -121,9 +130,16 @@ def chunks(s, n=1999):
|
|||||||
@client.command(pass_context=True)
|
@client.command(pass_context=True)
|
||||||
async def add(ctx):
|
async def add(ctx):
|
||||||
airing = await get_airing()
|
airing = await get_airing()
|
||||||
|
already_added = []
|
||||||
txt = ""
|
txt = ""
|
||||||
for i,v in enumerate(airing):
|
i = 0
|
||||||
|
for v in airing:
|
||||||
|
if v.title in already_added:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
already_added.append(v.title)
|
||||||
txt+="{}) {}\n".format(i,v.title)
|
txt+="{}) {}\n".format(i,v.title)
|
||||||
|
i += 1
|
||||||
msgs = []
|
msgs = []
|
||||||
for i in chunks(txt):
|
for i in chunks(txt):
|
||||||
msgs.append(await ctx.send(i))
|
msgs.append(await ctx.send(i))
|
||||||
@ -146,6 +162,8 @@ async def remove(ctx):
|
|||||||
watching = db.all()
|
watching = db.all()
|
||||||
txt = ""
|
txt = ""
|
||||||
for i,v in enumerate(watching):
|
for i,v in enumerate(watching):
|
||||||
|
if not 'title' in v:
|
||||||
|
continue
|
||||||
txt+="{}) {}\n".format(i,v['title'])
|
txt+="{}) {}\n".format(i,v['title'])
|
||||||
msgs = []
|
msgs = []
|
||||||
for i in chunks(txt):
|
for i in chunks(txt):
|
||||||
@ -164,7 +182,7 @@ async def remove(ctx):
|
|||||||
return await ctx.send("Invalid number")
|
return await ctx.send("Invalid number")
|
||||||
an = watching[msg]
|
an = watching[msg]
|
||||||
db.remove(Query().title==an['title'])
|
db.remove(Query().title==an['title'])
|
||||||
return await ctx.send("Removed {}".format(an))
|
return await ctx.send("Removed {}".format(an['title']))
|
||||||
|
|
||||||
@client.command(pass_context=True)
|
@client.command(pass_context=True)
|
||||||
async def down(ctx):
|
async def down(ctx):
|
||||||
@ -187,6 +205,11 @@ async def down(ctx):
|
|||||||
return await ctx.send("Invalid number")
|
return await ctx.send("Invalid number")
|
||||||
await ctx.send(await add_torrent(airing[msg]))
|
await ctx.send(await add_torrent(airing[msg]))
|
||||||
|
|
||||||
|
@client.command(pass_context=True)
|
||||||
|
async def setchannel(ctx):
|
||||||
|
db.update({'id':ctx.channel.id},Query().type == 'channel')
|
||||||
|
await ctx.send("I will now send notifications to this channel!")
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("Starting animebyter")
|
print("Starting animebyter")
|
||||||
|
22
Animebyter/docker-compose.yml
Normal file
22
Animebyter/docker-compose.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
animebyter:
|
||||||
|
build: .
|
||||||
|
container_name: animebyter
|
||||||
|
environment:
|
||||||
|
- qbit_url=http://qbittorrent:8080
|
||||||
|
- qbit_user=admin
|
||||||
|
- qbit_pass=adminadmin
|
||||||
|
- ab_key=YOUR_ANIMEBYTES_KEY
|
||||||
|
- discord_token=YOUR_DISCORD_TOKEN
|
||||||
|
- download_path=/Anime
|
||||||
|
volumes:
|
||||||
|
- ./db:/db
|
||||||
|
networks:
|
||||||
|
- qbit-network
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
networks:
|
||||||
|
qbit-network:
|
||||||
|
external:
|
||||||
|
name: qbittorrent_qbit-network
|
Loading…
x
Reference in New Issue
Block a user