trackma 0.6__py3.5.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.
Files changed (60) hide show
  1. EGG-INFO/PKG-INFO +19 -0
  2. EGG-INFO/SOURCES.txt +37 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/entry_points.txt +8 -0
  5. EGG-INFO/not-zip-safe +1 -0
  6. EGG-INFO/requires.txt +10 -0
  7. EGG-INFO/top_level.txt +1 -0
  8. trackma/__init__.py +0 -0
  9. trackma/__pycache__/__init__.cpython-35.pyc +0 -0
  10. trackma/__pycache__/accounts.cpython-35.pyc +0 -0
  11. trackma/__pycache__/data.cpython-35.pyc +0 -0
  12. trackma/__pycache__/engine.cpython-35.pyc +0 -0
  13. trackma/__pycache__/messenger.cpython-35.pyc +0 -0
  14. trackma/__pycache__/tracker.cpython-35.pyc +0 -0
  15. trackma/__pycache__/utils.cpython-35.pyc +0 -0
  16. trackma/accounts.py +145 -0
  17. trackma/data/anilist.jpg +0 -0
  18. trackma/data/hb.jpg +0 -0
  19. trackma/data/icon.png +0 -0
  20. trackma/data/mal.jpg +0 -0
  21. trackma/data/melative.jpg +0 -0
  22. trackma/data/shikimori.jpg +0 -0
  23. trackma/data/vndb.jpg +0 -0
  24. trackma/data.py +597 -0
  25. trackma/engine.py +818 -0
  26. trackma/extras/AnimeInfoExtractor.py +308 -0
  27. trackma/extras/__init__.py +1 -0
  28. trackma/extras/__pycache__/AnimeInfoExtractor.cpython-35.pyc +0 -0
  29. trackma/extras/__pycache__/__init__.cpython-35.pyc +0 -0
  30. trackma/extras/__pycache__/plex.cpython-35.pyc +0 -0
  31. trackma/extras/plex.py +101 -0
  32. trackma/lib/__init__.py +0 -0
  33. trackma/lib/__pycache__/__init__.cpython-35.pyc +0 -0
  34. trackma/lib/__pycache__/lib.cpython-35.pyc +0 -0
  35. trackma/lib/__pycache__/libanilist.cpython-35.pyc +0 -0
  36. trackma/lib/__pycache__/libhb.cpython-35.pyc +0 -0
  37. trackma/lib/__pycache__/libmal.cpython-35.pyc +0 -0
  38. trackma/lib/__pycache__/libmelative.cpython-35.pyc +0 -0
  39. trackma/lib/__pycache__/libshikimori.cpython-35.pyc +0 -0
  40. trackma/lib/__pycache__/libvndb.cpython-35.pyc +0 -0
  41. trackma/lib/lib.py +162 -0
  42. trackma/lib/libanilist.py +406 -0
  43. trackma/lib/libhb.py +237 -0
  44. trackma/lib/libmal.py +707 -0
  45. trackma/lib/libmelative.py +204 -0
  46. trackma/lib/libshikimori.py +340 -0
  47. trackma/lib/libvndb.py +375 -0
  48. trackma/messenger.py +42 -0
  49. trackma/tracker.py +390 -0
  50. trackma/ui/__init__.py +0 -0
  51. trackma/ui/__pycache__/__init__.cpython-35.pyc +0 -0
  52. trackma/ui/__pycache__/cli.cpython-35.pyc +0 -0
  53. trackma/ui/__pycache__/curses.cpython-35.pyc +0 -0
  54. trackma/ui/__pycache__/gtkui.cpython-35.pyc +0 -0
  55. trackma/ui/__pycache__/qtui.cpython-35.pyc +0 -0
  56. trackma/ui/cli.py +835 -0
  57. trackma/ui/curses.py +1061 -0
  58. trackma/ui/gtkui.py +2647 -0
  59. trackma/ui/qtui.py +3046 -0
  60. trackma/utils.py +379 -0
