trackma 0.7.5__py3.6.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 (73) hide show
  1. EGG-INFO/PKG-INFO +22 -0
  2. EGG-INFO/SOURCES.txt +55 -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 +8 -0
  7. EGG-INFO/top_level.txt +1 -0
  8. trackma/__init__.py +0 -0
  9. trackma/__pycache__/__init__.cpython-36.pyc +0 -0
  10. trackma/__pycache__/accounts.cpython-36.pyc +0 -0
  11. trackma/__pycache__/data.cpython-36.pyc +0 -0
  12. trackma/__pycache__/engine.cpython-36.pyc +0 -0
  13. trackma/__pycache__/messenger.cpython-36.pyc +0 -0
  14. trackma/__pycache__/utils.cpython-36.pyc +0 -0
  15. trackma/accounts.py +145 -0
  16. trackma/data/anilist.jpg +0 -0
  17. trackma/data/icon.png +0 -0
  18. trackma/data/kitsu.png +0 -0
  19. trackma/data/mal.jpg +0 -0
  20. trackma/data/shikimori.jpg +0 -0
  21. trackma/data/vndb.jpg +0 -0
  22. trackma/data.py +620 -0
  23. trackma/engine.py +979 -0
  24. trackma/extras/AnimeInfoExtractor.py +317 -0
  25. trackma/extras/__init__.py +1 -0
  26. trackma/extras/__pycache__/AnimeInfoExtractor.cpython-36.pyc +0 -0
  27. trackma/extras/__pycache__/__init__.cpython-36.pyc +0 -0
  28. trackma/lib/__init__.py +0 -0
  29. trackma/lib/__pycache__/__init__.cpython-36.pyc +0 -0
  30. trackma/lib/__pycache__/lib.cpython-36.pyc +0 -0
  31. trackma/lib/__pycache__/libanilist.cpython-36.pyc +0 -0
  32. trackma/lib/__pycache__/libkitsu.cpython-36.pyc +0 -0
  33. trackma/lib/__pycache__/libmal.cpython-36.pyc +0 -0
  34. trackma/lib/__pycache__/libshikimori.cpython-36.pyc +0 -0
  35. trackma/lib/__pycache__/libvndb.cpython-36.pyc +0 -0
  36. trackma/lib/lib.py +162 -0
  37. trackma/lib/libanilist.py +474 -0
  38. trackma/lib/libkitsu.py +506 -0
  39. trackma/lib/libmal.py +707 -0
  40. trackma/lib/libshikimori.py +340 -0
  41. trackma/lib/libvndb.py +387 -0
  42. trackma/messenger.py +42 -0
  43. trackma/tracker/__init__.py +0 -0
  44. trackma/tracker/__pycache__/__init__.cpython-36.pyc +0 -0
  45. trackma/tracker/__pycache__/inotify.cpython-36.pyc +0 -0
  46. trackma/tracker/__pycache__/inotifyBase.cpython-36.pyc +0 -0
  47. trackma/tracker/__pycache__/plex.cpython-36.pyc +0 -0
  48. trackma/tracker/__pycache__/polling.cpython-36.pyc +0 -0
  49. trackma/tracker/__pycache__/pyinotify.cpython-36.pyc +0 -0
  50. trackma/tracker/__pycache__/tracker.cpython-36.pyc +0 -0
  51. trackma/tracker/__pycache__/win32.cpython-36.pyc +0 -0
  52. trackma/tracker/inotify.py +69 -0
  53. trackma/tracker/inotifyBase.py +107 -0
  54. trackma/tracker/plex.py +144 -0
  55. trackma/tracker/polling.py +55 -0
  56. trackma/tracker/pyinotify.py +90 -0
  57. trackma/tracker/tracker.py +226 -0
  58. trackma/tracker/win32.py +74 -0
  59. trackma/ui/__init__.py +0 -0
  60. trackma/ui/__pycache__/__init__.cpython-36.pyc +0 -0
  61. trackma/ui/__pycache__/cli-single.cpython-36.pyc +0 -0
  62. trackma/ui/__pycache__/cli.cpython-36.pyc +0 -0
  63. trackma/ui/__pycache__/curses.cpython-36.pyc +0 -0
  64. trackma/ui/__pycache__/gtkui.cpython-36.pyc +0 -0
  65. trackma/ui/__pycache__/qt4ui.cpython-36.pyc +0 -0
  66. trackma/ui/__pycache__/qtui.cpython-36.pyc +0 -0
  67. trackma/ui/cli-single.py +3 -0
  68. trackma/ui/cli.py +1035 -0
  69. trackma/ui/curses.py +1156 -0
  70. trackma/ui/gtkui.py +2847 -0
  71. trackma/ui/qt4ui.py +25 -0
  72. trackma/ui/qtui.py +3273 -0
  73. trackma/utils.py +416 -0
