astroport-iptubes/crawl.py

61 lines
1.5 KiB
Python
Raw Normal View History

2020-03-20 03:34:36 +01:00
################################################################################
# Author: Poka (poka@p2p.legal)
# Version: 0.0.2
2020-03-20 03:34:36 +01:00
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# Git: https://git.p2p.legal/axiom-team/astroport
################################################################################
2020-03-20 02:00:21 +01:00
import requests
import json
import sys
import subprocess
2020-03-20 02:00:21 +01:00
import login
import time
2020-03-20 02:00:21 +01:00
2020-03-20 03:34:36 +01:00
# Load scraper
2020-03-20 02:44:22 +01:00
from yggcrawl import YggTorrentScraper
2020-03-20 02:00:21 +01:00
scraper = YggTorrentScraper(requests.session())
from yggtorrentscraper import set_yggtorrent_tld
set_yggtorrent_tld("se")
name = ' '.join(sys.argv[1:])
2020-03-20 02:00:21 +01:00
2020-03-20 03:34:36 +01:00
# Give paramaters to scraper
2020-03-20 02:00:21 +01:00
parameters = {
"name": name,
"category": "films_&_videos",
"subcategory": "film",
"sort": "seed",
"order": "desc"
}
2020-03-20 03:34:36 +01:00
# Execute scrapping
2020-03-20 02:00:21 +01:00
research = scraper.search(parameters)
# Check if not found
if research == []:
print("Aucun torrent trouvé ayant pour nom \"" + name + "\"")
sys.exit()
# Options
#most_completed = scraper.most_completed()
2020-03-20 02:00:21 +01:00
#print(json.dumps(research, sort_keys=True, indent=4))
#print(json.dumps(most_completed, sort_keys=True, indent=4))
2020-03-20 03:34:36 +01:00
# Download torrent file
2020-03-20 02:00:21 +01:00
if(scraper.login(login.user, login.passwd)):
print("Login success")
2020-03-20 02:44:22 +01:00
first_torrent = research[0]
scraper.download_from_torrent_url(first_torrent)
2020-03-20 02:00:21 +01:00
else:
print("Login failed")
# Remove tracker
print("Start to remove tracker ...")
time.sleep(1)
print("Wait 10 seconds to get peers before remove tracker...")
time.sleep(10)
subprocess.call(["./trans-ctl.sh", "rmtracker", name])
print("Done")