-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix-deluge-error.py
77 lines (58 loc) · 1.73 KB
/
fix-deluge-error.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
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python2.7
#
import requests
import configparser
import datetime
import logging
import os
import sys
import traceback
import glob
from deluge.ui.client import client
from twisted.internet import reactor, defer
logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
class Main:
# If this is true, will only print stuff. Won't actually delete anything
fakeDelete = True
plexFiles = set([])
watchedFiles = {}
config = None
def __init__(self, fakeDelete):
self.config = configparser.ConfigParser()
self.config.read(os.path.expanduser('~/.plex-delete-watched'))
pass
def run(self):
self.processTorrents()
reactor.run()
@defer.inlineCallbacks
def processTorrents(self):
delugeConfig = self.config['Deluge']
try:
yield client.connect(host=delugeConfig['host'], username=delugeConfig['username'],
password=delugeConfig['password'])
torrents = yield client.core.get_torrents_status({}, [])
for torrentId, torrent in torrents.iteritems():
if torrent["state"] == 'Error':
name = torrent['name']
path = find(name, '/volume1/video/tv')
if path is not None:
print('Linking %s' % (name))
try:
os.link(path, os.path.join('/volume1/video/deluge/tv', name))
except:
continue
except Exception as e:
traceback.print_exc()
finally:
client.disconnect()
reactor.stop()
def find(name, path):
for root, dirs, files in os.walk(path):
if name in files:
return os.path.join(root, name)
return None
if __name__ == '__main__':
fake = False
if len(sys.argv) > 1 and sys.argv[1] == '--fake':
fake = True
Main(fake).run()