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.
Files changed (57) hide show
  1. EGG-INFO/PKG-INFO +19 -0
  2. EGG-INFO/SOURCES.txt +35 -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/__init__.pyc +0 -0
  10. trackma/accounts.py +110 -0
  11. trackma/accounts.pyc +0 -0
  12. trackma/data/anilist.jpg +0 -0
  13. trackma/data/hb.jpg +0 -0
  14. trackma/data/icon.png +0 -0
  15. trackma/data/mal.jpg +0 -0
  16. trackma/data/melative.jpg +0 -0
  17. trackma/data/vndb.jpg +0 -0
  18. trackma/data.py +585 -0
  19. trackma/data.pyc +0 -0
  20. trackma/engine.py +742 -0
  21. trackma/engine.pyc +0 -0
  22. trackma/extras/AnimeInfoExtractor.py +308 -0
  23. trackma/extras/AnimeInfoExtractor.pyc +0 -0
  24. trackma/extras/__init__.py +0 -0
  25. trackma/extras/__init__.pyc +0 -0
  26. trackma/extras/plex.py +100 -0
  27. trackma/extras/plex.pyc +0 -0
  28. trackma/lib/__init__.py +0 -0
  29. trackma/lib/__init__.pyc +0 -0
  30. trackma/lib/lib.py +162 -0
  31. trackma/lib/lib.pyc +0 -0
  32. trackma/lib/libanilist.py +355 -0
  33. trackma/lib/libanilist.pyc +0 -0
  34. trackma/lib/libhb.py +248 -0
  35. trackma/lib/libhb.pyc +0 -0
  36. trackma/lib/libmal.py +705 -0
  37. trackma/lib/libmal.pyc +0 -0
  38. trackma/lib/libmelative.py +213 -0
  39. trackma/lib/libmelative.pyc +0 -0
  40. trackma/lib/libvndb.py +373 -0
  41. trackma/lib/libvndb.pyc +0 -0
  42. trackma/messenger.py +42 -0
  43. trackma/messenger.pyc +0 -0
  44. trackma/tracker.py +301 -0
  45. trackma/tracker.pyc +0 -0
  46. trackma/ui/__init__.py +0 -0
  47. trackma/ui/__init__.pyc +0 -0
  48. trackma/ui/cli.py +712 -0
  49. trackma/ui/cli.pyc +0 -0
  50. trackma/ui/curses.py +1049 -0
  51. trackma/ui/curses.pyc +0 -0
  52. trackma/ui/gtkui.py +2360 -0
  53. trackma/ui/gtkui.pyc +0 -0
  54. trackma/ui/qtui.py +2120 -0
  55. trackma/ui/qtui.pyc +0 -0
  56. trackma/utils.py +299 -0
  57. trackma/utils.pyc +0 -0
