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.
Files changed (60) hide show
  1. EGG-INFO/PKG-INFO +19 -0
  2. EGG-INFO/SOURCES.txt +37 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/entry_points.txt +8 -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-35.pyc +0 -0
  10. trackma/__pycache__/accounts.cpython-35.pyc +0 -0
  11. trackma/__pycache__/data.cpython-35.pyc +0 -0
  12. trackma/__pycache__/engine.cpython-35.pyc +0 -0
  13. trackma/__pycache__/messenger.cpython-35.pyc +0 -0
  14. trackma/__pycache__/tracker.cpython-35.pyc +0 -0
  15. trackma/__pycache__/utils.cpython-35.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 +597 -0
  25. trackma/engine.py +818 -0
  26. trackma/extras/AnimeInfoExtractor.py +308 -0
  27. trackma/extras/__init__.py +1 -0
  28. trackma/extras/__pycache__/AnimeInfoExtractor.cpython-35.pyc +0 -0
  29. trackma/extras/__pycache__/__init__.cpython-35.pyc +0 -0
  30. trackma/extras/__pycache__/plex.cpython-35.pyc +0 -0
  31. trackma/extras/plex.py +101 -0
  32. trackma/lib/__init__.py +0 -0
  33. trackma/lib/__pycache__/__init__.cpython-35.pyc +0 -0
  34. trackma/lib/__pycache__/lib.cpython-35.pyc +0 -0
  35. trackma/lib/__pycache__/libanilist.cpython-35.pyc +0 -0
  36. trackma/lib/__pycache__/libhb.cpython-35.pyc +0 -0
  37. trackma/lib/__pycache__/libmal.cpython-35.pyc +0 -0
  38. trackma/lib/__pycache__/libmelative.cpython-35.pyc +0 -0
  39. trackma/lib/__pycache__/libshikimori.cpython-35.pyc +0 -0
  40. trackma/lib/__pycache__/libvndb.cpython-35.pyc +0 -0
  41. trackma/lib/lib.py +162 -0
  42. trackma/lib/libanilist.py +406 -0
  43. trackma/lib/libhb.py +237 -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 +375 -0
  48. trackma/messenger.py +42 -0
  49. trackma/tracker.py +390 -0
  50. trackma/ui/__init__.py +0 -0
  51. trackma/ui/__pycache__/__init__.cpython-35.pyc +0 -0
  52. trackma/ui/__pycache__/cli.cpython-35.pyc +0 -0
  53. trackma/ui/__pycache__/curses.cpython-35.pyc +0 -0
  54. trackma/ui/__pycache__/gtkui.cpython-35.pyc +0 -0
  55. trackma/ui/__pycache__/qtui.cpython-35.pyc +0 -0
  56. trackma/ui/cli.py +835 -0
  57. trackma/ui/curses.py +1061 -0
  58. trackma/ui/gtkui.py +2647 -0
  59. trackma/ui/qtui.py +3046 -0
  60. trackma/utils.py +379 -0
