-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretracker.py
More file actions
66 lines (44 loc) · 1.88 KB
/
retracker.py
File metadata and controls
66 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
import datetime
import sqlite3
import time
import xml.etree.ElementTree as ET
import lib.transmissionrpc
import getpass
import urllib
import re, os
import pandas as pd
import base64
import requests
import configparser
config = configparser.RawConfigParser()
config.read('smartnode.properties')
client = lib.transmissionrpc.Client(address = config.get("Transmission","address"),
port=int(config.get("Transmission","port")),
user = config.get("Transmission","user"),
password = config.get("Transmission","password"))
## TODO finish transmission interface part
torrents = client.list()
torrents_in_server = set([torrents[t].hashString for t in torrents])
download_path = client.get_session().download_dir
cookies = config.get("AcademicTorrents","api_key")
cookie_key = dict([k.split("=") for k in cookies.split(";")])
userannounce = None
def get_userannounce():
global userannounce
if userannounce is None:
resp = requests.get(url="https://academictorrents.com/apiv2/userannounce", cookies=cookie_key)
userannounce = resp.json()["userannounce"] # Check the JSON Response Content documentation below
return userannounce
def fix_trackers():
# check to remove or update trackers
for torrentid in torrents:
torrentobj = torrents[torrentid]
torrentobj = client.get_torrent(torrentid)
for index, tracker in enumerate(torrentobj.trackers):
if ("academictorrents.com" in tracker["announce"]):
if (tracker["announce"] != get_userannounce()):
print("Updating tracker at index",index, torrentobj.hashString, torrentid, torrentobj.name)
client.change_torrent(torrentid, trackerReplace=[index,get_userannounce()])
client.reannounce(torrentid)
fix_trackers()