trackma/ui/qtui.pyc ADDED
Binary file
trackma/utils.py ADDED
@@ -0,0 +1,299 @@
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 cPickle as pickle
23
+
24
+ VERSION = '0.4'
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
+ 'vndb': ('VNDB', datadir + '/data/vndb.jpg', LOGIN_PASSWD),
45
+ }
46
+
47
+
48
+ def parse_config(filename, default):
49
+ config = copy.copy(default)
50
+
51
+ try:
52
+ with open(filename) as configfile:
53
+ config.update(json.load(configfile))
54
+ except IOError:
55
+ # Will just use the default config
56
+ # and create the file for manual editing
57
+ save_config(config, filename)
58
+
59
+ return config
60
+
61
+ def save_config(config_dict, filename):
62
+ path = os.path.dirname(filename)
63
+ if not os.path.isdir(path):
64
+ os.mkdir(path)
65
+
66
+ with open(filename, 'wb') as configfile:
67
+ json.dump(config_dict, configfile, sort_keys=True,
68
+ indent=4, separators=(',', ': '))
69
+
70
+ def load_data(filename):
71
+ with open(filename, 'rb') as datafile:
72
+ return pickle.load(datafile)
73
+
74
+ def save_data(data, filename):
75
+ with open(filename, 'wb') as datafile:
76
+ pickle.dump(data, datafile)
77
+
78
+ def log_error(msg):
79
+ with open(get_root_filename('error.log'), 'a') as logfile:
80
+ logfile.write(msg.encode('utf-8'))
81
+
82
+ def regex_find_videos(extensions, subdirectory=''):
83
+ __re = re.compile(extensions, re.I)
84
+
85
+ if subdirectory:
86
+ path = os.path.expanduser(subdirectory)
87
+ else:
88
+ path = os.getcwd()
89
+ for root, dirs, names in os.walk(path, followlinks=True):
90
+ for filename in names:
91
+ # Filename manipulation
92
+
93
+ extension = os.path.splitext(filename)[1][1:]
94
+ match = __re.match(extension)
95
+ if match:
96
+ yield ( os.path.join(root, filename), filename )
97
+
98
+ def list_library(path):
99
+ for root, dirs, names in os.walk(path, followlinks=True):
100
+ for filename in names:
101
+ yield ( os.path.join(root, filename), filename )
102
+
103
+ def make_dir(directory):
104
+ path = os.path.expanduser(os.path.join('~', '.trackma', directory))
105
+ if not os.path.isdir(path):
106
+ os.mkdir(path)
107
+
108
+ def dir_exists(dirname):
109
+ return os.path.isdir(dirname)
110
+
111
+ def file_exists(filename):
112
+ return os.path.isfile(filename)
113
+
114
+ def copy_file(src, dest):
115
+ shutil.copy(src, dest)
116
+
117
+ def get_filename(subdir, filename):
118
+ return os.path.expanduser(os.path.join('~', '.trackma', subdir, filename))
119
+
120
+ def get_root_filename(filename):
121
+ return os.path.expanduser(os.path.join('~', '.trackma', filename))
122
+
123
+ def estimate_aired_episodes(show):
124
+ # Estimate how many episodes have passed since airing
125
+ # Let's just assume 1 episode = 1 week
126
+ if not show['start_date']:
127
+ return
128
+
129
+ if show['status'] == 1:
130
+ days = (datetime.datetime.now() - show['start_date']).days
131
+ if days <= 0:
132
+ return 0
133
+
134
+ eps = days / 7 + 1
135
+ if eps > show['total']:
136
+ return show['total']
137
+ return eps
138
+ elif show['status'] == 2:
139
+ return show['total']
140
+
141
+ def guess_show(show_title, tracker_list):
142
+ # Use difflib to see if the show title is similar to
143
+ # one we have in the list
144
+ highest_ratio = (None, 0)
145
+ matcher = difflib.SequenceMatcher()
146
+ matcher.set_seq1(show_title.lower())
147
+
148
+ # Compare to every show in our list to see which one
149
+ # has the most similar name
150
+ for item in tracker_list:
151
+ # Make sure to search through all the aliases
152
+ for title in item['titles']:
153
+ matcher.set_seq2(title.lower())
154
+ ratio = matcher.ratio()
155
+ if ratio > highest_ratio[1]:
156
+ highest_ratio = (item, ratio)
157
+
158
+ playing_show = highest_ratio[0]
159
+ if highest_ratio[1] > 0.7:
160
+ return playing_show
161
+
162
+ def get_terminal_size(fd=1):
163
+ """
164
+ Returns height and width of current terminal. First tries to get
165
+ size via termios.TIOCGWINSZ, then from environment. Defaults to 25
166
+ lines x 80 columns if both methods fail.
167
+
168
+ :param fd: file descriptor (default: 1=stdout)
169
+ """
170
+ try:
171
+ import fcntl, termios, struct
172
+ hw = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
173
+ except:
174
+ try:
175
+ hw = (os.environ['LINES'], os.environ['COLUMNS'])
176
+ except:
177
+ hw = (25, 80)
178
+
179
+ return hw
180
+
181
+ def show():
182
+ return {
183
+ 'id': 0,
184
+ 'title': '',
185
+ 'url': '',
186
+ 'aliases': [],
187
+ 'my_progress': 0,
188
+ 'my_status': 1,
189
+ 'my_score': 0,
190
+ 'my_start_date': None,
191
+ 'my_finish_date': None,
192
+ 'type': 0,
193
+ 'status': 0,
194
+ 'total': 0,
195
+ 'start_date': None,
196
+ 'end_date': None,
197
+ 'image': '',
198
+ 'image_thumb': '',
199
+ 'queued': False,
200
+ 'neweps': False,
201
+ }
202
+
203
+ class TrackmaError(Exception):
204
+ pass
205
+
206
+ class EngineError(TrackmaError):
207
+ pass
208
+
209
+ class DataError(TrackmaError):
210
+ pass
211
+
212
+ class APIError(TrackmaError):
213
+ pass
214
+
215
+ class AccountError(TrackmaError):
216
+ pass
217
+
218
+ class TrackmaFatal(Exception):
219
+ pass
220
+
221
+ class EngineFatal(TrackmaFatal):
222
+ pass
223
+
224
+ class DataFatal(TrackmaFatal):
225
+ pass
226
+
227
+ class APIFatal(TrackmaFatal):
228
+ pass
229
+
230
+ # Configuration defaults
231
+ config_defaults = {
232
+ 'player': 'mpv',
233
+ 'searchdir': '/home/user/Videos',
234
+ 'tracker_enabled': True,
235
+ 'tracker_update_wait_s': 120,
236
+ 'tracker_update_close': False,
237
+ 'tracker_update_prompt': False,
238
+ 'tracker_interval': 10,
239
+ 'tracker_process': 'mplayer|mplayer2|mpv',
240
+ 'autoretrieve': 'days',
241
+ 'autoretrieve_days': 3,
242
+ 'autosend': 'hours',
243
+ 'autosend_hours': 5,
244
+ 'autosend_size': 5,
245
+ 'autosend_at_exit': True,
246
+ 'debug_disable_lock': True,
247
+ 'auto_status_change': True,
248
+ 'auto_status_change_if_scored': True,
249
+ 'auto_date_change': True,
250
+ 'tracker_type': "local",
251
+ 'plex_host': "localhost",
252
+ 'plex_port': "32400",
253
+ }
254
+ userconfig_defaults = {
255
+ 'mediatype': '',
256
+ 'userid': 0,
257
+ 'username': '',
258
+ }
259
+ keymap_defaults = {
260
+ 'help': 'f1',
261
+ 'prev_filter': 'left',
262
+ 'next_filter': 'right',
263
+ 'sort': 'f3',
264
+ 'update': 'f4',
265
+ 'play': 'f5',
266
+ 'status': 'f6',
267
+ 'score': 'f7',
268
+ 'send': 's',
269
+ 'retrieve': 'R',
270
+ 'addsearch': 'a',
271
+ 'reload': 'c',
272
+ 'switch_account': 'f9',
273
+ 'delete': 'd',
274
+ 'quit': 'f12',
275
+ 'altname': 'A',
276
+ 'search': '/',
277
+ 'neweps': 'N',
278
+ 'details': 'enter',
279
+ 'details_exit': 'esc',
280
+ 'open_web': 'O',
281
+ }
282
+
283
+ gtk_defaults = {
284
+ 'show_tray': True,
285
+ 'close_to_tray': True,
286
+ 'start_in_tray': False,
287
+ }
288
+
289
+ qt_defaults = {
290
+ 'show_tray': True,
291
+ 'close_to_tray': True,
292
+ 'notifications': True,
293
+ 'start_in_tray': False,
294
+ 'remember_geometry': False,
295
+ 'last_x': 0,
296
+ 'last_y': 0,
297
+ 'last_width': 740,
298
+ 'last_height': 480,
299
+ }
trackma/utils.pyc ADDED
Binary file