trackma 0.4__py2.7.egg → 0.5__py2.7.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +1 -1
- EGG-INFO/SOURCES.txt +2 -0
- trackma/__init__.pyc +0 -0
- trackma/accounts.py +36 -1
- trackma/accounts.pyc +0 -0
- trackma/data/shikimori.jpg +0 -0
- trackma/data.py +33 -20
- trackma/data.pyc +0 -0
- trackma/engine.py +82 -11
- trackma/engine.pyc +0 -0
- trackma/extras/AnimeInfoExtractor.pyc +0 -0
- trackma/extras/__init__.pyc +0 -0
- trackma/extras/plex.pyc +0 -0
- trackma/lib/__init__.pyc +0 -0
- trackma/lib/lib.pyc +0 -0
- trackma/lib/libanilist.py +65 -17
- trackma/lib/libanilist.pyc +0 -0
- trackma/lib/libhb.py +4 -5
- trackma/lib/libhb.pyc +0 -0
- trackma/lib/libmal.py +10 -7
- trackma/lib/libmal.pyc +0 -0
- trackma/lib/libmelative.py +1 -1
- trackma/lib/libmelative.pyc +0 -0
- trackma/lib/libshikimori.py +338 -0
- trackma/lib/libshikimori.pyc +0 -0
- trackma/lib/libvndb.py +1 -0
- trackma/lib/libvndb.pyc +0 -0
- trackma/messenger.pyc +0 -0
- trackma/tracker.py +64 -17
- trackma/tracker.pyc +0 -0
- trackma/ui/__init__.pyc +0 -0
- trackma/ui/cli.py +191 -70
- trackma/ui/cli.pyc +0 -0
- trackma/ui/curses.py +14 -3
- trackma/ui/curses.pyc +0 -0
- trackma/ui/gtkui.py +341 -110
- trackma/ui/gtkui.pyc +0 -0
- trackma/ui/qtui.py +1243 -327
- trackma/ui/qtui.pyc +0 -0
- trackma/utils.py +118 -38
- trackma/utils.pyc +0 -0
trackma/lib/libmal.py
CHANGED
|
@@ -41,7 +41,7 @@ class libmal(lib):
|
|
|
41
41
|
logged_in = False
|
|
42
42
|
opener = None
|
|
43
43
|
|
|
44
|
-
api_info = { 'name': 'MyAnimeList', 'version': 'v0.3', 'merge': False }
|
|
44
|
+
api_info = { 'name': 'MyAnimeList', 'shortname': 'mal', 'version': 'v0.3', 'merge': False }
|
|
45
45
|
|
|
46
46
|
default_mediatype = 'anime'
|
|
47
47
|
mediatypes = dict()
|
|
@@ -51,6 +51,7 @@ class libmal(lib):
|
|
|
51
51
|
'can_delete': True,
|
|
52
52
|
'can_score': True,
|
|
53
53
|
'can_status': True,
|
|
54
|
+
'can_tag': True,
|
|
54
55
|
'can_update': True,
|
|
55
56
|
'can_play': True,
|
|
56
57
|
'can_date': True,
|
|
@@ -67,6 +68,7 @@ class libmal(lib):
|
|
|
67
68
|
'can_delete': True,
|
|
68
69
|
'can_score': True,
|
|
69
70
|
'can_status': True,
|
|
71
|
+
'can_tag': True,
|
|
70
72
|
'can_update': True,
|
|
71
73
|
'can_play': False,
|
|
72
74
|
'can_date': True,
|
|
@@ -184,8 +186,7 @@ class libmal(lib):
|
|
|
184
186
|
values = {'data': xml}
|
|
185
187
|
data = self._urlencode(values)
|
|
186
188
|
try:
|
|
187
|
-
|
|
188
|
-
return True
|
|
189
|
+
self.opener.open(self.url + self.mediatype + "list/add/" + str(item['id']) + ".xml", data)
|
|
189
190
|
except urllib2.HTTPError, e:
|
|
190
191
|
raise utils.APIError('Error adding: ' + str(e.code))
|
|
191
192
|
|
|
@@ -200,8 +201,7 @@ class libmal(lib):
|
|
|
200
201
|
values = {'data': xml}
|
|
201
202
|
data = self._urlencode(values)
|
|
202
203
|
try:
|
|
203
|
-
|
|
204
|
-
return True
|
|
204
|
+
self.opener.open(self.url + self.mediatype + "list/update/" + str(item['id']) + ".xml", data)
|
|
205
205
|
except urllib2.HTTPError, e:
|
|
206
206
|
raise utils.APIError('Error updating: ' + str(e.code))
|
|
207
207
|
|
|
@@ -211,8 +211,7 @@ class libmal(lib):
|
|
|
211
211
|
self.msg.info(self.name, "Deleting show %s..." % item['title'])
|
|
212
212
|
|
|
213
213
|
try:
|
|
214
|
-
|
|
215
|
-
return True
|
|
214
|
+
self.opener.open(self.url + self.mediatype + "list/delete/" + str(item['id']) + ".xml")
|
|
216
215
|
except urllib2.HTTPError, e:
|
|
217
216
|
raise utils.APIError('Error deleting: ' + str(e.code))
|
|
218
217
|
|
|
@@ -334,6 +333,7 @@ class libmal(lib):
|
|
|
334
333
|
'my_score': int(child.find('my_score').text),
|
|
335
334
|
'my_start_date': self._str2date( child.find('my_start_date').text ),
|
|
336
335
|
'my_finish_date': self._str2date( child.find('my_finish_date').text ),
|
|
336
|
+
'my_tags': child.find('my_tags').text,
|
|
337
337
|
'total': int(child.find('series_episodes').text),
|
|
338
338
|
'status': int(child.find('series_status').text),
|
|
339
339
|
'start_date': self._str2date( child.find('series_start').text ),
|
|
@@ -410,6 +410,9 @@ class libmal(lib):
|
|
|
410
410
|
if 'my_finish_date' in item.keys():
|
|
411
411
|
finish_date = ET.SubElement(root, "date_finish")
|
|
412
412
|
finish_date.text = self._date2str(item['my_finish_date'])
|
|
413
|
+
if 'my_tags' in item.keys():
|
|
414
|
+
tags = ET.SubElement(root, "tags")
|
|
415
|
+
tags.text = str(item['my_tags'])
|
|
413
416
|
|
|
414
417
|
return ET.tostring(root)
|
|
415
418
|
|
trackma/lib/libmal.pyc
CHANGED
|
Binary file
|
trackma/lib/libmelative.py
CHANGED
trackma/lib/libmelative.pyc
CHANGED
|
Binary file
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# This file is part of Trackma.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
from trackma.lib.lib import lib
|
|
18
|
+
import trackma.utils as utils
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import urllib, urllib2, socket
|
|
22
|
+
import time
|
|
23
|
+
|
|
24
|
+
class libshikimori(lib):
|
|
25
|
+
"""
|
|
26
|
+
API class to communicate with Shikimori
|
|
27
|
+
|
|
28
|
+
Website: http://shikimori.org
|
|
29
|
+
|
|
30
|
+
messenger: Messenger object to send useful messages to
|
|
31
|
+
"""
|
|
32
|
+
name = 'libshikimori'
|
|
33
|
+
msg = None
|
|
34
|
+
logged_in = False
|
|
35
|
+
|
|
36
|
+
api_info = { 'name': 'Shikimori', 'shortname': 'shikimori', 'version': '1', 'merge': False }
|
|
37
|
+
mediatypes = dict()
|
|
38
|
+
mediatypes['anime'] = {
|
|
39
|
+
'has_progress': True,
|
|
40
|
+
'can_add': True,
|
|
41
|
+
'can_delete': True,
|
|
42
|
+
'can_score': True,
|
|
43
|
+
'can_status': True,
|
|
44
|
+
'can_update': True,
|
|
45
|
+
'can_play': True,
|
|
46
|
+
'status_start': 1,
|
|
47
|
+
'status_finish': 2,
|
|
48
|
+
'statuses': [1, 2, 3, 9, 4, 0],
|
|
49
|
+
'statuses_dict': {
|
|
50
|
+
1: 'Watching',
|
|
51
|
+
2: 'Completed',
|
|
52
|
+
3: 'On-Hold',
|
|
53
|
+
9: 'Rewatching',
|
|
54
|
+
4: 'Dropped',
|
|
55
|
+
0: 'Plan to Watch'
|
|
56
|
+
},
|
|
57
|
+
'score_max': 10,
|
|
58
|
+
'score_step': 1,
|
|
59
|
+
}
|
|
60
|
+
mediatypes['manga'] = {
|
|
61
|
+
'has_progress': True,
|
|
62
|
+
'can_add': True,
|
|
63
|
+
'can_delete': True,
|
|
64
|
+
'can_score': True,
|
|
65
|
+
'can_status': True,
|
|
66
|
+
'can_update': True,
|
|
67
|
+
'can_play': False,
|
|
68
|
+
'status_start': 1,
|
|
69
|
+
'status_finish': 2,
|
|
70
|
+
'statuses': [1, 2, 3, 9, 4, 0],
|
|
71
|
+
'statuses_dict': {
|
|
72
|
+
1: 'Reading',
|
|
73
|
+
2: 'Completed',
|
|
74
|
+
3: 'On-Hold',
|
|
75
|
+
9: 'Rereading',
|
|
76
|
+
4: 'Dropped',
|
|
77
|
+
0: 'Plan to Read'
|
|
78
|
+
},
|
|
79
|
+
'score_max': 10,
|
|
80
|
+
'score_step': 1,
|
|
81
|
+
}
|
|
82
|
+
default_mediatype = 'anime'
|
|
83
|
+
|
|
84
|
+
# Supported signals for the data handler
|
|
85
|
+
signals = { 'show_info_changed': None, }
|
|
86
|
+
|
|
87
|
+
url = "http://shikimori.org"
|
|
88
|
+
|
|
89
|
+
def __init__(self, messenger, account, userconfig):
|
|
90
|
+
"""Initializes the API"""
|
|
91
|
+
super(libshikimori, self).__init__(messenger, account, userconfig)
|
|
92
|
+
|
|
93
|
+
self.username = account['username']
|
|
94
|
+
self.password = account['password']
|
|
95
|
+
self.userid = userconfig['userid']
|
|
96
|
+
|
|
97
|
+
if not self.password:
|
|
98
|
+
raise utils.APIFatal("No password.")
|
|
99
|
+
|
|
100
|
+
if self.mediatype == 'manga':
|
|
101
|
+
self.total_str = "chapters"
|
|
102
|
+
self.watched_str = "chapters"
|
|
103
|
+
self.airing_str = "publishing_status"
|
|
104
|
+
self.status_translate = {
|
|
105
|
+
'publishing': utils.STATUS_AIRING,
|
|
106
|
+
'finished': utils.STATUS_FINISHED,
|
|
107
|
+
'not yet published': utils.STATUS_NOTYET,
|
|
108
|
+
'cancelled': utils.STATUS_CANCELLED,
|
|
109
|
+
}
|
|
110
|
+
else:
|
|
111
|
+
self.total_str = "episodes"
|
|
112
|
+
self.watched_str = "episodes"
|
|
113
|
+
self.airing_str = "airing_status"
|
|
114
|
+
self.status_translate = {
|
|
115
|
+
'currently airing': utils.STATUS_AIRING,
|
|
116
|
+
'finished airing': utils.STATUS_FINISHED,
|
|
117
|
+
'not yet aired': utils.STATUS_NOTYET,
|
|
118
|
+
'cancelled': utils.STATUS_CANCELLED,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#handler=urllib2.HTTPHandler(debuglevel=1)
|
|
122
|
+
#self.opener = urllib2.build_opener(handler)
|
|
123
|
+
self.opener = urllib2.build_opener()
|
|
124
|
+
self.opener.addheaders = [('User-agent', 'Trackma/0.4')]
|
|
125
|
+
|
|
126
|
+
def _request(self, method, url, get=None, post=None, jsondata=None, auth=False):
|
|
127
|
+
if get:
|
|
128
|
+
url = "{}?{}".format(url, urllib.urlencode(get))
|
|
129
|
+
if post:
|
|
130
|
+
post = urllib.urlencode(post)
|
|
131
|
+
if jsondata:
|
|
132
|
+
post = json.dumps(jsondata, separators=(',',':'))
|
|
133
|
+
|
|
134
|
+
request = urllib2.Request(self.url + url, post)
|
|
135
|
+
request.get_method = lambda: method
|
|
136
|
+
|
|
137
|
+
if auth:
|
|
138
|
+
request.add_header('Content-Type', 'application/json')
|
|
139
|
+
request.add_header('X-User-Nickname', self.username)
|
|
140
|
+
request.add_header('X-User-Api-Access-Token', self._get_userconfig('access_token'))
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
response = self.opener.open(request, timeout = 10)
|
|
144
|
+
return json.load(response)
|
|
145
|
+
except urllib2.HTTPError, e:
|
|
146
|
+
if e.code == 400:
|
|
147
|
+
raise utils.APIError("400")
|
|
148
|
+
else:
|
|
149
|
+
raise utils.APIError("Connection error: %s" % e)
|
|
150
|
+
except socket.timeout:
|
|
151
|
+
raise utils.APIError("Connection timed out.")
|
|
152
|
+
except ValueError:
|
|
153
|
+
pass # No JSON data
|
|
154
|
+
|
|
155
|
+
def _request_access_token(self):
|
|
156
|
+
self.msg.info(self.name, 'Requesting access token...')
|
|
157
|
+
param = {
|
|
158
|
+
'nickname': self.username,
|
|
159
|
+
'password': self.password,
|
|
160
|
+
}
|
|
161
|
+
data = self._request("POST", "/api/access_token", get=param)
|
|
162
|
+
|
|
163
|
+
self._set_userconfig('access_token', data['api_access_token'])
|
|
164
|
+
|
|
165
|
+
self.logged_in = True
|
|
166
|
+
self._refresh_user_info()
|
|
167
|
+
self._emit_signal('userconfig_changed')
|
|
168
|
+
|
|
169
|
+
def _refresh_user_info(self):
|
|
170
|
+
self.msg.info(self.name, 'Refreshing user details...')
|
|
171
|
+
|
|
172
|
+
data = self._request("GET", "/api/users/whoami", auth=True)
|
|
173
|
+
|
|
174
|
+
self._set_userconfig('userid', data['id'])
|
|
175
|
+
self._set_userconfig('username', data['nickname'])
|
|
176
|
+
|
|
177
|
+
self.userid = data['id']
|
|
178
|
+
|
|
179
|
+
def check_credentials(self):
|
|
180
|
+
"""
|
|
181
|
+
Log into Shikimori. Ask for the request token if necessary.
|
|
182
|
+
"""
|
|
183
|
+
timestamp = int(time.time())
|
|
184
|
+
|
|
185
|
+
if not self._get_userconfig('access_token'):
|
|
186
|
+
self._request_access_token()
|
|
187
|
+
else:
|
|
188
|
+
self.logged_in = True
|
|
189
|
+
return True
|
|
190
|
+
|
|
191
|
+
def fetch_list(self):
|
|
192
|
+
self.check_credentials()
|
|
193
|
+
self.msg.info(self.name, 'Downloading list...')
|
|
194
|
+
|
|
195
|
+
data = self._request("GET", "/api/users/{}/{}_rates".format(self.userid, self.mediatype))
|
|
196
|
+
|
|
197
|
+
showlist = {}
|
|
198
|
+
|
|
199
|
+
#with open('list', 'w') as f:
|
|
200
|
+
# json.dump(data, f, indent=2)
|
|
201
|
+
|
|
202
|
+
for item in data:
|
|
203
|
+
show = utils.show()
|
|
204
|
+
showid = item[self.mediatype]['id']
|
|
205
|
+
show.update({
|
|
206
|
+
'id': showid,
|
|
207
|
+
'my_id': item['id'],
|
|
208
|
+
'title': item[self.mediatype]['name'],
|
|
209
|
+
'aliases': [item[self.mediatype]['russian']],
|
|
210
|
+
#'type': item[self.mediatype]['type'],
|
|
211
|
+
#'status': self.status_translate[item[self.mediatype][self.airing_str]],
|
|
212
|
+
'my_id': item['id'],
|
|
213
|
+
'my_progress': item[self.watched_str],
|
|
214
|
+
'my_status': item['status'],
|
|
215
|
+
'my_score': item['score'],
|
|
216
|
+
'total': item[self.mediatype][self.total_str],
|
|
217
|
+
'url': self.url + item[self.mediatype]['url'],
|
|
218
|
+
'image': self.url + item[self.mediatype]['image']['original'],
|
|
219
|
+
'image_thumb': self.url + item[self.mediatype]['image']['preview'],
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
showlist[showid] = show
|
|
223
|
+
|
|
224
|
+
return showlist
|
|
225
|
+
|
|
226
|
+
def add_show(self, item):
|
|
227
|
+
self.check_credentials()
|
|
228
|
+
self.msg.info(self.name, "Adding item %s..." % item['title'])
|
|
229
|
+
return self._update_entry(item, "POST")
|
|
230
|
+
|
|
231
|
+
def update_show(self, item):
|
|
232
|
+
self.check_credentials()
|
|
233
|
+
self.msg.info(self.name, "Updating item %s..." % item['title'])
|
|
234
|
+
return self._update_entry(item, "PUT")
|
|
235
|
+
|
|
236
|
+
def delete_show(self, item):
|
|
237
|
+
self.check_credentials()
|
|
238
|
+
self.msg.info(self.name, "Deleting item %s..." % item['title'])
|
|
239
|
+
|
|
240
|
+
data = self._request("DELETE", "/api/user_rates/{}".format(item['my_id']), auth=True)
|
|
241
|
+
|
|
242
|
+
def search(self, criteria):
|
|
243
|
+
self.check_credentials()
|
|
244
|
+
|
|
245
|
+
self.msg.info(self.name, "Searching for {}...".format(criteria))
|
|
246
|
+
param = {'q': criteria}
|
|
247
|
+
try:
|
|
248
|
+
data = self._request("GET", "/api/{}s/search".format(self.mediatype), get=param)
|
|
249
|
+
except ValueError:
|
|
250
|
+
# An empty document, without any JSON, is returned
|
|
251
|
+
# when there are no results.
|
|
252
|
+
return []
|
|
253
|
+
|
|
254
|
+
showlist = []
|
|
255
|
+
|
|
256
|
+
for item in data:
|
|
257
|
+
show = utils.show()
|
|
258
|
+
showid = item['id']
|
|
259
|
+
show.update({
|
|
260
|
+
'id': showid,
|
|
261
|
+
'title': item['name'],
|
|
262
|
+
'aliases': [item['russian']],
|
|
263
|
+
'type': item.get('kind', ''),
|
|
264
|
+
#'status': item[self.airing_str],
|
|
265
|
+
'status': 0,
|
|
266
|
+
'my_status': self.media_info()['status_start'],
|
|
267
|
+
'total': item[self.total_str],
|
|
268
|
+
'image': self.url + item['image']['original'],
|
|
269
|
+
'image_thumb': self.url + item['image']['preview'],
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
showlist.append( show )
|
|
273
|
+
|
|
274
|
+
return showlist
|
|
275
|
+
|
|
276
|
+
def request_info(self, itemlist):
|
|
277
|
+
self.check_credentials()
|
|
278
|
+
infolist = []
|
|
279
|
+
|
|
280
|
+
for show in itemlist:
|
|
281
|
+
data = self._request("GET", "/api/{}s/{}".format(self.mediatype, show['id']))
|
|
282
|
+
infolist.append( self._parse_info(data) )
|
|
283
|
+
|
|
284
|
+
self._emit_signal('show_info_changed', infolist)
|
|
285
|
+
return infolist
|
|
286
|
+
|
|
287
|
+
def media_info(self):
|
|
288
|
+
"""Return information about the currently selected mediatype."""
|
|
289
|
+
return self.mediatypes[self.mediatype]
|
|
290
|
+
|
|
291
|
+
def _update_entry(self, item, method):
|
|
292
|
+
# Note: This method returns the newly added or modified item ID (my_id)
|
|
293
|
+
if method == 'POST':
|
|
294
|
+
user_rate = {
|
|
295
|
+
'user_id': self.userid,
|
|
296
|
+
'target_id': item['id'],
|
|
297
|
+
'target_type': self.mediatype.capitalize(),
|
|
298
|
+
}
|
|
299
|
+
dest_url = "/api/user_rates"
|
|
300
|
+
else:
|
|
301
|
+
#user_rate = {'score': 0, 'status': 0, 'episodes': 0, 'volumes': 0, 'chapters': 0, 'text': '', 'rewatches': 0}
|
|
302
|
+
user_rate = {}
|
|
303
|
+
dest_url = "/api/user_rates/{}".format(item['my_id'])
|
|
304
|
+
|
|
305
|
+
if 'my_progress' in item.keys():
|
|
306
|
+
user_rate[self.watched_str] = item['my_progress']
|
|
307
|
+
if 'my_status' in item.keys():
|
|
308
|
+
user_rate['status'] = item['my_status']
|
|
309
|
+
if 'my_score' in item.keys():
|
|
310
|
+
user_rate['score'] = item['my_score']
|
|
311
|
+
|
|
312
|
+
values = {'user_rate': user_rate}
|
|
313
|
+
data = self._request(method, dest_url, jsondata=values, auth=True)
|
|
314
|
+
return data['id']
|
|
315
|
+
|
|
316
|
+
def _parse_info(self, item):
|
|
317
|
+
info = utils.show()
|
|
318
|
+
info.update({
|
|
319
|
+
'id': item['id'],
|
|
320
|
+
'title': item['name'],
|
|
321
|
+
'status': 0,
|
|
322
|
+
'image': self.url + item['image']['original'],
|
|
323
|
+
'url': self.url + item['url'],
|
|
324
|
+
'extra': [
|
|
325
|
+
('Description', item.get('description')),
|
|
326
|
+
#('Genres', item.get('genres')),
|
|
327
|
+
('Type', item.get('kind').capitalize()),
|
|
328
|
+
('Average score', item.get('score')),
|
|
329
|
+
('Russian title', item.get('russian')),
|
|
330
|
+
('Japanese title', item.get('japanese')[0]),
|
|
331
|
+
('English title', item.get('english')),
|
|
332
|
+
]
|
|
333
|
+
})
|
|
334
|
+
return info
|
|
335
|
+
|
|
336
|
+
def _c(self, s):
|
|
337
|
+
return 0 if s is None else s
|
|
338
|
+
|
|
Binary file
|
trackma/lib/libvndb.py
CHANGED
trackma/lib/libvndb.pyc
CHANGED
|
Binary file
|
trackma/messenger.pyc
CHANGED
|
Binary file
|
trackma/tracker.py
CHANGED
|
@@ -26,6 +26,8 @@ import utils
|
|
|
26
26
|
import extras.plex as plex
|
|
27
27
|
import extras.AnimeInfoExtractor
|
|
28
28
|
|
|
29
|
+
import ctypes
|
|
30
|
+
|
|
29
31
|
inotify_available = False
|
|
30
32
|
|
|
31
33
|
STATE_PLAYING = 0
|
|
@@ -100,9 +102,9 @@ class Tracker(object):
|
|
|
100
102
|
except KeyError:
|
|
101
103
|
raise Exception("Call to undefined signal.")
|
|
102
104
|
|
|
103
|
-
def
|
|
105
|
+
def _get_playing_file_lsof(self, players):
|
|
104
106
|
try:
|
|
105
|
-
lsof = subprocess.Popen(['lsof', '-n', '-c', ''.join(['/', players, '/']), '-Fn'], stdout=subprocess.PIPE)
|
|
107
|
+
lsof = subprocess.Popen(['lsof', '+w', '-n', '-c', ''.join(['/', players, '/']), '-Fn'], stdout=subprocess.PIPE)
|
|
106
108
|
except OSError:
|
|
107
109
|
self.msg.warn(self.name, "Couldn't execute lsof. Disabling tracker.")
|
|
108
110
|
self.disable()
|
|
@@ -118,6 +120,39 @@ class Tracker(object):
|
|
|
118
120
|
|
|
119
121
|
return False
|
|
120
122
|
|
|
123
|
+
def _foreach_window(self, hwnd, lParam):
|
|
124
|
+
# Get class name and window title of the current hwnd
|
|
125
|
+
# and add it to the list of the found windows
|
|
126
|
+
length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
|
|
127
|
+
|
|
128
|
+
buff_class = ctypes.create_unicode_buffer(32)
|
|
129
|
+
buff_title = ctypes.create_unicode_buffer(length + 1)
|
|
130
|
+
|
|
131
|
+
ctypes.windll.user32.GetClassNameW(hwnd, buff_class, 32)
|
|
132
|
+
ctypes.windll.user32.GetWindowTextW(hwnd, buff_title, length + 1)
|
|
133
|
+
|
|
134
|
+
self.win32_hwnd_list.append( (buff_class.value, buff_title.value) )
|
|
135
|
+
return True
|
|
136
|
+
|
|
137
|
+
def _get_playing_file_win32(self):
|
|
138
|
+
# Enumerate all windows using the win32 API
|
|
139
|
+
# This will call _foreach_window for each window handle
|
|
140
|
+
# Then return the window title if the class name matches
|
|
141
|
+
# Currently supporting MPC(-HC) and mpv
|
|
142
|
+
|
|
143
|
+
self.win32_hwnd_list = []
|
|
144
|
+
self.EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
|
|
145
|
+
ctypes.windll.user32.EnumWindows(self.EnumWindowsProc(self._foreach_window), 0)
|
|
146
|
+
winregex = re.compile("(\.mkv|\.mp4|\.avi)")
|
|
147
|
+
|
|
148
|
+
for classname, title in self.win32_hwnd_list:
|
|
149
|
+
if classname == 'MediaPlayerClassicW' and winregex.search(title) is not None:
|
|
150
|
+
return title
|
|
151
|
+
elif classname == 'mpv' and winregex.search(title) is not None:
|
|
152
|
+
return title.replace('mpv - ', '')
|
|
153
|
+
|
|
154
|
+
return False
|
|
155
|
+
|
|
121
156
|
def _get_plex_file(self):
|
|
122
157
|
playing_file = plex.playing_file()
|
|
123
158
|
return playing_file
|
|
@@ -126,9 +161,9 @@ class Tracker(object):
|
|
|
126
161
|
self.msg.debug(self.name, 'inotify: Watching %s' % watch_dir)
|
|
127
162
|
inotifyx.add_watch(fd, watch_dir.encode('utf-8'), inotifyx.IN_OPEN | inotifyx.IN_CLOSE)
|
|
128
163
|
|
|
129
|
-
for
|
|
130
|
-
|
|
131
|
-
self._inotify_watch_recursive(fd, os.path.join(
|
|
164
|
+
for path in os.listdir(watch_dir):
|
|
165
|
+
if os.path.isdir(os.path.join(watch_dir, path)):
|
|
166
|
+
self._inotify_watch_recursive(fd, os.path.join(watch_dir, path))
|
|
132
167
|
|
|
133
168
|
def _observe_inotify(self, watch_dir):
|
|
134
169
|
self.msg.info(self.name, 'Using inotify.')
|
|
@@ -142,7 +177,8 @@ class Tracker(object):
|
|
|
142
177
|
if events:
|
|
143
178
|
for event in events:
|
|
144
179
|
if not event.mask & inotifyx.IN_ISDIR:
|
|
145
|
-
|
|
180
|
+
filename = self._get_playing_file_lsof(self.process_name)
|
|
181
|
+
(state, show_tuple) = self._get_playing_show(filename)
|
|
146
182
|
self.update_show_if_needed(state, show_tuple)
|
|
147
183
|
|
|
148
184
|
if self.last_state == STATE_NOVIDEO:
|
|
@@ -158,17 +194,30 @@ class Tracker(object):
|
|
|
158
194
|
os.close(fd)
|
|
159
195
|
|
|
160
196
|
def _observe_polling(self, interval):
|
|
161
|
-
self.msg.
|
|
197
|
+
self.msg.info(self.name, "inotifyx not available; using polling (slow).")
|
|
162
198
|
while True:
|
|
163
199
|
# This runs the tracker and update the playing show if necessary
|
|
164
|
-
|
|
200
|
+
filename = self._get_playing_file_lsof(self.process_name)
|
|
201
|
+
(state, show_tuple) = self._get_playing_show(filename)
|
|
165
202
|
self.update_show_if_needed(state, show_tuple)
|
|
166
203
|
|
|
167
204
|
# Wait for the interval before running check again
|
|
168
205
|
time.sleep(interval)
|
|
169
206
|
|
|
207
|
+
def _observe_win32(self, interval):
|
|
208
|
+
self.msg.info(self.name, "Using Win32.")
|
|
209
|
+
|
|
210
|
+
while True:
|
|
211
|
+
# This runs the tracker and update the playing show if necessary
|
|
212
|
+
filename = self._get_playing_file_win32()
|
|
213
|
+
(state, show_tuple) = self._get_playing_show(filename)
|
|
214
|
+
self.update_show_if_needed(state, show_tuple)
|
|
215
|
+
|
|
216
|
+
# Wait for the interval before running check again
|
|
217
|
+
time.sleep(1)
|
|
218
|
+
|
|
170
219
|
def _observe_plex(self, interval):
|
|
171
|
-
self.msg.info(self.name, "
|
|
220
|
+
self.msg.info(self.name, "Using Plex.")
|
|
172
221
|
|
|
173
222
|
while True:
|
|
174
223
|
# This stores the last two states of the plex server and only
|
|
@@ -178,7 +227,8 @@ class Tracker(object):
|
|
|
178
227
|
|
|
179
228
|
if self.plex_log[-1] == "ACTIVE" or self.plex_log[-1] == "IDLE":
|
|
180
229
|
self.wait_s = plex.timer_from_file()
|
|
181
|
-
|
|
230
|
+
filename = self._get_plex_file()
|
|
231
|
+
(state, show_tuple) = self._get_playing_show(filename)
|
|
182
232
|
self.update_show_if_needed(state, show_tuple)
|
|
183
233
|
elif (self.plex_log[-2] != "NOT_RUNNING" and self.plex_log[-1] == "NOT_RUNNING"):
|
|
184
234
|
self.msg.warn(self.name, "Plex Media Server is not running.")
|
|
@@ -191,7 +241,9 @@ class Tracker(object):
|
|
|
191
241
|
if self.plex_enabled:
|
|
192
242
|
self._observe_plex(interval)
|
|
193
243
|
else:
|
|
194
|
-
if
|
|
244
|
+
if os.name == 'nt':
|
|
245
|
+
self._observe_win32(interval)
|
|
246
|
+
elif inotify_available:
|
|
195
247
|
self._observe_inotify(watch_dir)
|
|
196
248
|
else:
|
|
197
249
|
self._observe_polling(interval)
|
|
@@ -267,16 +319,11 @@ class Tracker(object):
|
|
|
267
319
|
|
|
268
320
|
self.last_state = state
|
|
269
321
|
|
|
270
|
-
def _get_playing_show(self):
|
|
322
|
+
def _get_playing_show(self, filename):
|
|
271
323
|
if not self.active:
|
|
272
324
|
# Don't do anything if the Tracker is disabled
|
|
273
325
|
return (STATE_NOVIDEO, None)
|
|
274
326
|
|
|
275
|
-
if self.plex_enabled:
|
|
276
|
-
filename = self._get_plex_file()
|
|
277
|
-
else:
|
|
278
|
-
filename = self._get_playing_file(self.process_name)
|
|
279
|
-
|
|
280
327
|
if filename:
|
|
281
328
|
if filename == self.last_filename:
|
|
282
329
|
# It's the exact same filename, there's no need to do the processing again
|
trackma/tracker.pyc
CHANGED
|
Binary file
|
trackma/ui/__init__.pyc
CHANGED
|
Binary file
|