trackma/lib/libvndb.py ADDED
@@ -0,0 +1,375 @@
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
+ import socket
18
+ import json
19
+ import datetime
20
+
21
+ from trackma.lib.lib import lib
22
+ from trackma import utils
23
+
24
+ class libvndb(lib):
25
+ """
26
+ API class to communicate with VNDB
27
+ Implements protocol version 1.
28
+
29
+ Website: http://www.vndb.org
30
+ API documentation: http://vndb.org/d11
31
+ Designed by: Yorhel <contact@vndb.org> (http://vndb.org/u2)
32
+
33
+ """
34
+ name = 'libvndb'
35
+
36
+ api_info = {
37
+ 'name': 'VNDB',
38
+ 'shortname': 'vndb',
39
+ 'version': 'v0.3',
40
+ 'merge': True,
41
+ }
42
+
43
+ default_mediatype = 'vnlist'
44
+ mediatypes = dict()
45
+ mediatypes['vnlist'] = {
46
+ 'has_progress': False,
47
+ 'can_score': True,
48
+ 'can_status': True,
49
+ 'can_add': True,
50
+ 'can_delete': True,
51
+ 'can_update': False,
52
+ 'can_play': False,
53
+ 'statuses': [1, 2, 3, 4, 0],
54
+ 'statuses_dict': { 1: 'Playing', 2: 'Finished', 3: 'Stalled', 4: 'Dropped', 0: 'Unknown' },
55
+ 'score_max': 10,
56
+ 'score_step': 0.1,
57
+ 'status_start': 1,
58
+ 'status_finish': 2,
59
+ }
60
+ mediatypes['wishlist'] = {
61
+ 'has_progress': False,
62
+ 'can_score': True,
63
+ 'can_status': True,
64
+ 'can_add': True,
65
+ 'can_delete': True,
66
+ 'can_update': False,
67
+ 'can_play': False,
68
+ 'statuses': [0, 1, 2, 3],
69
+ 'statuses_dict': { 0: 'High', 1: 'Medium', 2: 'Low', 3: 'Blacklist' },
70
+ 'score_max': 10,
71
+ 'score_step': 0.1,
72
+ 'status_start': None,
73
+ 'status_finish': None,
74
+ }
75
+
76
+ def __init__(self, messenger, account, userconfig):
77
+ """Initializes the useragent through credentials."""
78
+ super(libvndb, self).__init__(messenger, account, userconfig)
79
+
80
+ self.username = account['username']
81
+ self.password = account['password']
82
+ self.logged_in = False
83
+
84
+ def _connect(self):
85
+ """Create TCP socket and connect"""
86
+ try:
87
+ self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
88
+ self.s.connect(("api.vndb.org", 19534))
89
+ except socket.error:
90
+ raise utils.APIError("Connection error.")
91
+
92
+ def _disconnect(self):
93
+ """Shutdown and close the socket"""
94
+ self.s.shutdown(socket.SHUT_RDWR)
95
+ self.s.close()
96
+
97
+ def _sendcmd(self, cmd, options=None):
98
+ """Send a VNDB compatible command and return the response data"""
99
+ msg = cmd
100
+ if options:
101
+ msg += " " + json.dumps(options, separators=(',',':'))
102
+ msg = msg.encode('utf-8')
103
+ msg += b"\x04" # EOT
104
+
105
+ # Send message
106
+ self.s.sendall(msg)
107
+
108
+ # Construct response
109
+ lines = []
110
+ while True:
111
+ line = self.s.recv(65536)
112
+ if line.endswith(b"\x04"):
113
+ line = line.strip(b"\x04")
114
+ lines.append(line)
115
+ response = b"".join(lines).decode('utf-8')
116
+ break
117
+ else:
118
+ lines.append(line)
119
+
120
+ # Separate into response name and JSON data
121
+ _resp = response.split(' ', 1)
122
+ name = _resp[0]
123
+ try:
124
+ data = json.loads(_resp[1])
125
+ except IndexError:
126
+ data = None
127
+
128
+ # Treat error as an exception
129
+ if name == 'error':
130
+ raise utils.APIError(data['msg'])
131
+
132
+ return (name, data)
133
+
134
+ def check_credentials(self):
135
+ """Checks if credentials are correct; returns True or False."""
136
+ if self.logged_in:
137
+ return True
138
+
139
+ self.msg.info(self.name, 'Connecting...')
140
+ self._connect()
141
+
142
+ self.msg.info(self.name, 'Logging in...')
143
+ (name, data) = self._sendcmd('login',
144
+ {'protocol': 1,
145
+ 'client': 'Trackma',
146
+ 'clientver': self.api_info['version'],
147
+ 'username': self.username,
148
+ 'password': self.password,
149
+ })
150
+
151
+ if name == 'ok':
152
+ self.logged_in = True
153
+ self._set_userconfig('username', self.username)
154
+ return True
155
+ else:
156
+ return False
157
+
158
+ def fetch_list(self):
159
+ """Queries the full list from the remote server.
160
+ Returns the list if successful, False otherwise."""
161
+ self.check_credentials()
162
+
163
+ # Retrieve VNs per pages
164
+ page = 1
165
+ vns = dict()
166
+ while True:
167
+ self.msg.info(self.name, 'Downloading list... (%d)' % page)
168
+
169
+ (name, data) = self._sendcmd('get %s basic (uid = 0)' % self.mediatype,
170
+ {'page': page,
171
+ 'results': 25
172
+ })
173
+
174
+ # Something is wrong if we don't get a results response.
175
+ if name != 'results':
176
+ raise utils.APIFatal("Invalid response (%s)" % name)
177
+
178
+ # Process list
179
+ for item in data['items']:
180
+ vnid = item['vn']
181
+ vns[vnid] = utils.show()
182
+ vns[vnid]['id'] = vnid
183
+ vns[vnid]['url'] = self._get_url(vnid)
184
+ vns[vnid]['my_status'] = item.get('status', item.get('priority'))
185
+
186
+ if not data['more']:
187
+ # No more VNs, finish
188
+ break
189
+ page += 1
190
+
191
+ # Retrieve scores per pages
192
+ page = 1
193
+ while True:
194
+ self.msg.info(self.name, 'Downloading votes... (%d)' % page)
195
+
196
+ (name, data) = self._sendcmd('get votelist basic (uid = 0)',
197
+ {'page': page,
198
+ 'results': 25
199
+ })
200
+
201
+ # Something is wrong if we don't get a results response.
202
+ if name != 'results':
203
+ raise utils.APIFatal("Invalid response (%s)" % name)
204
+
205
+ for item in data['items']:
206
+ vnid = item['vn']
207
+ try:
208
+ vns[vnid]['my_score'] = (item['vote'] / 10.0)
209
+ except KeyError:
210
+ # Ghost vote; ignore it
211
+ pass
212
+
213
+ if not data['more']:
214
+ # No more VNs, finish
215
+ break
216
+ page += 1
217
+
218
+ return vns
219
+
220
+ def request_info(self, itemlist):
221
+ self.check_credentials()
222
+
223
+ start = 0
224
+ infos = list()
225
+ remaining = [ show['id'] for show in itemlist ]
226
+ while True:
227
+ self.msg.info(self.name, 'Requesting details...(%d)' % start)
228
+ end = start + 25
229
+
230
+ (name, data) = self._sendcmd('get vn basic,details (id = %s)' % repr(remaining[start:end]),
231
+ {'page': 1,
232
+ 'results': 25,
233
+ })
234
+
235
+ # Something is wrong if we don't get a results response.
236
+ if name != 'results':
237
+ raise utils.APIFatal("Invalid response (%s)" % name)
238
+
239
+ # Process list
240
+ for item in data['items']:
241
+ infos.append(self._parse_info(item))
242
+
243
+ start += 25
244
+ if start >= len(itemlist):
245
+ # We're going beyond the list, finish
246
+ break
247
+
248
+ self._emit_signal('show_info_changed', infos)
249
+ return infos
250
+
251
+ def add_show(self, item):
252
+ # When we try to "update" a VN that isn't in the list, the
253
+ # VNDB API automatically inserts it, so we can use the same
254
+ # command.
255
+ self.update_show(item)
256
+
257
+ def update_show(self, item):
258
+ self.check_credentials()
259
+
260
+ # Update status with set vnlist
261
+ if 'my_status' in item.keys():
262
+ self.msg.info(self.name, 'Updating VN %s (status)...' % item['title'])
263
+
264
+ if self.mediatype == 'wishlist':
265
+ values = {'priority': item['my_status']}
266
+ else:
267
+ values = {'status': item['my_status']}
268
+
269
+ (name, data) = self._sendcmd('set %s %d' % (self.mediatype, item['id']), values)
270
+
271
+ if name != 'ok':
272
+ raise utils.APIError("Invalid response (%s)" % name)
273
+
274
+ # Update vote with set votelist
275
+ if 'my_score' in item.keys():
276
+ self.msg.info(self.name, 'Updating VN %s (vote)...' % item['title'])
277
+
278
+ if item['my_score'] > 0:
279
+ # Add or update vote
280
+ values = {'vote': item['my_score'] * 10}
281
+ else:
282
+ # Delete vote if it's 0
283
+ values = None
284
+
285
+ (name, data) = self._sendcmd('set votelist %d' % item['id'], values)
286
+
287
+ if name != 'ok':
288
+ raise utils.APIError("Invalid response (%s)" % name)
289
+
290
+ def delete_show(self, item):
291
+ self.check_credentials()
292
+
293
+ self.msg.info(self.name, 'Deleting VN %s...' % item['title'])
294
+
295
+ (name, data) = self._sendcmd('set %s %d' % (self.mediatype, item['id']))
296
+
297
+ if name != 'ok':
298
+ raise utils.APIError("Invalid response (%s)" % name)
299
+
300
+ def search(self, criteria):
301
+ self.check_credentials()
302
+
303
+ results = list()
304
+ self.msg.info(self.name, 'Searching for %s...' % criteria)
305
+
306
+ (name, data) = self._sendcmd('get vn basic,details (search ~ "%s")' % criteria,
307
+ {'page': 1,
308
+ 'results': 25,
309
+ })
310
+
311
+ # Something is wrong if we don't get a results response.
312
+ if name != 'results':
313
+ raise utils.APIFatal("Invalid response (%s)" % name)
314
+
315
+ # Process list
316
+ for item in data['items']:
317
+ results.append(self._parse_info(item))
318
+
319
+ self._emit_signal('show_info_changed', results)
320
+
321
+ if not results:
322
+ raise utils.APIError('No results.')
323
+
324
+ return results
325
+
326
+ def logout(self):
327
+ self.msg.info(self.name, 'Disconnecting...')
328
+ self._disconnect()
329
+ self.logged_in = False
330
+
331
+ def merge(self, show, info):
332
+ show['title'] = info['title']
333
+ show['image'] = info.get('image')
334
+ show['start_date'] = info.get('start_date')
335
+ if show['start_date'] and show['start_date'] > datetime.datetime.now():
336
+ show['status'] = utils.STATUS_NOTYET
337
+ else:
338
+ show['status'] = utils.STATUS_FINISHED
339
+
340
+ def _parse_info(self, item):
341
+ start_date = self._str2date(item['released'])
342
+
343
+ info = utils.show()
344
+ info.update({'id': item['id'],
345
+ 'title': item['title'],
346
+ 'image': item['image'],
347
+ 'url': self._get_url(item['id']),
348
+ 'start_date': self._str2date(item['released']),
349
+ 'extra': [
350
+ ('Original Name', item['original']),
351
+ ('Released', item['released']),
352
+ ('Languages', ','.join(item['languages'])),
353
+ ('Original Language', ','.join(item['orig_lang'])),
354
+ ('Platforms', ','.join(item['platforms'])),
355
+ ('Aliases', item['aliases']),
356
+ ('Length', item['length']),
357
+ ('Description', item['description']),
358
+ ('Links', item['links']),
359
+ ]
360
+ })
361
+ return info
362
+
363
+ def _get_url(self, vnid):
364
+ return "http://vndb.org/v%d" % vnid
365
+
366
+ def _str2date(self, string):
367
+ if string != '0000-00-00':
368
+ try:
369
+ return datetime.datetime.strptime(string, "%Y-%m-%d")
370
+ except ValueError:
371
+ return None # Ignore date if it's invalid
372
+ else:
373
+ return None
374
+
375
+
trackma/messenger.py ADDED
@@ -0,0 +1,42 @@
1
+ # This file is part of wMAL.
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
+ TYPE_DEBUG = 1
18
+ TYPE_INFO = 2
19
+ #TYPE_ERROR = 3
20
+ #TYPE_FATAL = 4
21
+ TYPE_WARN = 5
22
+
23
+ class Messenger():
24
+ _handler = None
25
+
26
+ def __init__(self, handler):
27
+ self._handler = handler
28
+
29
+ def set_handler(self, handler):
30
+ self._handler = handler
31
+
32
+ def debug(self, classname, msg):
33
+ if self._handler:
34
+ self._handler(classname, TYPE_DEBUG, msg)
35
+
36
+ def info(self, classname, msg):
37
+ if self._handler:
38
+ self._handler(classname, TYPE_INFO, msg)
39
+
40
+ def warn(self, classname, msg):
41
+ if self._handler:
42
+ self._handler(classname, TYPE_WARN, msg)