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