trackma/utils.py ADDED
@@ -0,0 +1,379 @@
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 os, re, shutil, copy
18
+ import subprocess
19
+ import datetime
20
+ import json
21
+ import difflib
22
+ import pickle
23
+
24
+ VERSION = '0.6'
25
+
26
+ datadir = os.path.dirname(__file__)
27
+ LOGIN_PASSWD = 1
28
+ LOGIN_OAUTH = 2
29
+
30
+ STATUS_AIRING = 1
31
+ STATUS_FINISHED = 2
32
+ STATUS_NOTYET = 3
33
+ STATUS_CANCELLED = 4
34
+
35
+ # Put the available APIs here
36
+ available_libs = {
37
+ 'anilist': ('Anilist', datadir + '/data/anilist.jpg', LOGIN_OAUTH,
38
+ "http://omaera.org/trackma/anilist.html",
39
+ "https://anilist.co/api/auth/authorize?grant_type=authorization_pin&client_id=z411-gdjc3&response_type=pin"
40
+ ),
41
+ 'hb': ('Hummingbird', datadir + '/data/hb.jpg', LOGIN_PASSWD),
42
+ 'mal': ('MyAnimeList', datadir + '/data/mal.jpg', LOGIN_PASSWD),
43
+ 'melative': ('Melative', datadir + '/data/melative.jpg', LOGIN_PASSWD),
44
+ 'shikimori':('Shikimori', datadir + '/data/shikimori.jpg', LOGIN_PASSWD),
45
+ 'vndb': ('VNDB', datadir + '/data/vndb.jpg', LOGIN_PASSWD),
46
+ }
47
+
48
+
49
+ def parse_config(filename, default):
50
+ config = copy.copy(default)
51
+
52
+ try:
53
+ with open(filename) as configfile:
54
+ loaded_config = json.load(configfile)
55
+ if 'colors' in config and 'colors' in loaded_config:
56
+ # Need to prevent nested dict from being overwritten with an incomplete dict
57
+ config['colors'].update(loaded_config['colors'])
58
+ loaded_config['colors'] = config['colors']
59
+ config.update(loaded_config)
60
+ except IOError:
61
+ # Will just use the default config
62
+ # and create the file for manual editing
63
+ save_config(config, filename)
64
+ except ValueError:
65
+ # There's a syntax error in the config file
66
+ errorString = "Erroneous config %s requires manual fixing or deletion to proceed." % filename
67
+ log_error(errorString)
68
+ raise TrackmaFatal(errorString)
69
+
70
+ return config
71
+
72
+ def save_config(config_dict, filename):
73
+ path = os.path.dirname(filename)
74
+ if not os.path.isdir(path):
75
+ os.mkdir(path)
76
+
77
+ with open(filename, 'wb') as configfile:
78
+ configfile.write(json.dumps(config_dict, sort_keys=True,
79
+ indent=4, separators=(',', ': ')).encode('utf-8'))
80
+
81
+ def load_data(filename):
82
+ with open(filename, 'rb') as datafile:
83
+ return pickle.load(datafile, encoding='bytes')
84
+
85
+ def save_data(data, filename):
86
+ with open(filename, 'wb') as datafile:
87
+ pickle.dump(data, datafile, protocol=2)
88
+
89
+ def log_error(msg):
90
+ with open(get_root_filename('error.log'), 'a') as logfile:
91
+ logfile.write(msg)
92
+
93
+ def regex_find_videos(extensions, subdirectory=''):
94
+ __re = re.compile(extensions, re.I)
95
+
96
+ if subdirectory:
97
+ path = os.path.expanduser(subdirectory)
98
+ else:
99
+ path = os.getcwd()
100
+ for root, dirs, names in os.walk(path, followlinks=True):
101
+ for filename in names:
102
+ # Filename manipulation
103
+
104
+ extension = os.path.splitext(filename)[1][1:]
105
+ match = __re.match(extension)
106
+ if match:
107
+ yield ( os.path.join(root, filename), filename )
108
+
109
+ def regex_rename_files(pattern, source_dir, dest_dir):
110
+ in_path = os.path.expanduser(os.path.join('~', '.trackma', source_dir))
111
+ out_path = os.path.expanduser(os.path.join('~', '.trackma', dest_dir))
112
+ for filename in os.listdir(in_path):
113
+ if re.match(pattern, filename):
114
+ in_file = os.path.join(in_path,filename)
115
+ out_file = os.path.join(out_path,filename)
116
+ os.rename(in_file, out_file)
117
+
118
+ def list_library(path):
119
+ for root, dirs, names in os.walk(path, followlinks=True):
120
+ for filename in names:
121
+ yield ( os.path.join(root, filename), filename )
122
+
123
+ def make_dir(directory):
124
+ path = os.path.expanduser(os.path.join('~', '.trackma', directory))
125
+ if not os.path.isdir(path):
126
+ os.mkdir(path)
127
+
128
+ def dir_exists(dirname):
129
+ return os.path.isdir(dirname)
130
+
131
+ def file_exists(filename):
132
+ return os.path.isfile(filename)
133
+
134
+ def copy_file(src, dest):
135
+ shutil.copy(src, dest)
136
+
137
+ def get_filename(subdir, filename):
138
+ return os.path.expanduser(os.path.join('~', '.trackma', subdir, filename))
139
+
140
+ def get_root_filename(filename):
141
+ return os.path.expanduser(os.path.join('~', '.trackma', filename))
142
+
143
+ def get_root():
144
+ return os.path.expanduser(os.path.join('~', '.trackma'))
145
+
146
+ def change_permissions(filename, mode):
147
+ os.chmod(filename, mode)
148
+
149
+ def estimate_aired_episodes(show):
150
+ # Estimate how many episodes have passed since airing
151
+
152
+ if show['status'] == STATUS_FINISHED:
153
+ return show['total']
154
+ elif show['status'] == STATUS_NOTYET:
155
+ return 0
156
+ elif show['status'] == STATUS_AIRING: # It's airing, so we make an estimate based on available information
157
+ if 'next_ep_number' in show: # Do we have the upcoming episode number?
158
+ return show['next_ep_number']-1
159
+ elif show['start_date']: # Do we know when it started? Let's just assume 1 episode = 1 week
160
+ days = (datetime.datetime.now() - show['start_date']).days
161
+ if days <= 0:
162
+ return 0
163
+
164
+ eps = days // 7 + 1
165
+ if eps > show['total'] and show['total'] > 0:
166
+ return show['total']
167
+ return eps
168
+ return 0
169
+
170
+ def guess_show(show_title, tracker_list):
171
+ # Use difflib to see if the show title is similar to
172
+ # one we have in the list
173
+ highest_ratio = (None, 0)
174
+ matcher = difflib.SequenceMatcher()
175
+ matcher.set_seq1(show_title.lower())
176
+
177
+ # Compare to every show in our list to see which one
178
+ # has the most similar name
179
+ for item in tracker_list:
180
+ # Make sure to search through all the aliases
181
+ for title in item['titles']:
182
+ matcher.set_seq2(title.lower())
183
+ ratio = matcher.ratio()
184
+ if ratio > highest_ratio[1]:
185
+ highest_ratio = (item, ratio)
186
+
187
+ playing_show = highest_ratio[0]
188
+ if highest_ratio[1] > 0.7:
189
+ return playing_show
190
+
191
+ def get_terminal_size(fd=1):
192
+ """
193
+ Returns height and width of current terminal. First tries to get
194
+ size via termios.TIOCGWINSZ, then from environment. Defaults to 25
195
+ lines x 80 columns if both methods fail.
196
+
197
+ :param fd: file descriptor (default: 1=stdout)
198
+ """
199
+ try:
200
+ import fcntl, termios, struct
201
+ hw = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
202
+ except:
203
+ try:
204
+ hw = (os.environ['LINES'], os.environ['COLUMNS'])
205
+ except:
206
+ hw = (25, 80)
207
+
208
+ return hw
209
+
210
+ def show():
211
+ return {
212
+ 'id': 0,
213
+ 'title': '',
214
+ 'url': '',
215
+ 'aliases': [],
216
+ 'my_id': None,
217
+ 'my_progress': 0,
218
+ 'my_status': 1,
219
+ 'my_score': 0,
220
+ 'my_start_date': None,
221
+ 'my_finish_date': None,
222
+ 'type': 0,
223
+ 'status': 0,
224
+ 'total': 0,
225
+ 'start_date': None,
226
+ 'end_date': None,
227
+ 'image': '',
228
+ 'image_thumb': '',
229
+ 'queued': False,
230
+ 'neweps': False,
231
+ }
232
+
233
+ class TrackmaError(Exception):
234
+ pass
235
+
236
+ class EngineError(TrackmaError):
237
+ pass
238
+
239
+ class DataError(TrackmaError):
240
+ pass
241
+
242
+ class APIError(TrackmaError):
243
+ pass
244
+
245
+ class AccountError(TrackmaError):
246
+ pass
247
+
248
+ class TrackmaFatal(Exception):
249
+ pass
250
+
251
+ class EngineFatal(TrackmaFatal):
252
+ pass
253
+
254
+ class DataFatal(TrackmaFatal):
255
+ pass
256
+
257
+ class APIFatal(TrackmaFatal):
258
+ pass
259
+
260
+ # Configuration defaults
261
+ config_defaults = {
262
+ 'player': 'mpv',
263
+ 'searchdir': '/home/user/Videos',
264
+ 'tracker_enabled': True,
265
+ 'tracker_update_wait_s': 120,
266
+ 'tracker_update_close': False,
267
+ 'tracker_update_prompt': False,
268
+ 'tracker_interval': 10,
269
+ 'tracker_process': 'mplayer|mplayer2|mpv',
270
+ 'autoretrieve': 'days',
271
+ 'autoretrieve_days': 3,
272
+ 'autosend': 'hours',
273
+ 'autosend_hours': 5,
274
+ 'autosend_size': 5,
275
+ 'autosend_at_exit': True,
276
+ 'debug_disable_lock': True,
277
+ 'auto_status_change': True,
278
+ 'auto_status_change_if_scored': True,
279
+ 'auto_date_change': True,
280
+ 'tracker_type': "local",
281
+ 'plex_host': "localhost",
282
+ 'plex_port': "32400",
283
+ }
284
+ userconfig_defaults = {
285
+ 'mediatype': '',
286
+ 'userid': 0,
287
+ 'username': '',
288
+ }
289
+ curses_defaults = {
290
+ 'keymap': {
291
+ 'help': 'f1',
292
+ 'prev_filter': 'left',
293
+ 'next_filter': 'right',
294
+ 'sort': 'f3',
295
+ 'sort_order': 'r',
296
+ 'update': 'f4',
297
+ 'play': 'f5',
298
+ 'status': 'f6',
299
+ 'score': 'f7',
300
+ 'send': 's',
301
+ 'retrieve': 'R',
302
+ 'addsearch': 'a',
303
+ 'reload': 'c',
304
+ 'switch_account': 'f9',
305
+ 'delete': 'd',
306
+ 'quit': 'f12',
307
+ 'altname': 'A',
308
+ 'search': '/',
309
+ 'neweps': 'N',
310
+ 'details': 'enter',
311
+ 'details_exit': 'esc',
312
+ 'open_web': 'O',
313
+ },
314
+ 'palette': {
315
+
316
+ }
317
+ }
318
+
319
+ gtk_defaults = {
320
+ 'show_tray': True,
321
+ 'close_to_tray': True,
322
+ 'start_in_tray': False,
323
+ 'tray_api_icon': False,
324
+ 'remember_geometry': False,
325
+ 'last_width': 740,
326
+ 'last_height': 480,
327
+ 'visible_columns': ['Title', 'Progress', 'Score', 'Percent'],
328
+ 'episodebar_style': 1,
329
+ 'colors': {
330
+ 'is_airing': '#0099CC',
331
+ 'is_playing': '#6C2DC7',
332
+ 'is_queued': '#54C571',
333
+ 'new_episode': '#FBB917',
334
+ 'not_aired': '#999900',
335
+ 'progress_bg': '#E5E5E5',
336
+ 'progress_fg': '#99B3CC',
337
+ 'progress_sub_bg': '#B3B3B3',
338
+ 'progress_sub_fg': '#668099',
339
+ 'progress_complete': '#99CCB3',
340
+ },
341
+ }
342
+
343
+ qt_defaults = {
344
+ 'show_tray': True,
345
+ 'close_to_tray': True,
346
+ 'notifications': True,
347
+ 'start_in_tray': False,
348
+ 'tray_api_icon': False,
349
+ 'remember_geometry': False,
350
+ 'remember_columns': False,
351
+ 'last_x': 0,
352
+ 'last_y': 0,
353
+ 'last_width': 740,
354
+ 'last_height': 480,
355
+ 'visible_columns': ['Title', 'Progress', 'Score', 'Percent'],
356
+ 'columns_state': {},
357
+ 'columns_per_api': False,
358
+ 'episodebar_style': 1,
359
+ 'episodebar_text': False,
360
+ 'filter_bar_position': 2,
361
+ 'filter_global': False,
362
+ 'colors': {
363
+ 'is_airing': '#D2FAFA',
364
+ 'is_playing': '#9696FA',
365
+ 'is_queued': '#D2FAD2',
366
+ 'new_episode': '#FAFA82',
367
+ 'not_aired': '#FAFAD2',
368
+ 'progress_bg': '#F5F5F5',
369
+ 'progress_fg': '#74C0FA',
370
+ 'progress_sub_bg': '#D2D2D2',
371
+ 'progress_sub_fg': '#5187B1',
372
+ 'progress_complete': '#00D200',
373
+ },
374
+ }
375
+
376
+ qt_per_api_defaults = {
377
+ 'visible_columns': ['Title', 'Progress', 'Score', 'Percent'],
378
+ 'columns_state': {},
379
+ }