Add files via upload
This commit is contained in:
parent
ab730cbf45
commit
e88ef349c4
4 changed files with 108 additions and 0 deletions
1
Procfile
Normal file
1
Procfile
Normal file
|
@ -0,0 +1 @@
|
|||
worker: python getp2pbot.py
|
75
getp2pbot.py
Normal file
75
getp2pbot.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
import os
|
||||
import re
|
||||
import requests
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from lxml import html
|
||||
|
||||
# Add the bot:
|
||||
# https://discord.com/api/oauth2/authorize?client_id=866933457967513630&permissions=2147585024&scope=bot
|
||||
|
||||
# Setting Up
|
||||
token = 'ODY2OTMzNDU3OTY3NTEzNjMw.YPZwsw.MFEC2UJt1rJ3wvFPYB1qxRDNIzo'
|
||||
bot = commands.Bot(command_prefix='/')
|
||||
|
||||
@bot.command()
|
||||
async def rutor(ctx, *args):
|
||||
regex = re.compile(r'\'([\wА-Яа-я\s]+)\'\s*?(\d+)*$')
|
||||
parsed_args = regex.match(' '.join(args))
|
||||
query = parsed_args.group(1)
|
||||
try:
|
||||
rownum = int(parsed_args.group(2))
|
||||
except TypeError:
|
||||
rownum = 0
|
||||
|
||||
page = requests.get(f'http://rutor.info/search/{query}')
|
||||
page_tree = html.fromstring(page.content)
|
||||
table = page_tree.xpath('//div[@id="index"]')[0]
|
||||
rows = table.xpath('.//tr[@class="gai" or @class="tum"]')
|
||||
|
||||
if rownum != 0:
|
||||
# The 2nd cell (index=1) is the main text
|
||||
# with a link to download and a title,
|
||||
# the 1st anchor (index=0) is a download link
|
||||
cells = rows[rownum-1].xpath('.//td')
|
||||
dllink = cells[1].xpath('.//a//@href')[0]
|
||||
|
||||
linkparts = dllink.split('/')
|
||||
torrentid = int(linkparts[len(linkparts)-1])
|
||||
filename = f'{torrentid}.torrent'
|
||||
|
||||
torrent = requests.get(dllink).content
|
||||
dlfile = open(filename, 'wb')
|
||||
dlfile.write(torrent)
|
||||
dlfile.close()
|
||||
|
||||
hascomments = len(cells) > 4
|
||||
size = cells[3 if hascomments else 2].text
|
||||
title = cells[1].xpath('.//a')[2].text.strip().replace('\'', '')
|
||||
|
||||
await ctx.send(
|
||||
f'`{torrentid}: {title} ({size})`',
|
||||
file=discord.File(filename)
|
||||
)
|
||||
os.remove(filename)
|
||||
else:
|
||||
choose_text = ''
|
||||
i = 1
|
||||
for row in rows:
|
||||
if (i > 10):
|
||||
break
|
||||
# The 3rd anchor (index=2) in the 2nd cell (index=1) is a title,
|
||||
# the 4th cell (index=3) contains the size of a film
|
||||
cells = row.xpath('.//td')
|
||||
maincell = cells[1]
|
||||
|
||||
hascomments = len(cells) > 4
|
||||
size = cells[3 if hascomments else 2].text
|
||||
title = maincell.xpath('.//a')[2].text.strip().replace('\'', '')
|
||||
|
||||
choose_text += f'${i} {title} \'{size}\'\n'
|
||||
i += 1
|
||||
await ctx.send(f'Choose torrent:```bash\n{choose_text}```')
|
||||
|
||||
# Starting
|
||||
bot.run(token)
|
31
requirements.txt
Normal file
31
requirements.txt
Normal file
|
@ -0,0 +1,31 @@
|
|||
aiohttp==3.7.4.post0
|
||||
anyio==3.2.1
|
||||
async-timeout==3.0.1
|
||||
attrs==21.2.0
|
||||
beautifulsoup4==4.9.3
|
||||
certifi==2020.12.5
|
||||
cffi==1.14.5
|
||||
chardet==4.0.0
|
||||
click==7.1.2
|
||||
discord.py==1.7.3
|
||||
h11==0.12.0
|
||||
httpcore==0.13.6
|
||||
httpx==0.18.2
|
||||
idna==2.10
|
||||
lxml==4.6.2
|
||||
multidict==5.1.0
|
||||
numpy==1.20.2
|
||||
Pillow==8.2.0
|
||||
pycparser==2.20
|
||||
pygal==2.4.0
|
||||
pygame==2.0.1
|
||||
PyNaCl==1.4.0
|
||||
PySocks==1.7.1
|
||||
requests==2.25.1
|
||||
rfc3986==1.5.0
|
||||
six==1.15.0
|
||||
sniffio==1.2.0
|
||||
soupsieve==2.2.1
|
||||
typing-extensions==3.10.0.0
|
||||
urllib3==1.26.3
|
||||
yarl==1.6.3
|
1
runtime.txt
Normal file
1
runtime.txt
Normal file
|
@ -0,0 +1 @@
|
|||
python-3.9.6
|
Loading…
Add table
Reference in a new issue