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.
- EGG-INFO/PKG-INFO +19 -0
- EGG-INFO/SOURCES.txt +37 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/entry_points.txt +8 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +10 -0
- EGG-INFO/top_level.txt +1 -0
- trackma/__init__.py +0 -0
- trackma/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/__pycache__/accounts.cpython-35.pyc +0 -0
- trackma/__pycache__/data.cpython-35.pyc +0 -0
- trackma/__pycache__/engine.cpython-35.pyc +0 -0
- trackma/__pycache__/messenger.cpython-35.pyc +0 -0
- trackma/__pycache__/tracker.cpython-35.pyc +0 -0
- trackma/__pycache__/utils.cpython-35.pyc +0 -0
- trackma/accounts.py +145 -0
- trackma/data/anilist.jpg +0 -0
- trackma/data/hb.jpg +0 -0
- trackma/data/icon.png +0 -0
- trackma/data/mal.jpg +0 -0
- trackma/data/melative.jpg +0 -0
- trackma/data/shikimori.jpg +0 -0
- trackma/data/vndb.jpg +0 -0
- trackma/data.py +597 -0
- trackma/engine.py +818 -0
- trackma/extras/AnimeInfoExtractor.py +308 -0
- trackma/extras/__init__.py +1 -0
- trackma/extras/__pycache__/AnimeInfoExtractor.cpython-35.pyc +0 -0
- trackma/extras/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/extras/__pycache__/plex.cpython-35.pyc +0 -0
- trackma/extras/plex.py +101 -0
- trackma/lib/__init__.py +0 -0
- trackma/lib/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/lib.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libanilist.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libhb.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libmal.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libmelative.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libshikimori.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libvndb.cpython-35.pyc +0 -0
- trackma/lib/lib.py +162 -0
- trackma/lib/libanilist.py +406 -0
- trackma/lib/libhb.py +237 -0
- trackma/lib/libmal.py +707 -0
- trackma/lib/libmelative.py +204 -0
- trackma/lib/libshikimori.py +340 -0
- trackma/lib/libvndb.py +375 -0
- trackma/messenger.py +42 -0
- trackma/tracker.py +390 -0
- trackma/ui/__init__.py +0 -0
- trackma/ui/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/cli.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/curses.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/gtkui.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/qtui.cpython-35.pyc +0 -0
- trackma/ui/cli.py +835 -0
- trackma/ui/curses.py +1061 -0
- trackma/ui/gtkui.py +2647 -0
- trackma/ui/qtui.py +3046 -0
- trackma/utils.py +379 -0
|
@@ -0,0 +1,204 @@
|
|
|
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 urllib.parse
|
|
18
|
+
import urllib.request
|
|
19
|
+
import json
|
|
20
|
+
|
|
21
|
+
from trackma.lib.lib import lib
|
|
22
|
+
from trackma import utils
|
|
23
|
+
|
|
24
|
+
class libmelative(lib):
|
|
25
|
+
"""
|
|
26
|
+
API class to communiate with Melative.
|
|
27
|
+
|
|
28
|
+
http://www.melative.com
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
name = 'libmelative'
|
|
32
|
+
|
|
33
|
+
api_info = { 'name': 'Melative', 'shortname': 'melative', 'version': 'v0.1', 'merge': False }
|
|
34
|
+
|
|
35
|
+
mediatypes = dict()
|
|
36
|
+
|
|
37
|
+
# All mediatypes share the same statuses so we'll reuse them
|
|
38
|
+
statuses = [1, 2, 3, 4, 6]
|
|
39
|
+
statuses_dict = { 1: 'Current', 2: 'Complete', 3: 'Hold', 4: 'Dropped', 6: 'Wishlisted' }
|
|
40
|
+
|
|
41
|
+
default_mediatype = 'anime'
|
|
42
|
+
mediatypes['anime'] = {
|
|
43
|
+
'has_progress': True,
|
|
44
|
+
'can_score': True,
|
|
45
|
+
'can_status': True,
|
|
46
|
+
'can_update': True,
|
|
47
|
+
'can_play': True,
|
|
48
|
+
'statuses': statuses,
|
|
49
|
+
'statuses_dict': statuses_dict,
|
|
50
|
+
'segment_type': 'Episode',
|
|
51
|
+
'score_max': 10,
|
|
52
|
+
'score_step': 0.1,
|
|
53
|
+
}
|
|
54
|
+
mediatypes['manga'] = {
|
|
55
|
+
'has_progress': True,
|
|
56
|
+
'can_score': True,
|
|
57
|
+
'can_status': True,
|
|
58
|
+
'can_update': True,
|
|
59
|
+
'can_play': False,
|
|
60
|
+
'statuses': statuses,
|
|
61
|
+
'statuses_dict': statuses_dict,
|
|
62
|
+
'segment_type': 'Chapter',
|
|
63
|
+
'score_max': 10,
|
|
64
|
+
'score_step': 0.1,
|
|
65
|
+
}
|
|
66
|
+
mediatypes['vn'] = {
|
|
67
|
+
'has_progress': False,
|
|
68
|
+
'can_score': True,
|
|
69
|
+
'can_status': True,
|
|
70
|
+
'can_update': True,
|
|
71
|
+
'can_play': False,
|
|
72
|
+
'statuses': statuses,
|
|
73
|
+
'statuses_dict': statuses_dict,
|
|
74
|
+
'segment_type': 'Chapter',
|
|
75
|
+
'score_max': 10,
|
|
76
|
+
'score_step': 0.1,
|
|
77
|
+
}
|
|
78
|
+
mediatypes['lightnovel'] = {
|
|
79
|
+
'has_progress': True,
|
|
80
|
+
'can_score': True,
|
|
81
|
+
'can_status': True,
|
|
82
|
+
'can_update': True,
|
|
83
|
+
'can_play': False,
|
|
84
|
+
'statuses': statuses,
|
|
85
|
+
'statuses_dict': statuses_dict,
|
|
86
|
+
'segment_type': 'Chapter',
|
|
87
|
+
'score_max': 10,
|
|
88
|
+
'score_step': 0.1,
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
def __init__(self, messenger, account, userconfig):
|
|
92
|
+
"""Initializes the useragent through credentials."""
|
|
93
|
+
super(libmelative, self).__init__(messenger, account, userconfig)
|
|
94
|
+
|
|
95
|
+
self.username = account['username']
|
|
96
|
+
|
|
97
|
+
self.password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
|
98
|
+
self.password_mgr.add_password("Melative", "melative.com:80", account['username'], account['password']);
|
|
99
|
+
|
|
100
|
+
self.handler = urllib.request.HTTPBasicAuthHandler(self.password_mgr)
|
|
101
|
+
self.opener = urllib.request.build_opener(self.handler)
|
|
102
|
+
|
|
103
|
+
urllib.request.install_opener(self.opener)
|
|
104
|
+
|
|
105
|
+
def check_credentials(self):
|
|
106
|
+
self.msg.info(self.name, 'Logging in...')
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
response = self.opener.open("http://melative.com/api/account/verify_credentials.json")
|
|
110
|
+
self.logged_in = True
|
|
111
|
+
|
|
112
|
+
# Parse user information
|
|
113
|
+
data = json.loads(response.read().decode('utf-8'))
|
|
114
|
+
|
|
115
|
+
self.username = data['name']
|
|
116
|
+
self.userid = data['id']
|
|
117
|
+
|
|
118
|
+
return True
|
|
119
|
+
except urllib.request.HTTPError as e:
|
|
120
|
+
raise utils.APIError("Incorrect credentials.")
|
|
121
|
+
|
|
122
|
+
def fetch_list(self):
|
|
123
|
+
self.check_credentials()
|
|
124
|
+
self.msg.info(self.name, 'Downloading list...')
|
|
125
|
+
|
|
126
|
+
# Get a JSON list from API
|
|
127
|
+
response = self.opener.open("http://melative.com/api/library.json?user={0}&context_type={1}".format(self.username, self.mediatype))
|
|
128
|
+
data = json.loads(response.read().decode('utf-8'))
|
|
129
|
+
|
|
130
|
+
# Load data from the JSON stream into a parsed dictionary
|
|
131
|
+
statuses = self.media_info()['statuses_dict']
|
|
132
|
+
itemlist = dict()
|
|
133
|
+
for record in data['library']:
|
|
134
|
+
entity = record['entity']
|
|
135
|
+
segment = record['segment']
|
|
136
|
+
itemid = int(entity['id'])
|
|
137
|
+
|
|
138
|
+
# use appropiate number for the show state
|
|
139
|
+
_status = 0
|
|
140
|
+
for k, v in statuses.items():
|
|
141
|
+
if v.lower() == record['state']:
|
|
142
|
+
_status = k
|
|
143
|
+
|
|
144
|
+
# use show length if available
|
|
145
|
+
try:
|
|
146
|
+
_total = int(entity['length'])
|
|
147
|
+
except TypeError:
|
|
148
|
+
_total = 0
|
|
149
|
+
|
|
150
|
+
# use show progress if needed
|
|
151
|
+
if self.mediatypes[self.mediatype]['has_progress']:
|
|
152
|
+
_progress = int(segment['name'])
|
|
153
|
+
else:
|
|
154
|
+
_progress = 0
|
|
155
|
+
|
|
156
|
+
show = utils.show()
|
|
157
|
+
show['id'] = itemid
|
|
158
|
+
show['title'] = entity['aliases'][0]
|
|
159
|
+
show['my_status'] = _status
|
|
160
|
+
show['my_score'] = int(record['rating'] or 0)
|
|
161
|
+
show['my_progress'] =_progress
|
|
162
|
+
show['total'] = _total
|
|
163
|
+
show['image'] = entity['image_url']
|
|
164
|
+
show['status'] = 0 #placeholder
|
|
165
|
+
|
|
166
|
+
itemlist[itemid] = show
|
|
167
|
+
|
|
168
|
+
return itemlist
|
|
169
|
+
|
|
170
|
+
#except urllib.request.HTTPError as e:
|
|
171
|
+
# raise utils.APIError("Error getting list. %s" % e)
|
|
172
|
+
|
|
173
|
+
def update_show(self, item):
|
|
174
|
+
self.check_credentials()
|
|
175
|
+
self.msg.info(self.name, 'Updating show %s...' % item['title'])
|
|
176
|
+
|
|
177
|
+
changes = dict()
|
|
178
|
+
if self.media_info()['has_progress'] and 'my_progress' in item.keys():
|
|
179
|
+
# We need to update the segment, so we call api/scrobble
|
|
180
|
+
#values = dict()
|
|
181
|
+
#values = {'attribute_type': _self.media_info['segment_type'],
|
|
182
|
+
# 'attribute_name': item['my_progress']}
|
|
183
|
+
#data = urllib.parse.urlencode(values)
|
|
184
|
+
#
|
|
185
|
+
#try:
|
|
186
|
+
# reponse = self.opener.open("http://melative.com/api/scrobble.json", data.encode('utf-8'))
|
|
187
|
+
#except urllib.request.HTTPError as e:
|
|
188
|
+
# raise utils.APIError("Error scrobbling: " + str(e.code))
|
|
189
|
+
changes['segment'] = "%s|%d" % (self.media_info()['segment_type'], item['my_progress'] )
|
|
190
|
+
|
|
191
|
+
if 'my_status' in item.keys():
|
|
192
|
+
changes['state'] = self.statuses_dict[item['my_status']]
|
|
193
|
+
|
|
194
|
+
if 'my_score' in item.keys():
|
|
195
|
+
changes['rating'] = item['my_score']
|
|
196
|
+
|
|
197
|
+
data = urllib.parse.urlencode(changes)
|
|
198
|
+
|
|
199
|
+
try:
|
|
200
|
+
response = self.opener.open("http://melative.com/api/scrobble.json", data.encode('utf-8'))
|
|
201
|
+
except urllib.request.HTTPError as e:
|
|
202
|
+
raise utils.APIError("Error updating: " + str(e.code))
|
|
203
|
+
|
|
204
|
+
return True
|
|
@@ -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.keys():
|
|
308
|
+
user_rate[self.watched_str] = item['my_progress']
|
|
309
|
+
if 'my_status' in item.keys():
|
|
310
|
+
user_rate['status'] = item['my_status']
|
|
311
|
+
if 'my_score' in item.keys():
|
|
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
|
+
|