Created
July 26, 2019 13:57
-
-
Save histrio/86944e3ff83b2e22030adc5539f2abbf to your computer and use it in GitHub Desktop.
echo "Name" | python rutracker.py | fzf | awk -F, '{print $(NF)}' | python rutracker.py | xargs peerflix -f . --mpv
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import os | |
import requests | |
import pickle | |
from lxml.html import document_fromstring | |
SESSION_FILENAME = 'rutracker.session' | |
ROOT = "https://rutracker.org/forum/" | |
def get_session(): | |
s = requests.session() | |
try: | |
with open(SESSION_FILENAME, 'rb') as f: | |
s.cookies.update(pickle.load(f)) | |
resp = s.head(ROOT) | |
resp.raise_for_status() | |
except Exception: | |
resp = s.post("https://rutracker.org/forum/login.php", data={ | |
"login_username": "xxx", | |
"login_password": "xxx", | |
"login": "вход" | |
}) | |
resp.raise_for_status() | |
with open(SESSION_FILENAME, 'wb') as f: | |
pickle.dump(s.cookies, f) | |
return s | |
def main(search): | |
s = get_session() | |
resp = s.post("https://rutracker.org/forum/tracker.php", data={"o":10, "s": 2, "nm": search}) | |
# resp = s.post("https://rutracker.org/forum/tracker.php", data={"o":10, "s": 2, "f": '2091,2092,2093,2221', "nm": search}) | |
resp.raise_for_status() | |
el = document_fromstring(resp.text) | |
rows = el.xpath(".//table[@class='forumline tablesorter']/tbody/tr") | |
for row in rows: | |
rec, = row.xpath("td[@class='row4 med tLeft t-title']/div/a") | |
title = rec.text | |
rec, = row.xpath("td[@class='row4 med tLeft t-title']/div/a") | |
size = row.xpath("td[@class='row4 small nowrap tor-size']/u")[0].text | |
# magnet_link = ROOT + row.xpath("td[@class='row4 small nowrap tor-size']/a")[0].get('href') | |
href = ROOT + rec.get('href') | |
print(f'{title},{size},{href}') | |
def resolve(link): | |
s = get_session() | |
resp = s.get(link) | |
resp.raise_for_status() | |
el = document_fromstring(resp.text) | |
rec, = el.xpath(".//a[@class='med magnet-link magnet-link-16']") | |
print(rec.get('href')) | |
if __name__ == "__main__": | |
data = sys.stdin.read() | |
if not data.startswith('http'): | |
exit(main(data)) | |
else: | |
exit(resolve(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment