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
@@ -0,0 +1,144 @@
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 ntpath
18
+ import time
19
+ import urllib.parse
20
+ import urllib.request
21
+ import xml.dom.minidom as xdmd
22
+
23
+ import trackma.utils as utils
24
+ from trackma.tracker import tracker
25
+
26
+ NOT_RUNNING = 0
27
+ ACTIVE = 1
28
+ IDLE = 2
29
+
30
+ class PlexTracker(tracker.TrackerBase):
31
+ name = 'Tracker (Plex)'
32
+
33
+ def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
34
+ self.config = utils.parse_config(utils.get_root_filename('config.json'), utils.config_defaults)
35
+ self.host_port = self.config['plex_host']+":"+self.config['plex_port']
36
+ self.update_wait = update_wait
37
+ self.status_log = [None, None]
38
+ self.token = self._get_plex_token()
39
+ super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
40
+
41
+ def get_plex_status(self):
42
+ # returns the plex status of the first active session
43
+ try:
44
+ active = int(self._get_sessions_info("MediaContainer", "size"))
45
+
46
+ if active:
47
+ return ACTIVE
48
+ else:
49
+ return IDLE
50
+ except urllib.request.URLError:
51
+ return NOT_RUNNING
52
+
53
+ def playing_file(self):
54
+ # returns the filename of the currently playing file
55
+ if self.get_plex_status() == IDLE:
56
+ return None
57
+
58
+ meta = self._get_sessions_info("Video", "key")
59
+ meta_url = "http://"+self.host_port+meta
60
+ mres = self._get_xml_info(meta_url, "Part", "file")
61
+ name = urllib.parse.unquote(ntpath.basename(mres))
62
+
63
+ return name
64
+
65
+ def timer_from_file(self):
66
+ # returns 80% of video duration for the update timer,
67
+ # roughly the time of the video minus the OP and ED
68
+ if self.get_plex_status() == IDLE:
69
+ return None
70
+
71
+ try:
72
+ duration = int(self._get_sessions_info("Video", "duration"))
73
+ return round((duration*0.80)/60000)*60
74
+ except IndexError:
75
+ return None
76
+
77
+ def observe(self, watch_dir, interval):
78
+ self.msg.info(self.name, "Using Plex.")
79
+
80
+ while self.active:
81
+ self.status_log.append(self.get_plex_status())
82
+
83
+ if self.status_log[-1] == ACTIVE or self.status_log[-1] == IDLE:
84
+ if self.status_log[-1] == IDLE and self.status_log[-2] == NOT_RUNNING:
85
+ self.msg.info(self.name, "Reconnected to Plex.")
86
+
87
+ if self.config['plex_obey_update_wait_s']:
88
+ self.wait_s = self.update_wait
89
+ else:
90
+ self.wait_s = self.timer_from_file()
91
+
92
+ try:
93
+ filename = self.playing_file()
94
+ (state, show_tuple) = self._get_playing_show(filename)
95
+ self.update_show_if_needed(state, show_tuple)
96
+ except IndexError:
97
+ pass
98
+ elif self.status_log[-1] == NOT_RUNNING and self.status_log[-2] == NOT_RUNNING:
99
+ self.msg.warn(self.name, "Plex Media Server is not running.")
100
+
101
+ del self.status_log[0]
102
+
103
+ # Wait for the interval before running check again
104
+ time.sleep(interval)
105
+
106
+ def _get_plex_token(self):
107
+ username = self.config['plex_user']
108
+ password = self.config['plex_passwd']
109
+ uuid = self.config['plex_uuid']
110
+
111
+ if not (username and password):
112
+ return ''
113
+
114
+ body = bytes('user[login]=%s&user[password]=%s' % (username, password), "utf-8")
115
+ headers={'X-Plex-Client-Identifier': uuid,
116
+ 'X-Plex-Product': "Trackma",
117
+ 'X-Plex-Version': utils.VERSION}
118
+
119
+ req = urllib.request.Request('https://plex.tv/users/sign_in.xml', body, headers=headers)
120
+ response = urllib.request.urlopen(req)
121
+ data = response.read().decode("utf-8")
122
+
123
+ tdoc = xdmd.parseString(data)
124
+ token = tdoc.getElementsByTagName("user")[0].getAttribute("authToken")
125
+
126
+ return "?X-Plex-Token="+token
127
+
128
+ def _get_xml_info(self, url, tag, attr):
129
+ try:
130
+ uop = urllib.request.urlopen(url)
131
+ except urllib.request.URLError:
132
+ uop = urllib.request.urlopen(url+self.token)
133
+
134
+ doc = xdmd.parse(uop)
135
+ res = doc.getElementsByTagName(tag)[0].getAttribute(attr)
136
+
137
+ return res
138
+
139
+ def _get_sessions_info(self, tag, attr):
140
+ # Get the required info from the /status/sessions url
141
+ session_url = "http://"+self.host_port+"/status/sessions"
142
+ info = self._get_xml_info(session_url, tag, attr)
143
+
144
+ return info
@@ -0,0 +1,55 @@
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 time
18
+ import re
19
+ import os
20
+ import subprocess
21
+
22
+ from trackma.tracker import tracker
23
+
24
+ class PollingTracker(tracker.TrackerBase):
25
+ name = 'Tracker (polling)'
26
+
27
+ def get_playing_file(self, watch_dir, players):
28
+ try:
29
+ lsof = subprocess.Popen(['lsof', '+w', '-n', '-c', ''.join(['/', players, '/']), '-Fn', watch_dir], stdout=subprocess.PIPE)
30
+ except OSError:
31
+ self.msg.warn(self.name, "Couldn't execute lsof. Disabling tracker.")
32
+ self.disable()
33
+ return None
34
+
35
+ output = lsof.communicate()[0].decode('utf-8')
36
+ fileregex = re.compile("n(.*(\.mkv|\.mp4|\.avi))")
37
+
38
+ for line in output.splitlines():
39
+ match = fileregex.match(line)
40
+ if match is not None:
41
+ return os.path.basename(match.group(1))
42
+
43
+ return None
44
+
45
+ def observe(self, watch_dir, interval):
46
+ self.msg.info(self.name, "pyinotify not available; using polling (slow).")
47
+ while self.active:
48
+ # This runs the tracker and update the playing show if necessary
49
+ filename = self.get_playing_file(watch_dir, self.process_name)
50
+ (state, show_tuple) = self._get_playing_show(filename)
51
+ self.update_show_if_needed(state, show_tuple)
52
+
53
+ # Wait for the interval before running check again
54
+ time.sleep(interval)
55
+
@@ -0,0 +1,90 @@
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 pyinotify
18
+
19
+ from trackma.tracker import inotifyBase
20
+ from trackma import utils
21
+
22
+ class pyinotifyTracker(inotifyBase.inotifyBase):
23
+ name = 'Tracker (pyinotify)'
24
+
25
+ def observe(self, watch_dir, interval):
26
+ self.msg.info(self.name, 'Using pyinotify.')
27
+ wm = pyinotify.WatchManager() # Watch Manager
28
+ mask = (pyinotify.IN_OPEN
29
+ | pyinotify.IN_CLOSE_NOWRITE
30
+ | pyinotify.IN_CLOSE_WRITE
31
+ | pyinotify.IN_CREATE
32
+ | pyinotify.IN_MOVED_FROM
33
+ | pyinotify.IN_MOVED_TO
34
+ | pyinotify.IN_DELETE)
35
+
36
+ class EventHandler(pyinotify.ProcessEvent):
37
+ def my_init(self, parent=None):
38
+ self.parent = parent
39
+
40
+ def process_IN_OPEN(self, event):
41
+ if not event.mask & pyinotify.IN_ISDIR:
42
+ self.parent._proc_open(event.path, event.name)
43
+
44
+ def process_IN_CLOSE_NOWRITE(self, event):
45
+ if not event.mask & pyinotify.IN_ISDIR:
46
+ self.parent._proc_close(event.path, event.name)
47
+
48
+ def process_IN_CLOSE_WRITE(self, event):
49
+ if not event.mask & pyinotify.IN_ISDIR:
50
+ self.parent._proc_close(event.path, event.name)
51
+
52
+ def process_IN_CREATE(self, event):
53
+ if not event.mask & pyinotify.IN_ISDIR:
54
+ self.parent._emit_signal('detected', event.path, event.name)
55
+
56
+ def process_IN_MOVED_TO(self, event):
57
+ if not event.mask & pyinotify.IN_ISDIR:
58
+ self.parent._emit_signal('detected', event.path, event.name)
59
+
60
+ def process_IN_MOVED_FROM(self, event):
61
+ if not event.mask & pyinotify.IN_ISDIR:
62
+ self.parent._emit_signal('removed', event.path, event.name)
63
+
64
+ def process_IN_DELETE(self, event):
65
+ if not event.mask & pyinotify.IN_ISDIR:
66
+ self.parent._emit_signal('removed', event.path, event.name)
67
+
68
+ handler = EventHandler(parent=self)
69
+ notifier = pyinotify.Notifier(wm, handler)
70
+ self.msg.debug(self.name, 'Watching directory {}'.format(watch_dir))
71
+ wdd = wm.add_watch(watch_dir, mask, rec=True, auto_add=True)
72
+
73
+ try:
74
+ #notifier.loop()
75
+ timeout = None
76
+ while self.active:
77
+ if notifier.check_events(timeout):
78
+ notifier.read_events()
79
+ notifier.process_events()
80
+ if self.last_state == utils.TRACKER_NOVIDEO or self.last_updated:
81
+ timeout = None # Block indefinitely
82
+ else:
83
+ timeout = 1000 # Check each second for counting
84
+ else:
85
+ self.msg.debug(self.name, "Sending last state {} {}".format(self.last_state, self.last_show_tuple))
86
+ self.update_show_if_needed(self.last_state, self.last_show_tuple)
87
+ finally:
88
+ notifier.stop()
89
+ self.msg.info(self.name, 'Tracker has stopped.')
90
+
@@ -0,0 +1,226 @@
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 threading
18
+ import re
19
+ import time
20
+ import os
21
+
22
+ import ctypes
23
+
24
+ from trackma import messenger
25
+ from trackma import utils
26
+ from trackma.extras import AnimeInfoExtractor
27
+
28
+ class TrackerBase(object):
29
+ msg = None
30
+ active = True
31
+ list = None
32
+ last_show_tuple = None
33
+ last_filename = None
34
+ last_state = utils.TRACKER_NOVIDEO
35
+ last_time = 0
36
+ last_updated = False
37
+ last_close_queue = None
38
+ timer = None
39
+
40
+ name = 'Tracker'
41
+
42
+ signals = {
43
+ 'state': None,
44
+ 'detected': None,
45
+ 'playing': None,
46
+ 'removed': None,
47
+ 'update': None,
48
+ 'unrecognised': None,
49
+ }
50
+
51
+ def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
52
+ self.msg = messenger
53
+ self.msg.info(self.name, 'Initializing...')
54
+
55
+ self.list = tracker_list
56
+ self.process_name = process_name
57
+
58
+ tracker_args = (utils.expand_path(watch_dir), interval)
59
+ self.wait_s = update_wait
60
+ self.wait_close = update_close
61
+ self.not_found_prompt = not_found_prompt
62
+ tracker_t = threading.Thread(target=self.observe, args=tracker_args)
63
+ tracker_t.daemon = True
64
+ self.msg.debug(self.name, 'Enabling tracker...')
65
+ tracker_t.start()
66
+
67
+ def set_message_handler(self, message_handler):
68
+ """Changes the message handler function on the fly."""
69
+ self.msg = message_handler
70
+
71
+ def disable(self):
72
+ self.active = False
73
+
74
+ def enable(self):
75
+ self.active = True
76
+
77
+ def update_list(self, tracker_list):
78
+ self.list = tracker_list
79
+
80
+ def connect_signal(self, signal, callback):
81
+ try:
82
+ self.signals[signal] = callback
83
+ except KeyError:
84
+ raise utils.EngineFatal("Invalid signal.")
85
+
86
+ def observe(self, watch_dir, interval):
87
+ raise NotImplementedError
88
+
89
+ def get_status(self):
90
+ return {
91
+ 'state': self.last_state,
92
+ 'timer': self.timer,
93
+ 'show': self.last_show_tuple,
94
+ 'filename': self.last_filename,
95
+ }
96
+
97
+ def _emit_signal(self, signal, *args):
98
+ try:
99
+ if self.signals[signal]:
100
+ self.signals[signal](*args)
101
+ except KeyError:
102
+ raise Exception("Call to undefined signal.")
103
+
104
+ def _update_show(self, state, show_tuple):
105
+ (show, episode) = show_tuple
106
+ self.timer = int(1 + self.wait_s - (time.time() - self.last_time))
107
+ self._emit_signal('state', state, self.timer)
108
+
109
+ if self.timer <= 0:
110
+ # Perform show update
111
+ self.last_updated = True
112
+ action = None
113
+ if state == utils.TRACKER_PLAYING:
114
+ action = lambda: self._emit_signal('update', show['id'], episode)
115
+ elif state == utils.TRACKER_NOT_FOUND:
116
+ action = lambda: self._emit_signal('unrecognised', show['title'], episode)
117
+
118
+ if self.wait_close:
119
+ self.msg.info(self.name, 'Waiting for the player to close.')
120
+ self.last_close_queue = action
121
+ elif action:
122
+ action()
123
+
124
+ def _ignore_current(self):
125
+ # Stops attempt to update current episode
126
+ self.last_updated = True
127
+ self.last_state = utils.TRACKER_IGNORED
128
+ self.timer = None
129
+ self._emit_signal('state', utils.TRACKER_IGNORED, None)
130
+
131
+ def _update_state(self, state):
132
+ # Call when show or state is changed. Perform queued update if any, and clear playing flag.
133
+ if self.last_close_queue:
134
+ self.last_close_queue()
135
+ self.last_close_queue = None
136
+ self.last_time = time.time()
137
+ if self.last_show_tuple:
138
+ (last_show, last_show_ep) = self.last_show_tuple
139
+ if last_show['id']:
140
+ self._emit_signal('playing', last_show['id'], False, last_show_ep)
141
+
142
+ def update_show_if_needed(self, state, show_tuple):
143
+ # If the state and show are unchanged, skip to countdown
144
+ if show_tuple and state == self.last_state and show_tuple == self.last_show_tuple and not self.last_updated:
145
+ self._update_show(state, show_tuple)
146
+ return
147
+
148
+ if show_tuple and show_tuple != self.last_show_tuple:
149
+ (show, episode) = show_tuple
150
+ self._update_state(state)
151
+ # There's a new show/ep detected, so let's save the show information
152
+ self.last_show_tuple = show_tuple
153
+ self.last_updated = False
154
+ if state == utils.TRACKER_PLAYING:
155
+ self._emit_signal('playing', show['id'], True, episode)
156
+ # Check if we shouldn't update the show
157
+ if episode != (show['my_progress'] + 1):
158
+ self.msg.warn(self.name, 'Not playing the next episode of %s. Ignoring.' % show['title'])
159
+ self._ignore_current()
160
+ return
161
+ if episode < 1 or (show['total'] and episode > show['total']):
162
+ self.msg.warn(self.name, 'Playing an invalid episode of %s. Ignoring.' % show['title'])
163
+ self._ignore_current()
164
+ return
165
+
166
+ # Start our countdown
167
+ (show, episode) = show_tuple
168
+ if state == utils.TRACKER_PLAYING:
169
+ self.msg.info(self.name, 'Will update %s %d in %d seconds' % (show['title'], episode, self.wait_s))
170
+ elif state == utils.TRACKER_NOT_FOUND:
171
+ self.msg.info(self.name, 'Will add %s %d in %d seconds' % (show['title'], episode, self.wait_s))
172
+ self._update_show(state, show_tuple)
173
+
174
+ elif self.last_state != state:
175
+ self._update_state(state)
176
+
177
+ # React depending on state
178
+ if state == utils.TRACKER_NOVIDEO: # No video is playing
179
+ # Video didn't get to update phase before it was closed
180
+ if self.last_state == utils.TRACKER_PLAYING and not self.last_updated:
181
+ self.msg.info(self.name, 'Player was closed before update.')
182
+ elif state == utils.TRACKER_UNRECOGNIZED: # There's a new video playing but the regex didn't recognize the format
183
+ self.msg.warn(self.name, 'Found video but the file name format couldn\'t be recognized.')
184
+ elif state == utils.TRACKER_NOT_FOUND: # There's a new video playing but an associated show wasn't found
185
+ self.msg.warn(self.name, 'Found player but show not in list.')
186
+
187
+ self.last_show_tuple = None
188
+ self.last_updated = False
189
+ self.timer = None
190
+ self._emit_signal('state', state, None)
191
+
192
+ self.last_state = state
193
+
194
+ def _get_playing_show(self, filename):
195
+ if not self.active:
196
+ # Don't do anything if the Tracker is disabled
197
+ return (utils.TRACKER_NOVIDEO, None)
198
+
199
+ if filename:
200
+ if filename == self.last_filename:
201
+ # It's the exact same filename, there's no need to do the processing again
202
+ return (self.last_state, self.last_show_tuple)
203
+
204
+ self.last_filename = filename
205
+
206
+ # Do a regex to the filename to get
207
+ # the show title and episode number
208
+ aie = AnimeInfoExtractor(filename)
209
+ (show_title, show_ep) = (aie.getName(), aie.getEpisode())
210
+ if not show_title:
211
+ return (utils.TRACKER_UNRECOGNIZED, None) # Format not recognized
212
+
213
+ playing_show = utils.guess_show(show_title, self.list)
214
+ if playing_show:
215
+ return (utils.TRACKER_PLAYING, (playing_show, show_ep))
216
+ else:
217
+ # Show not in list
218
+ if self.not_found_prompt:
219
+ # Dummy show to search for
220
+ show = {'id': 0, 'title': show_title}
221
+ return (utils.TRACKER_NOT_FOUND, (show, show_ep))
222
+ else:
223
+ return (utils.TRACKER_NOT_FOUND, None)
224
+ else:
225
+ self.last_filename = None
226
+ return (utils.TRACKER_NOVIDEO, None) # Not playing
@@ -0,0 +1,74 @@
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 ctypes
18
+ import time
19
+ import re
20
+
21
+ from trackma.tracker import tracker
22
+
23
+ class Win32Tracker(tracker.TrackerBase):
24
+ name = 'Tracker (win32)'
25
+
26
+ def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
27
+ super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
28
+
29
+ self.winregex = re.compile("(\.mkv|\.mp4|\.avi)")
30
+
31
+ def _foreach_window(self, hwnd, lParam):
32
+ # Get class name and window title of the current hwnd
33
+ # and add it to the list of the found windows
34
+ length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
35
+
36
+ buff_class = ctypes.create_unicode_buffer(32)
37
+ buff_title = ctypes.create_unicode_buffer(length + 1)
38
+
39
+ ctypes.windll.user32.GetClassNameW(hwnd, buff_class, 32)
40
+ ctypes.windll.user32.GetWindowTextW(hwnd, buff_title, length + 1)
41
+
42
+ self.win32_hwnd_list.append( (buff_class.value, buff_title.value) )
43
+ return True
44
+
45
+ def _get_playing_file_win32(self):
46
+ # Enumerate all windows using the win32 API
47
+ # This will call _foreach_window for each window handle
48
+ # Then return the window title if the class name matches
49
+ # Currently supporting MPC(-HC) and mpv
50
+
51
+ self.win32_hwnd_list = []
52
+ self.EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
53
+ ctypes.windll.user32.EnumWindows(self.EnumWindowsProc(self._foreach_window), 0)
54
+
55
+ for classname, title in self.win32_hwnd_list:
56
+ if classname == 'MediaPlayerClassicW' and self.winregex.search(title) is not None:
57
+ return title
58
+ elif classname == 'mpv' and self.winregex.search(title) is not None:
59
+ return title.replace('mpv - ', '')
60
+
61
+ return False
62
+
63
+ def observe(self, interval, watch_dir):
64
+ self.msg.info(self.name, "Using Win32.")
65
+
66
+ while self.active:
67
+ # This runs the tracker and update the playing show if necessary
68
+ filename = self._get_playing_file_win32()
69
+ (state, show_tuple) = self._get_playing_show(filename)
70
+ self.update_show_if_needed(state, show_tuple)
71
+
72
+ # Wait for the interval before running check again
73
+ time.sleep(1)
74
+
trackma/ui/__init__.py ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ from trackma.engine import Engine
2
+ engine = Engine({'username': "z411", 'password': '199199199','api':"mal"})
3
+ engine.start()