@@ -0,0 +1,340 @@
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 json
18
+ import urllib.parse
19
+ import urllib.request
20
+ import socket
21
+ import time
22
+
23
+ from trackma.lib.lib import lib
24
+ from trackma import utils
25
+
26
+ class libshikimori(lib):
27
+ """
28
+ API class to communicate with Shikimori
29
+
30
+ Website: http://shikimori.org
31
+
32
+ messenger: Messenger object to send useful messages to
33
+ """
34
+ name = 'libshikimori'
35
+ msg = None
36
+ logged_in = False
37
+
38
+ api_info = { 'name': 'Shikimori', 'shortname': 'shikimori', 'version': '1', 'merge': False }
39
+ mediatypes = dict()
40
+ mediatypes['anime'] = {
41
+ 'has_progress': True,
42
+ 'can_add': True,
43
+ 'can_delete': True,
44
+ 'can_score': True,
45
+ 'can_status': True,
46
+ 'can_update': True,
47
+ 'can_play': True,
48
+ 'status_start': 1,
49
+ 'status_finish': 2,
50
+ 'statuses': [1, 2, 3, 9, 4, 0],
51
+ 'statuses_dict': {
52
+ 1: 'Watching',
53
+ 2: 'Completed',
54
+ 3: 'On-Hold',
55
+ 9: 'Rewatching',
56
+ 4: 'Dropped',
57
+ 0: 'Plan to Watch'
58
+ },
59
+ 'score_max': 10,
60
+ 'score_step': 1,
61
+ }
62
+ mediatypes['manga'] = {
63
+ 'has_progress': True,
64
+ 'can_add': True,
65
+ 'can_delete': True,
66
+ 'can_score': True,
67
+ 'can_status': True,
68
+ 'can_update': True,
69
+ 'can_play': False,
70
+ 'status_start': 1,
71
+ 'status_finish': 2,
72
+ 'statuses': [1, 2, 3, 9, 4, 0],
73
+ 'statuses_dict': {
74
+ 1: 'Reading',
75
+ 2: 'Completed',
76
+ 3: 'On-Hold',
77
+ 9: 'Rereading',
78
+ 4: 'Dropped',
79
+ 0: 'Plan to Read'
80
+ },
81
+ 'score_max': 10,
82
+ 'score_step': 1,
83
+ }
84
+ default_mediatype = 'anime'
85
+
86
+ # Supported signals for the data handler
87
+ signals = { 'show_info_changed': None, }
88
+
89
+ url = "http://shikimori.org"
90
+
91
+ def __init__(self, messenger, account, userconfig):
92
+ """Initializes the API"""
93
+ super(libshikimori, self).__init__(messenger, account, userconfig)
94
+
95
+ self.username = account['username']
96
+ self.password = account['password']
97
+ self.userid = userconfig['userid']
98
+
99
+ if not self.password:
100
+ raise utils.APIFatal("No password.")
101
+
102
+ if self.mediatype == 'manga':
103
+ self.total_str = "chapters"
104
+ self.watched_str = "chapters"
105
+ self.airing_str = "publishing_status"
106
+ self.status_translate = {
107
+ 'publishing': utils.STATUS_AIRING,
108
+ 'finished': utils.STATUS_FINISHED,
109
+ 'not yet published': utils.STATUS_NOTYET,
110
+ 'cancelled': utils.STATUS_CANCELLED,
111
+ }
112
+ else:
113
+ self.total_str = "episodes"
114
+ self.watched_str = "episodes"
115
+ self.airing_str = "airing_status"
116
+ self.status_translate = {
117
+ 'currently airing': utils.STATUS_AIRING,
118
+ 'finished airing': utils.STATUS_FINISHED,
119
+ 'not yet aired': utils.STATUS_NOTYET,
120
+ 'cancelled': utils.STATUS_CANCELLED,
121
+ }
122
+
123
+ #handler=urllib.request.HTTPHandler(debuglevel=1)
124
+ #self.opener = urllib.request.build_opener(handler)
125
+ self.opener = urllib.request.build_opener()
126
+ self.opener.addheaders = [('User-agent', 'Trackma/0.4')]
127
+
128
+ def _request(self, method, url, get=None, post=None, jsondata=None, auth=False):
129
+ if get:
130
+ url = "{}?{}".format(url, urllib.parse.urlencode(get))
131
+ if post:
132
+ post = urllib.parse.urlencode(post)
133
+ if jsondata:
134
+ post = json.dumps(jsondata, separators=(',',':')).encode('utf-8')
135
+
136
+ request = urllib.request.Request(self.url + url, post)
137
+ request.get_method = lambda: method
138
+
139
+ if auth:
140
+ request.add_header('Content-Type', 'application/json')
141
+ request.add_header('X-User-Nickname', self.username)
142
+ request.add_header('X-User-Api-Access-Token', self._get_userconfig('access_token'))
143
+
144
+ try:
145
+ response = self.opener.open(request, timeout = 10)
146
+ return json.loads(response.read().decode('utf-8'))
147
+ except urllib.request.HTTPError as e:
148
+ if e.code == 400:
149
+ raise utils.APIError("400")
150
+ else:
151
+ raise utils.APIError("Connection error: %s" % e)
152
+ except socket.timeout:
153
+ raise utils.APIError("Connection timed out.")
154
+ except ValueError:
155
+ pass # No JSON data
156
+
157
+ def _request_access_token(self):
158
+ self.msg.info(self.name, 'Requesting access token...')
159
+ param = {
160
+ 'nickname': self.username,
161
+ 'password': self.password,
162
+ }
163
+ data = self._request("POST", "/api/access_token", get=param)
164
+
165
+ self._set_userconfig('access_token', data['api_access_token'])
166
+
167
+ self.logged_in = True
168
+ self._refresh_user_info()
169
+ self._emit_signal('userconfig_changed')
170
+
171
+ def _refresh_user_info(self):
172
+ self.msg.info(self.name, 'Refreshing user details...')
173
+
174
+ data = self._request("GET", "/api/users/whoami", auth=True)
175
+
176
+ self._set_userconfig('userid', data['id'])
177
+ self._set_userconfig('username', data['nickname'])
178
+
179
+ self.userid = data['id']
180
+
181
+ def check_credentials(self):
182
+ """
183
+ Log into Shikimori. Ask for the request token if necessary.
184
+ """
185
+ timestamp = int(time.time())
186
+
187
+ if not self._get_userconfig('access_token'):
188
+ self._request_access_token()
189
+ else:
190
+ self.logged_in = True
191
+ return True
192
+
193
+ def fetch_list(self):
194
+ self.check_credentials()
195
+ self.msg.info(self.name, 'Downloading list...')
196
+
197
+ data = self._request("GET", "/api/users/{}/{}_rates".format(self.userid, self.mediatype))
198
+
199
+ showlist = {}
200
+
201
+ #with open('list', 'w') as f:
202
+ # json.dump(data, f, indent=2)
203
+
204
+ for item in data:
205
+ show = utils.show()
206
+ showid = item[self.mediatype]['id']
207
+ show.update({
208
+ 'id': showid,
209
+ 'my_id': item['id'],
210
+ 'title': item[self.mediatype]['name'],
211
+ 'aliases': [item[self.mediatype]['russian']],
212
+ #'type': item[self.mediatype]['type'],
213
+ #'status': self.status_translate[item[self.mediatype][self.airing_str]],
214
+ 'my_id': item['id'],
215
+ 'my_progress': item[self.watched_str],
216
+ 'my_status': item['status'],
217
+ 'my_score': item['score'],
218
+ 'total': item[self.mediatype][self.total_str],
219
+ 'url': self.url + item[self.mediatype]['url'],
220
+ 'image': self.url + item[self.mediatype]['image']['original'],
221
+ 'image_thumb': self.url + item[self.mediatype]['image']['preview'],
222
+ })
223
+
224
+ showlist[showid] = show
225
+
226
+ return showlist
227
+
228
+ def add_show(self, item):
229
+ self.check_credentials()
230
+ self.msg.info(self.name, "Adding item %s..." % item['title'])
231
+ return self._update_entry(item, "POST")
232
+
233
+ def update_show(self, item):
234
+ self.check_credentials()
235
+ self.msg.info(self.name, "Updating item %s..." % item['title'])
236
+ return self._update_entry(item, "PUT")
237
+
238
+ def delete_show(self, item):
239
+ self.check_credentials()
240
+ self.msg.info(self.name, "Deleting item %s..." % item['title'])
241
+
242
+ data = self._request("DELETE", "/api/user_rates/{}".format(item['my_id']), auth=True)
243
+
244
+ def search(self, criteria):
245
+ self.check_credentials()
246
+
247
+ self.msg.info(self.name, "Searching for {}...".format(criteria))
248
+ param = {'q': criteria}
249
+ try:
250
+ data = self._request("GET", "/api/{}s/search".format(self.mediatype), get=param)
251
+ except ValueError:
252
+ # An empty document, without any JSON, is returned
253
+ # when there are no results.
254
+ return []
255
+
256
+ showlist = []
257
+
258
+ for item in data:
259
+ show = utils.show()
260
+ showid = item['id']
261
+ show.update({
262
+ 'id': showid,
263
+ 'title': item['name'],
264
+ 'aliases': [item['russian']],
265
+ 'type': item.get('kind', ''),
266
+ #'status': item[self.airing_str],
267
+ 'status': 0,
268
+ 'my_status': self.media_info()['status_start'],
269
+ 'total': item[self.total_str],
270
+ 'image': self.url + item['image']['original'],
271
+ 'image_thumb': self.url + item['image']['preview'],
272
+ })
273
+
274
+ showlist.append( show )
275
+
276
+ return showlist
277
+
278
+ def request_info(self, itemlist):
279
+ self.check_credentials()
280
+ infolist = []
281
+
282
+ for show in itemlist:
283
+ data = self._request("GET", "/api/{}s/{}".format(self.mediatype, show['id']))
284
+ infolist.append( self._parse_info(data) )
285
+
286
+ self._emit_signal('show_info_changed', infolist)
287
+ return infolist
288
+
289
+ def media_info(self):
290
+ """Return information about the currently selected mediatype."""
291
+ return self.mediatypes[self.mediatype]
292
+
293
+ def _update_entry(self, item, method):
294
+ # Note: This method returns the newly added or modified item ID (my_id)
295
+ if method == 'POST':
296
+ user_rate = {
297
+ 'user_id': self.userid,
298
+ 'target_id': item['id'],
299
+ 'target_type': self.mediatype.capitalize(),
300
+ }
301
+ dest_url = "/api/user_rates"
302
+ else:
303
+ #user_rate = {'score': 0, 'status': 0, 'episodes': 0, 'volumes': 0, 'chapters': 0, 'text': '', 'rewatches': 0}
304
+ user_rate = {}
305
+ dest_url = "/api/user_rates/{}".format(item['my_id'])
306
+
307
+ if 'my_progress' in item:
308
+ user_rate[self.watched_str] = item['my_progress']
309
+ if 'my_status' in item:
310
+ user_rate['status'] = item['my_status']
311
+ if 'my_score' in item:
312
+ user_rate['score'] = item['my_score']
313
+
314
+ values = {'user_rate': user_rate}
315
+ data = self._request(method, dest_url, jsondata=values, auth=True)
316
+ return data['id']
317
+
318
+ def _parse_info(self, item):
319
+ info = utils.show()
320
+ info.update({
321
+ 'id': item['id'],
322
+ 'title': item['name'],
323
+ 'status': 0,
324
+ 'image': self.url + item['image']['original'],
325
+ 'url': self.url + item['url'],
326
+ 'extra': [
327
+ ('Description', item.get('description')),
328
+ #('Genres', item.get('genres')),
329
+ ('Type', item.get('kind').capitalize()),
330
+ ('Average score', item.get('score')),
331
+ ('Russian title', item.get('russian')),
332
+ ('Japanese title', item.get('japanese')[0]),
333
+ ('English title', item.get('english')),
334
+ ]
335
+ })
336
+ return info
337
+
338
+ def _c(self, s):
339
+ return 0 if s is None else s
340
+