-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleech_me.py
66 lines (61 loc) · 3.15 KB
/
leech_me.py
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
60
61
62
63
64
65
66
import qbittorrentapi
import time
import argparse
from plexapi.server import PlexServer
from playsound import playsound
parser = argparse.ArgumentParser(
description='when your torrent is complete its removed from the queue and refresh your Plex library',
epilog="python leech_me.py --torrent_host '192.168.1.221' --password 'Password' --plex_host '192.168.1.221' --plex_token 'ad8voSaz1f52TjoV4RgK' --download_complete_sound '/home/joerod/Dropbox/Public/files-done.mp3'"
)
parser.add_argument("--torrent_host", required=True, help="IP of machine running qbittorrent")
parser.add_argument("--torrent_port", default='8080', help="Port of machine running qbittorrent")
parser.add_argument("--username", default='admin', help="user name to login")
parser.add_argument("--password", required=True, help="password to login")
parser.add_argument("--plex_host", help="IP of machine running Plex")
parser.add_argument("--plex_port", default='32400', help="IP of machine running Plex")
parser.add_argument("--plex_token", help="token to auth to Plex")
parser.add_argument("--download_complete_sound" ,help="Path to sound (wav/mp3) to play when downlaod is complete")
args = parser.parse_args()
# instantiate a qbittorrent client using the appropriate WebUI configuration
qbt_client = qbittorrentapi.Client(host=args.torrent_host, port=args.torrent_port, username=args.username, password=args.password)
try:
qbt_client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
print(e)
if(args.plex_host):
# instantiate a plex connection
try:
plex = PlexServer("http://" + args.plex_host + ":" + args.plex_port, args.plex_token)
except Exception as e:
print(e)
start = time.time()
while(len(qbt_client.torrents_info())>0):
for torrents in qbt_client.torrents_info():
print(f'Still leaching: {torrents.name} - {round((torrents.progress * 100),2)}%')
if(torrents.state in ['uploading','stalledUP']):
print(f'Removing {torrents.name}')
qbt_client.torrents_delete(torrent_hashes=torrents.hash)
if(args.download_complete_sound):
playsound(args.download_complete_sound)
if(args.plex_host):
# remove unneeded path info from download
refresh_path = torrents.save_path.replace('/downloads/','').replace('/','')
if refresh_path == 'TV':
refresh_path = 'TV Shows'
try:
plex.library.section(refresh_path).update()
print(f'Refreshed Plex path "{refresh_path}"')
except Exception as e:
print(e)
if(len(qbt_client.torrents_info())==0):
end = time.time()
total_time = round((end-start)/60, 0)
plural_time = 'minute' if total_time <= 1 else 'minutes'
print(f'All leached up: leaching took {total_time} {plural_time}')
quit()
time.sleep(60)
else:
end = time.time()
total_time = round((end-start)/60, 0)
plural_time = 'minute' if total_time <= 1 else 'minutes'
print(f'All leached up: leaching took {total_time} {plural_time}')