Last active
March 31, 2021 11:49
-
-
Save kslr/27bc716ac604362d5bca8372980d5fc7 to your computer and use it in GitHub Desktop.
libtorrent test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import libtorrent as lt | |
import requests | |
from bs4 import BeautifulSoup | |
import time | |
alert_mask = ( | |
lt.alert.category_t.error_notification | |
| lt.alert.category_t.port_mapping_notification | |
| lt.alert.category_t.status_notification | |
| lt.alert.category_t.stats_notification | |
) | |
def get_list(): | |
magnets = [] | |
for page in range(1, 13): | |
html = requests.get('https://nyaa.si/?s=seeders&o=desc&p=' + str(page)).text | |
soup = BeautifulSoup(html, 'html.parser') | |
table = soup.find('table', attrs={'class': 'torrent-list'}) | |
table_body = table.find('tbody') | |
rows = table_body.find_all('tr') | |
for row in rows: | |
cols = row.find_all('td') | |
magnets.append(cols[2].find_all('a')[1]['href']) | |
return magnets | |
if __name__ == '__main__': | |
session = lt.session({ | |
'alert_mask': alert_mask | |
}) | |
session.add_extension('ut_metadata') | |
session.add_extension('smart_ban') | |
print("session start") | |
lists = get_list() | |
for i in lists: | |
atp = lt.parse_magnet_uri(i) | |
atp.save_path = "./" | |
atp.flags = lt.torrent_flags.duplicate_is_error \ | |
| lt.torrent_flags.auto_managed | |
session.async_add_torrent(atp) | |
while True: | |
alerts = session.pop_alerts() | |
for a in alerts: | |
print(a.message()) | |
if isinstance(a, lt.state_update_alert): | |
for s in a.status: | |
print(s.handle.status()) | |
session.post_torrent_updates() | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment