trackma 0.6.2__py3.4.egg → 0.7.1__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.
- EGG-INFO/PKG-INFO +1 -1
- EGG-INFO/SOURCES.txt +10 -6
- EGG-INFO/requires.txt +0 -2
- trackma/__pycache__/__init__.cpython-34.pyc +0 -0
- trackma/__pycache__/accounts.cpython-34.pyc +0 -0
- trackma/__pycache__/data.cpython-34.pyc +0 -0
- trackma/__pycache__/engine.cpython-34.pyc +0 -0
- trackma/__pycache__/messenger.cpython-34.pyc +0 -0
- trackma/__pycache__/utils.cpython-34.pyc +0 -0
- trackma/data/kitsu.png +0 -0
- trackma/data.py +26 -16
- trackma/engine.py +68 -17
- trackma/extras/AnimeInfoExtractor.py +1 -1
- trackma/extras/__pycache__/AnimeInfoExtractor.cpython-34.pyc +0 -0
- trackma/extras/__pycache__/__init__.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/__init__.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/lib.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/libanilist.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/libkitsu.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/libmal.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/libshikimori.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/libvndb.cpython-34.pyc +0 -0
- trackma/lib/libanilist.py +3 -3
- trackma/lib/libkitsu.py +507 -0
- trackma/lib/libmal.py +6 -6
- trackma/lib/libshikimori.py +3 -3
- trackma/lib/libvndb.py +12 -9
- trackma/messenger.py +1 -1
- trackma/tracker/__init__.py +0 -0
- trackma/tracker/__pycache__/__init__.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/inotify.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/inotifyBase.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/plex.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/polling.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/pyinotify.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/tracker.cpython-34.pyc +0 -0
- trackma/tracker/__pycache__/win32.cpython-34.pyc +0 -0
- trackma/tracker/inotify.py +69 -0
- trackma/tracker/inotifyBase.py +110 -0
- trackma/tracker/plex.py +106 -0
- trackma/tracker/polling.py +55 -0
- trackma/tracker/pyinotify.py +90 -0
- trackma/tracker/tracker.py +221 -0
- trackma/tracker/win32.py +74 -0
- trackma/ui/__pycache__/__init__.cpython-34.pyc +0 -0
- trackma/ui/__pycache__/cli.cpython-34.pyc +0 -0
- trackma/ui/__pycache__/curses.cpython-34.pyc +0 -0
- trackma/ui/__pycache__/gtkui.cpython-34.pyc +0 -0
- trackma/ui/__pycache__/qt4ui.cpython-34.pyc +0 -0
- trackma/ui/__pycache__/qtui.cpython-34.pyc +0 -0
- trackma/ui/cli.py +110 -13
- trackma/ui/curses.py +88 -30
- trackma/ui/gtkui.py +120 -58
- trackma/ui/qtui.py +161 -49
- trackma/utils.py +16 -9
- trackma/__pycache__/tracker.cpython-34.pyc +0 -0
- trackma/data/hb.jpg +0 -0
- trackma/data/melative.jpg +0 -0
- trackma/extras/__pycache__/plex.cpython-34.pyc +0 -0
- trackma/extras/plex.py +0 -101
- trackma/lib/__pycache__/libhb.cpython-34.pyc +0 -0
- trackma/lib/__pycache__/libmelative.cpython-34.pyc +0 -0
- trackma/lib/libhb.py +0 -239
- trackma/lib/libmelative.py +0 -204
- trackma/tracker.py +0 -430
trackma/lib/libkitsu.py
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is part of Trackma.
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU General Public License
|
|
15
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
import datetime
|
|
19
|
+
import time
|
|
20
|
+
import urllib.parse
|
|
21
|
+
import urllib.request
|
|
22
|
+
import json
|
|
23
|
+
import gzip
|
|
24
|
+
import socket
|
|
25
|
+
|
|
26
|
+
#import http.client
|
|
27
|
+
#http.client.HTTPConnection.debuglevel = 1
|
|
28
|
+
|
|
29
|
+
from trackma.lib.lib import lib
|
|
30
|
+
from trackma import utils
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class libkitsu(lib):
|
|
34
|
+
"""
|
|
35
|
+
API class to communicate with Kitsu
|
|
36
|
+
Should inherit a base library interface.
|
|
37
|
+
|
|
38
|
+
Website: https://kitsu.io/
|
|
39
|
+
API documentation:
|
|
40
|
+
Designed by:
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
name = 'libkitsu'
|
|
44
|
+
user_agent = 'Trackma/{}'.format(utils.VERSION)
|
|
45
|
+
|
|
46
|
+
auth = ''
|
|
47
|
+
logged_in = False
|
|
48
|
+
|
|
49
|
+
api_info = {
|
|
50
|
+
'name': 'Kitsu',
|
|
51
|
+
'shortname': 'kitsu',
|
|
52
|
+
'version': 'v0.3',
|
|
53
|
+
'merge': True
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
default_mediatype = 'anime'
|
|
57
|
+
default_statuses = ['current', 'completed', 'on_hold', 'dropped', 'planned']
|
|
58
|
+
default_statuses_dict = {
|
|
59
|
+
'current': 'Watching',
|
|
60
|
+
'completed': 'Completed',
|
|
61
|
+
'on_hold': 'On Hold',
|
|
62
|
+
'dropped': 'Dropped',
|
|
63
|
+
'planned': 'Plan to Watch'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
mediatypes = dict()
|
|
67
|
+
mediatypes['anime'] = {
|
|
68
|
+
'has_progress': True,
|
|
69
|
+
'can_add': True,
|
|
70
|
+
'can_delete': True,
|
|
71
|
+
'can_score': True,
|
|
72
|
+
'can_status': True,
|
|
73
|
+
'can_update': True,
|
|
74
|
+
'can_play': True,
|
|
75
|
+
'status_start': 'current',
|
|
76
|
+
'status_finish': 'completed',
|
|
77
|
+
'statuses': default_statuses,
|
|
78
|
+
'statuses_dict': default_statuses_dict,
|
|
79
|
+
'score_max': 5,
|
|
80
|
+
'score_step': 0.5,
|
|
81
|
+
}
|
|
82
|
+
mediatypes['manga'] = {
|
|
83
|
+
'has_progress': True,
|
|
84
|
+
'can_add': True,
|
|
85
|
+
'can_delete': True,
|
|
86
|
+
'can_score': True,
|
|
87
|
+
'can_status': True,
|
|
88
|
+
'can_update': True,
|
|
89
|
+
'can_play': False,
|
|
90
|
+
'status_start': 'current',
|
|
91
|
+
'status_finish': 'completed',
|
|
92
|
+
'statuses': default_statuses,
|
|
93
|
+
'statuses_dict': default_statuses_dict,
|
|
94
|
+
'score_max': 5,
|
|
95
|
+
'score_step': 0.5,
|
|
96
|
+
}
|
|
97
|
+
mediatypes['drama'] = {
|
|
98
|
+
'has_progress': True,
|
|
99
|
+
'can_add': True,
|
|
100
|
+
'can_delete': True,
|
|
101
|
+
'can_score': True,
|
|
102
|
+
'can_status': True,
|
|
103
|
+
'can_update': True,
|
|
104
|
+
'can_play': True,
|
|
105
|
+
'status_start': 'current',
|
|
106
|
+
'status_finish': 'completed',
|
|
107
|
+
'statuses': default_statuses,
|
|
108
|
+
'statuses_dict': default_statuses_dict,
|
|
109
|
+
'score_max': 5,
|
|
110
|
+
'score_step': 0.5,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
url = 'https://kitsu.io/api'
|
|
114
|
+
prefix = 'https://kitsu.io/api/edge'
|
|
115
|
+
|
|
116
|
+
# TODO : These values are previsional.
|
|
117
|
+
_client_id = 'dd031b32d2f56c990b1425efe6c42ad847e7fe3ab46bf1299f05ecd856bdb7dd'
|
|
118
|
+
_client_secret = '54d7307928f63414defd96399fc31ba847961ceaecef3a5fd93144e960c0e151'
|
|
119
|
+
|
|
120
|
+
status_translate = {'Currently Airing': utils.STATUS_AIRING,
|
|
121
|
+
'Finished Airing': utils.STATUS_FINISHED,
|
|
122
|
+
'Not Yet Aired': utils.STATUS_NOTYET}
|
|
123
|
+
|
|
124
|
+
def __init__(self, messenger, account, userconfig):
|
|
125
|
+
"""Initializes the useragent through credentials."""
|
|
126
|
+
super(libkitsu, self).__init__(messenger, account, userconfig)
|
|
127
|
+
|
|
128
|
+
self.username = account['username']
|
|
129
|
+
self.password = account['password']
|
|
130
|
+
|
|
131
|
+
# Build opener with the mashape API key
|
|
132
|
+
self.opener = urllib.request.build_opener()
|
|
133
|
+
self.opener.addheaders = [
|
|
134
|
+
('User-Agent', self.user_agent),
|
|
135
|
+
('Accept', 'application/vnd.api+json'),
|
|
136
|
+
('Accept-Encoding', 'gzip'),
|
|
137
|
+
('Accept-Charset', 'utf-8'),
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
def _request(self, method, url, get=None, post=None, body=None, auth=False):
|
|
141
|
+
content_type = None
|
|
142
|
+
|
|
143
|
+
if get:
|
|
144
|
+
url += "?%s" % urllib.parse.urlencode(get)
|
|
145
|
+
if post:
|
|
146
|
+
post = urllib.parse.urlencode(post).encode('utf-8')
|
|
147
|
+
content_type = 'application/x-www-form-urlencoded'
|
|
148
|
+
if body:
|
|
149
|
+
post = body.encode('utf-8')
|
|
150
|
+
content_type = 'application/vnd.api+json'
|
|
151
|
+
|
|
152
|
+
request = urllib.request.Request(url, post)
|
|
153
|
+
request.get_method = lambda: method
|
|
154
|
+
|
|
155
|
+
if content_type:
|
|
156
|
+
request.add_header('Content-Type', content_type)
|
|
157
|
+
|
|
158
|
+
if auth:
|
|
159
|
+
request.add_header('Authorization', '{0} {1}'.format(
|
|
160
|
+
self._get_userconfig('token_type').capitalize(),
|
|
161
|
+
self._get_userconfig('access_token'),
|
|
162
|
+
))
|
|
163
|
+
|
|
164
|
+
try:
|
|
165
|
+
response = self.opener.open(request)
|
|
166
|
+
|
|
167
|
+
# The response most probably will be gzipped so we
|
|
168
|
+
# have to take care of that first
|
|
169
|
+
if response.info().get('content-encoding') == 'gzip':
|
|
170
|
+
return gzip.GzipFile(fileobj=response).read().decode('utf-8')
|
|
171
|
+
else:
|
|
172
|
+
return response.read().decode('utf-8')
|
|
173
|
+
except urllib.request.HTTPError as e:
|
|
174
|
+
if e.code == 401:
|
|
175
|
+
raise utils.APIError("Incorrect credentials.")
|
|
176
|
+
else:
|
|
177
|
+
api_error = self._parse_errors(e)
|
|
178
|
+
if api_error:
|
|
179
|
+
raise utils.APIError("API error: %s" % api_error)
|
|
180
|
+
else:
|
|
181
|
+
raise utils.APIError("Connection error: %s" % e)
|
|
182
|
+
except urllib.request.URLError as e:
|
|
183
|
+
raise utils.APIError("URL error: %s" % e)
|
|
184
|
+
except socket.timeout:
|
|
185
|
+
raise utils.APIError("Operation timed out.")
|
|
186
|
+
|
|
187
|
+
def _parse_errors(self, e):
|
|
188
|
+
try:
|
|
189
|
+
data = json.loads(e.read().decode('utf-8'))
|
|
190
|
+
errors = ""
|
|
191
|
+
for error in data['errors']:
|
|
192
|
+
errors += "{}: {}".format(error['code'], error['detail'])
|
|
193
|
+
|
|
194
|
+
return errors
|
|
195
|
+
except:
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
def _request_access_token(self, refresh=False):
|
|
199
|
+
params = {
|
|
200
|
+
'client_id': self._client_id,
|
|
201
|
+
'client_secret': self._client_secret,
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if refresh:
|
|
205
|
+
self.msg.info(self.name, 'Refreshing access token...')
|
|
206
|
+
|
|
207
|
+
params['grant_type'] = 'refresh_token'
|
|
208
|
+
params['refresh_token'] = self._get_userconfig('refresh_token')
|
|
209
|
+
else:
|
|
210
|
+
self.msg.info(self.name, 'Requesting access token...')
|
|
211
|
+
|
|
212
|
+
params['grant_type'] = 'password'
|
|
213
|
+
params['username'] = self.username
|
|
214
|
+
params['password'] = self.password
|
|
215
|
+
|
|
216
|
+
response = self._request('POST', self.url + '/oauth/token', post=params)
|
|
217
|
+
data = json.loads(response)
|
|
218
|
+
|
|
219
|
+
timestamp = int(time.time())
|
|
220
|
+
|
|
221
|
+
self._set_userconfig('access_token', data['access_token'])
|
|
222
|
+
self._set_userconfig('token_type', data['token_type'])
|
|
223
|
+
self._set_userconfig('expires', timestamp + data['expires_in'])
|
|
224
|
+
self._set_userconfig('refresh_token', data['refresh_token'])
|
|
225
|
+
|
|
226
|
+
self.logged_in = True
|
|
227
|
+
self._refresh_user_info()
|
|
228
|
+
self._emit_signal('userconfig_changed')
|
|
229
|
+
|
|
230
|
+
def _refresh_user_info(self):
|
|
231
|
+
self.msg.info(self.name, 'Refreshing user details...')
|
|
232
|
+
params = {
|
|
233
|
+
"filter[name]": self.username,
|
|
234
|
+
}
|
|
235
|
+
data = self._request('GET', self.prefix + "/users", get=params)
|
|
236
|
+
json_data = json.loads(data)
|
|
237
|
+
user = json_data['data'][0]
|
|
238
|
+
|
|
239
|
+
# Parse user information
|
|
240
|
+
self._set_userconfig('userid', user['id'])
|
|
241
|
+
self._set_userconfig('username', user['attributes']['name'])
|
|
242
|
+
|
|
243
|
+
def check_credentials(self):
|
|
244
|
+
"""
|
|
245
|
+
Log into Kitsu. If there isn't an acess token, request it, or
|
|
246
|
+
refresh it if necessary.
|
|
247
|
+
"""
|
|
248
|
+
timestamp = int(time.time())
|
|
249
|
+
|
|
250
|
+
if not self._get_userconfig('access_token'):
|
|
251
|
+
self._request_access_token(False)
|
|
252
|
+
elif (timestamp+60) > self._get_userconfig('expires'):
|
|
253
|
+
self._request_access_token(True)
|
|
254
|
+
else:
|
|
255
|
+
self.logged_in = True
|
|
256
|
+
|
|
257
|
+
return True
|
|
258
|
+
|
|
259
|
+
def fetch_list(self):
|
|
260
|
+
"""Queries the full list from the remote server.
|
|
261
|
+
Returns the list if successful, False otherwise."""
|
|
262
|
+
self.check_credentials()
|
|
263
|
+
self.msg.info(self.name, 'Downloading list...')
|
|
264
|
+
|
|
265
|
+
try:
|
|
266
|
+
showlist = dict()
|
|
267
|
+
infolist = list()
|
|
268
|
+
|
|
269
|
+
# Get first page and continue from there
|
|
270
|
+
params = {
|
|
271
|
+
"filter[user_id]": self._get_userconfig('userid'),
|
|
272
|
+
"filter[kind]": self.mediatype,
|
|
273
|
+
#"include": self.mediatype, # TODO : This returns a 500 for some reason.
|
|
274
|
+
"include": "media",
|
|
275
|
+
# TODO : List for manga should be different
|
|
276
|
+
"fields[anime]": "id,slug,canonicalTitle,titles,episodeCount,synopsis,subtype,posterImage,startDate,endDate",
|
|
277
|
+
"page[limit]": "250",
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
url = "{}/library-entries?{}".format(self.prefix, urllib.parse.urlencode(params))
|
|
281
|
+
i = 1
|
|
282
|
+
|
|
283
|
+
while url:
|
|
284
|
+
self.msg.info(self.name, 'Getting page {}...'.format(i))
|
|
285
|
+
|
|
286
|
+
data = self._request('GET', url)
|
|
287
|
+
data_json = json.loads(data)
|
|
288
|
+
|
|
289
|
+
#print(json.dumps(data_json, sort_keys=True, indent=2))
|
|
290
|
+
#return []
|
|
291
|
+
|
|
292
|
+
entries = data_json['data']
|
|
293
|
+
links = data_json['links']
|
|
294
|
+
|
|
295
|
+
for entry in entries:
|
|
296
|
+
# TODO : Including the mediatype returns a 500 for some reason.
|
|
297
|
+
#showid = int(entry['relationships'][self.mediatype]['data']['id'])
|
|
298
|
+
showid = int(entry['relationships']['media']['data']['id'])
|
|
299
|
+
status = entry['attributes']['status']
|
|
300
|
+
rating = entry['attributes']['rating']
|
|
301
|
+
|
|
302
|
+
showlist[showid] = utils.show()
|
|
303
|
+
showlist[showid].update({
|
|
304
|
+
'id': showid,
|
|
305
|
+
'my_id': entry['id'],
|
|
306
|
+
'my_progress': entry['attributes']['progress'],
|
|
307
|
+
'my_score': float(rating) if rating is not None else 0.0,
|
|
308
|
+
'my_status': entry['attributes']['status'],
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
if 'included' in data_json:
|
|
312
|
+
medias = data_json['included']
|
|
313
|
+
for media in medias:
|
|
314
|
+
info = self._parse_info(media)
|
|
315
|
+
infolist.append(info)
|
|
316
|
+
|
|
317
|
+
self._emit_signal('show_info_changed', infolist)
|
|
318
|
+
|
|
319
|
+
url = links.get('next')
|
|
320
|
+
i += 1
|
|
321
|
+
|
|
322
|
+
return showlist
|
|
323
|
+
except urllib.request.HTTPError as e:
|
|
324
|
+
raise utils.APIError("Error getting list.")
|
|
325
|
+
|
|
326
|
+
def merge(self, show, info):
|
|
327
|
+
show['title'] = info['title']
|
|
328
|
+
show['aliases'] = info['aliases']
|
|
329
|
+
show['url'] = info['url']
|
|
330
|
+
show['total'] = info['total']
|
|
331
|
+
show['image'] = info['image']
|
|
332
|
+
|
|
333
|
+
show['image_thumb'] = info['image_thumb']
|
|
334
|
+
|
|
335
|
+
show['start_date'] = info['start_date']
|
|
336
|
+
show['end_date'] = info['end_date']
|
|
337
|
+
show['status'] = info['status']
|
|
338
|
+
|
|
339
|
+
def request_info(self, item_list):
|
|
340
|
+
print("These are missing: " + repr(item_list))
|
|
341
|
+
# TODO implement
|
|
342
|
+
raise NotImplementedError
|
|
343
|
+
|
|
344
|
+
def add_show(self, item):
|
|
345
|
+
"""Adds a new show in the server"""
|
|
346
|
+
self.check_credentials()
|
|
347
|
+
self.msg.info(self.name, "Adding show %s..." % item['title'])
|
|
348
|
+
|
|
349
|
+
data = self._build_data(item)
|
|
350
|
+
|
|
351
|
+
try:
|
|
352
|
+
data = self._request('POST', self.prefix + "/library-entries", body=data, auth=True)
|
|
353
|
+
|
|
354
|
+
data_json = json.loads(data)
|
|
355
|
+
return int(data_json['data']['id'])
|
|
356
|
+
except urllib.request.HTTPError as e:
|
|
357
|
+
raise utils.APIError('Error adding: ' + str(e.code))
|
|
358
|
+
|
|
359
|
+
def update_show(self, item):
|
|
360
|
+
"""Sends a show update to the server"""
|
|
361
|
+
self.check_credentials()
|
|
362
|
+
self.msg.info(self.name, "Updating show %s..." % item['title'])
|
|
363
|
+
|
|
364
|
+
data = self._build_data(item)
|
|
365
|
+
|
|
366
|
+
try:
|
|
367
|
+
self._request('PATCH', self.prefix + "/library-entries/%s" % item['my_id'], body=data, auth=True)
|
|
368
|
+
except urllib.request.HTTPError as e:
|
|
369
|
+
raise utils.APIError('Error updating: ' + str(e.code))
|
|
370
|
+
|
|
371
|
+
def delete_show(self, item):
|
|
372
|
+
"""Sends a show delete to the server"""
|
|
373
|
+
self.check_credentials()
|
|
374
|
+
self.msg.info(self.name, "Deleting show %s..." % item['title'])
|
|
375
|
+
|
|
376
|
+
try:
|
|
377
|
+
self._request('DELETE', self.prefix + "/library-entries/%s" % item['my_id'], auth=True)
|
|
378
|
+
except urllib.request.HTTPError as e:
|
|
379
|
+
raise utils.APIError('Error deleting: ' + str(e.code))
|
|
380
|
+
|
|
381
|
+
def search(self, query):
|
|
382
|
+
self.msg.info(self.name, "Searching for %s..." % query)
|
|
383
|
+
|
|
384
|
+
values = {
|
|
385
|
+
"filter[text]": query,
|
|
386
|
+
"page[limit]": 20,
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
try:
|
|
390
|
+
data = self._request('GET', self.prefix + "/" + self.mediatype, get=values)
|
|
391
|
+
shows = json.loads(data)
|
|
392
|
+
|
|
393
|
+
infolist = []
|
|
394
|
+
for media in shows['data']:
|
|
395
|
+
info = self._parse_info(media)
|
|
396
|
+
infolist.append(info)
|
|
397
|
+
|
|
398
|
+
self._emit_signal('show_info_changed', infolist)
|
|
399
|
+
|
|
400
|
+
if not infolist:
|
|
401
|
+
raise utils.APIError('No results.')
|
|
402
|
+
|
|
403
|
+
return infolist
|
|
404
|
+
except urllib.request.HTTPError as e:
|
|
405
|
+
raise utils.APIError('Error searching: ' + str(e.code))
|
|
406
|
+
|
|
407
|
+
def _build_data(self, item):
|
|
408
|
+
values = {'data': {
|
|
409
|
+
'type': 'libraryEntries',
|
|
410
|
+
'attributes': {},
|
|
411
|
+
'relationships': {
|
|
412
|
+
'media': {
|
|
413
|
+
'data': {
|
|
414
|
+
'type': self.mediatype,
|
|
415
|
+
'id': item['id'],
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
'user': {
|
|
419
|
+
'data': {
|
|
420
|
+
'type': 'users',
|
|
421
|
+
'id': self._get_userconfig('userid'),
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
# Update necessary keys
|
|
429
|
+
if item['my_id']:
|
|
430
|
+
values['data']['id'] = str(item['my_id'])
|
|
431
|
+
if 'my_progress' in item:
|
|
432
|
+
values['data']['attributes']['progress'] = item['my_progress']
|
|
433
|
+
if 'my_status' in item:
|
|
434
|
+
values['data']['attributes']['status'] = item['my_status']
|
|
435
|
+
if 'my_score' in item:
|
|
436
|
+
values['data']['attributes']['rating'] = item['my_score'] or None
|
|
437
|
+
|
|
438
|
+
return json.dumps(values)
|
|
439
|
+
|
|
440
|
+
def _str2date(self, string):
|
|
441
|
+
if string is None:
|
|
442
|
+
return None
|
|
443
|
+
|
|
444
|
+
try:
|
|
445
|
+
return datetime.datetime.strptime(string, "%Y-%m-%d")
|
|
446
|
+
except:
|
|
447
|
+
self.msg.debug(self.name, 'Invalid date {}'.format(string))
|
|
448
|
+
return None # Ignore date if it's invalid
|
|
449
|
+
|
|
450
|
+
def _guess_status(self, start_date, end_date):
|
|
451
|
+
# Try to guess show status by checking start and end dates
|
|
452
|
+
now = datetime.datetime.now()
|
|
453
|
+
|
|
454
|
+
if end_date and end_date < now:
|
|
455
|
+
return utils.STATUS_FINISHED
|
|
456
|
+
|
|
457
|
+
if start_date:
|
|
458
|
+
if start_date > now:
|
|
459
|
+
return utils.STATUS_NOTYET
|
|
460
|
+
else:
|
|
461
|
+
return utils.STATUS_AIRING
|
|
462
|
+
|
|
463
|
+
# Safe to assume dates haven't even been announced yet
|
|
464
|
+
return utils.STATUS_NOTYET
|
|
465
|
+
|
|
466
|
+
def _parse_info(self, media):
|
|
467
|
+
info = utils.show()
|
|
468
|
+
attr = media['attributes']
|
|
469
|
+
|
|
470
|
+
#print(json.dumps(media, indent=2))
|
|
471
|
+
#raise NotImplementedError
|
|
472
|
+
|
|
473
|
+
if media['type'] == 'anime':
|
|
474
|
+
total = attr['episodeCount']
|
|
475
|
+
elif media['type'] == 'manga':
|
|
476
|
+
total = attr['chapterCount']
|
|
477
|
+
elif media['type'] == 'drama':
|
|
478
|
+
total = attr['episodeCount'] # TODO Unconfirmed
|
|
479
|
+
|
|
480
|
+
info.update({
|
|
481
|
+
'id': int(media['id']),
|
|
482
|
+
# TODO : Some shows actually don't have a canonicalTitle; this should be fixed in the future.
|
|
483
|
+
# For now I'm just picking the romaji title in these cases.
|
|
484
|
+
'title': attr['canonicalTitle'] or attr['titles']['en_jp'],
|
|
485
|
+
'total': total or 0,
|
|
486
|
+
'image': attr['posterImage']['small'],
|
|
487
|
+
'image_thumb': attr['posterImage']['tiny'],
|
|
488
|
+
'start_date': self._str2date(attr['startDate']),
|
|
489
|
+
'end_date': self._str2date(attr['endDate']),
|
|
490
|
+
'url': "https://kitsu.io/{}/{}".format(self.mediatype, attr['slug']),
|
|
491
|
+
'aliases': list(filter(None, attr['titles'].values())),
|
|
492
|
+
'extra': [
|
|
493
|
+
('Synopsis', attr['synopsis']),
|
|
494
|
+
('Type', attr['subtype']),
|
|
495
|
+
]
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
# WORKAROUND: Shows with 1 episode (TVs, SPs, OVAs) end the same day they start
|
|
499
|
+
if total == 1:
|
|
500
|
+
info['end_date'] = info['start_date']
|
|
501
|
+
|
|
502
|
+
# WORKAROUND: Since there's no way to get the formal status,
|
|
503
|
+
# use the helper function to guess it.
|
|
504
|
+
info['status'] = self._guess_status(info['start_date'], info['end_date'])
|
|
505
|
+
|
|
506
|
+
return info
|
|
507
|
+
|
trackma/lib/libmal.py
CHANGED
|
@@ -399,22 +399,22 @@ class libmal(lib):
|
|
|
399
399
|
progressname = 'chapter'
|
|
400
400
|
|
|
401
401
|
# Update necessary keys
|
|
402
|
-
if 'my_progress' in item
|
|
402
|
+
if 'my_progress' in item:
|
|
403
403
|
episode = ET.SubElement(root, progressname)
|
|
404
404
|
episode.text = str(item['my_progress'])
|
|
405
|
-
if 'my_status' in item
|
|
405
|
+
if 'my_status' in item:
|
|
406
406
|
status = ET.SubElement(root, "status")
|
|
407
407
|
status.text = str(item['my_status'])
|
|
408
|
-
if 'my_score' in item
|
|
408
|
+
if 'my_score' in item:
|
|
409
409
|
score = ET.SubElement(root, "score")
|
|
410
410
|
score.text = str(item['my_score'])
|
|
411
|
-
if 'my_start_date' in item
|
|
411
|
+
if 'my_start_date' in item:
|
|
412
412
|
start_date = ET.SubElement(root, "date_start")
|
|
413
413
|
start_date.text = self._date2str(item['my_start_date'])
|
|
414
|
-
if 'my_finish_date' in item
|
|
414
|
+
if 'my_finish_date' in item:
|
|
415
415
|
finish_date = ET.SubElement(root, "date_finish")
|
|
416
416
|
finish_date.text = self._date2str(item['my_finish_date'])
|
|
417
|
-
if 'my_tags' in item
|
|
417
|
+
if 'my_tags' in item:
|
|
418
418
|
tags = ET.SubElement(root, "tags")
|
|
419
419
|
tags.text = str(item['my_tags'])
|
|
420
420
|
|
trackma/lib/libshikimori.py
CHANGED
|
@@ -304,11 +304,11 @@ class libshikimori(lib):
|
|
|
304
304
|
user_rate = {}
|
|
305
305
|
dest_url = "/api/user_rates/{}".format(item['my_id'])
|
|
306
306
|
|
|
307
|
-
if 'my_progress' in item
|
|
307
|
+
if 'my_progress' in item:
|
|
308
308
|
user_rate[self.watched_str] = item['my_progress']
|
|
309
|
-
if 'my_status' in item
|
|
309
|
+
if 'my_status' in item:
|
|
310
310
|
user_rate['status'] = item['my_status']
|
|
311
|
-
if 'my_score' in item
|
|
311
|
+
if 'my_score' in item:
|
|
312
312
|
user_rate['score'] = item['my_score']
|
|
313
313
|
|
|
314
314
|
values = {'user_rate': user_rate}
|
trackma/lib/libvndb.py
CHANGED
|
@@ -37,11 +37,14 @@ class libvndb(lib):
|
|
|
37
37
|
api_info = {
|
|
38
38
|
'name': 'VNDB',
|
|
39
39
|
'shortname': 'vndb',
|
|
40
|
-
'version':
|
|
40
|
+
'version': 2,
|
|
41
41
|
'merge': True,
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
default_mediatype = 'vnlist'
|
|
45
|
+
pagesize_list = 100
|
|
46
|
+
pagesize_details = 25
|
|
47
|
+
|
|
45
48
|
mediatypes = dict()
|
|
46
49
|
mediatypes['vnlist'] = {
|
|
47
50
|
'has_progress': False,
|
|
@@ -177,7 +180,7 @@ class libvndb(lib):
|
|
|
177
180
|
|
|
178
181
|
(name, data) = self._sendcmd('get %s basic (uid = 0)' % self.mediatype,
|
|
179
182
|
{'page': page,
|
|
180
|
-
'results':
|
|
183
|
+
'results': self.pagesize_list
|
|
181
184
|
})
|
|
182
185
|
|
|
183
186
|
# Something is wrong if we don't get a results response.
|
|
@@ -204,7 +207,7 @@ class libvndb(lib):
|
|
|
204
207
|
|
|
205
208
|
(name, data) = self._sendcmd('get votelist basic (uid = 0)',
|
|
206
209
|
{'page': page,
|
|
207
|
-
'results':
|
|
210
|
+
'results': self.pagesize_list
|
|
208
211
|
})
|
|
209
212
|
|
|
210
213
|
# Something is wrong if we don't get a results response.
|
|
@@ -234,11 +237,11 @@ class libvndb(lib):
|
|
|
234
237
|
remaining = [ show['id'] for show in itemlist ]
|
|
235
238
|
while True:
|
|
236
239
|
self.msg.info(self.name, 'Requesting details...(%d)' % start)
|
|
237
|
-
end = start +
|
|
240
|
+
end = start + self.pagesize_details
|
|
238
241
|
|
|
239
242
|
(name, data) = self._sendcmd('get vn basic,details (id = %s)' % repr(remaining[start:end]),
|
|
240
243
|
{'page': 1,
|
|
241
|
-
'results':
|
|
244
|
+
'results': self.pagesize_details,
|
|
242
245
|
})
|
|
243
246
|
|
|
244
247
|
# Something is wrong if we don't get a results response.
|
|
@@ -249,7 +252,7 @@ class libvndb(lib):
|
|
|
249
252
|
for item in data['items']:
|
|
250
253
|
infos.append(self._parse_info(item))
|
|
251
254
|
|
|
252
|
-
start +=
|
|
255
|
+
start += self.pagesize_details
|
|
253
256
|
if start >= len(itemlist):
|
|
254
257
|
# We're going beyond the list, finish
|
|
255
258
|
break
|
|
@@ -267,7 +270,7 @@ class libvndb(lib):
|
|
|
267
270
|
self.check_credentials()
|
|
268
271
|
|
|
269
272
|
# Update status with set vnlist
|
|
270
|
-
if 'my_status' in item
|
|
273
|
+
if 'my_status' in item:
|
|
271
274
|
self.msg.info(self.name, 'Updating VN %s (status)...' % item['title'])
|
|
272
275
|
|
|
273
276
|
if self.mediatype == 'wishlist':
|
|
@@ -281,7 +284,7 @@ class libvndb(lib):
|
|
|
281
284
|
raise utils.APIError("Invalid response (%s)" % name)
|
|
282
285
|
|
|
283
286
|
# Update vote with set votelist
|
|
284
|
-
if 'my_score' in item
|
|
287
|
+
if 'my_score' in item:
|
|
285
288
|
self.msg.info(self.name, 'Updating VN %s (vote)...' % item['title'])
|
|
286
289
|
|
|
287
290
|
if item['my_score'] > 0:
|
|
@@ -314,7 +317,7 @@ class libvndb(lib):
|
|
|
314
317
|
|
|
315
318
|
(name, data) = self._sendcmd('get vn basic,details (search ~ "%s")' % criteria,
|
|
316
319
|
{'page': 1,
|
|
317
|
-
'results':
|
|
320
|
+
'results': self.pagesize_details,
|
|
318
321
|
})
|
|
319
322
|
|
|
320
323
|
# Something is wrong if we don't get a results response.
|
trackma/messenger.py
CHANGED
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|