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