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