trackma 0.6__py3.5.egg → 0.7.4__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.
- EGG-INFO/PKG-INFO +1 -1
- EGG-INFO/SOURCES.txt +23 -6
- EGG-INFO/entry_points.txt +4 -3
- EGG-INFO/requires.txt +1 -3
- trackma/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/__pycache__/accounts.cpython-35.pyc +0 -0
- trackma/__pycache__/data.cpython-35.pyc +0 -0
- trackma/__pycache__/engine.cpython-35.pyc +0 -0
- trackma/__pycache__/messenger.cpython-35.pyc +0 -0
- trackma/__pycache__/utils.cpython-35.pyc +0 -0
- trackma/data/kitsu.png +0 -0
- trackma/data.py +28 -17
- trackma/engine.py +208 -64
- trackma/extras/AnimeInfoExtractor.py +14 -5
- trackma/extras/__pycache__/AnimeInfoExtractor.cpython-35.pyc +0 -0
- trackma/extras/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/lib.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libanilist.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libkitsu.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libmal.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libshikimori.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libvndb.cpython-35.pyc +0 -0
- trackma/lib/libanilist.py +21 -17
- trackma/lib/libkitsu.py +506 -0
- trackma/lib/libmal.py +15 -15
- trackma/lib/libshikimori.py +3 -3
- trackma/lib/libvndb.py +26 -14
- trackma/messenger.py +1 -1
- trackma/tracker/__init__.py +0 -0
- trackma/tracker/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/inotify.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/inotifyBase.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/plex.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/polling.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/pyinotify.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/tracker.cpython-35.pyc +0 -0
- trackma/tracker/__pycache__/win32.cpython-35.pyc +0 -0
- trackma/tracker/inotify.py +69 -0
- trackma/tracker/inotifyBase.py +107 -0
- trackma/tracker/plex.py +139 -0
- trackma/tracker/polling.py +55 -0
- trackma/tracker/pyinotify.py +90 -0
- trackma/tracker/tracker.py +223 -0
- trackma/tracker/win32.py +74 -0
- trackma/ui/__pycache__/__init__.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/cli.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/curses.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/gtkui.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/qt4ui.cpython-35.pyc +0 -0
- trackma/ui/__pycache__/qtui.cpython-35.pyc +0 -0
- trackma/ui/cli.py +195 -26
- trackma/ui/curses.py +133 -66
- trackma/ui/gtkui.py +253 -78
- trackma/ui/qt4ui.py +25 -0
- trackma/ui/qtui.py +357 -186
- trackma/utils.py +40 -11
- trackma/__pycache__/tracker.cpython-35.pyc +0 -0
- trackma/data/hb.jpg +0 -0
- trackma/data/melative.jpg +0 -0
- trackma/extras/__pycache__/plex.cpython-35.pyc +0 -0
- trackma/extras/plex.py +0 -101
- trackma/lib/__pycache__/libhb.cpython-35.pyc +0 -0
- trackma/lib/__pycache__/libmelative.cpython-35.pyc +0 -0
- trackma/lib/libhb.py +0 -237
- trackma/lib/libmelative.py +0 -204
- trackma/tracker.py +0 -390
|
@@ -0,0 +1,223 @@
|
|
|
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 = (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, 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
|
+
self._emit_signal('playing', last_show['id'], False, last_show_ep)
|
|
140
|
+
|
|
141
|
+
def update_show_if_needed(self, state, show_tuple):
|
|
142
|
+
# If the state and show are unchanged, skip to countdown
|
|
143
|
+
if show_tuple and state == self.last_state and show_tuple == self.last_show_tuple and not self.last_updated:
|
|
144
|
+
self._update_show(state, show_tuple)
|
|
145
|
+
return
|
|
146
|
+
|
|
147
|
+
if show_tuple and show_tuple != self.last_show_tuple:
|
|
148
|
+
(show, episode) = show_tuple
|
|
149
|
+
self._update_state(state)
|
|
150
|
+
# There's a new show/ep detected, so let's save the show information
|
|
151
|
+
self.last_show_tuple = show_tuple
|
|
152
|
+
self.last_updated = False
|
|
153
|
+
if state == utils.TRACKER_PLAYING:
|
|
154
|
+
self._emit_signal('playing', show['id'], True, episode)
|
|
155
|
+
# Check if we shouldn't update the show
|
|
156
|
+
if episode != (show['my_progress'] + 1):
|
|
157
|
+
self.msg.warn(self.name, 'Not playing the next episode of %s. Ignoring.' % show['title'])
|
|
158
|
+
self._ignore_current()
|
|
159
|
+
return
|
|
160
|
+
if episode < 1 or (show['total'] and episode > show['total']):
|
|
161
|
+
self.msg.warn(self.name, 'Playing an invalid episode of %s. Ignoring.' % show['title'])
|
|
162
|
+
self._ignore_current()
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
# Start our countdown
|
|
166
|
+
(show, episode) = show_tuple
|
|
167
|
+
if state == utils.TRACKER_PLAYING:
|
|
168
|
+
self.msg.info(self.name, 'Will update %s %d in %d seconds' % (show['title'], episode, self.wait_s))
|
|
169
|
+
elif state == utils.TRACKER_NOT_FOUND:
|
|
170
|
+
self.msg.info(self.name, 'Will add %s %d in %d seconds' % (show, episode, self.wait_s))
|
|
171
|
+
self._update_show(state, show_tuple)
|
|
172
|
+
|
|
173
|
+
elif self.last_state != state:
|
|
174
|
+
self._update_state(state)
|
|
175
|
+
|
|
176
|
+
# React depending on state
|
|
177
|
+
if state == utils.TRACKER_NOVIDEO: # No video is playing
|
|
178
|
+
# Video didn't get to update phase before it was closed
|
|
179
|
+
if self.last_state == utils.TRACKER_PLAYING and not self.last_updated:
|
|
180
|
+
self.msg.info(self.name, 'Player was closed before update.')
|
|
181
|
+
elif state == utils.TRACKER_UNRECOGNIZED: # There's a new video playing but the regex didn't recognize the format
|
|
182
|
+
self.msg.warn(self.name, 'Found video but the file name format couldn\'t be recognized.')
|
|
183
|
+
elif state == utils.TRACKER_NOT_FOUND: # There's a new video playing but an associated show wasn't found
|
|
184
|
+
self.msg.warn(self.name, 'Found player but show not in list.')
|
|
185
|
+
|
|
186
|
+
self.last_show_tuple = None
|
|
187
|
+
self.last_updated = False
|
|
188
|
+
self.timer = None
|
|
189
|
+
self._emit_signal('state', state, None)
|
|
190
|
+
|
|
191
|
+
self.last_state = state
|
|
192
|
+
|
|
193
|
+
def _get_playing_show(self, filename):
|
|
194
|
+
if not self.active:
|
|
195
|
+
# Don't do anything if the Tracker is disabled
|
|
196
|
+
return (utils.TRACKER_NOVIDEO, None)
|
|
197
|
+
|
|
198
|
+
if filename:
|
|
199
|
+
if filename == self.last_filename:
|
|
200
|
+
# It's the exact same filename, there's no need to do the processing again
|
|
201
|
+
return (self.last_state, self.last_show_tuple)
|
|
202
|
+
|
|
203
|
+
self.last_filename = filename
|
|
204
|
+
|
|
205
|
+
# Do a regex to the filename to get
|
|
206
|
+
# the show title and episode number
|
|
207
|
+
aie = AnimeInfoExtractor(filename)
|
|
208
|
+
(show_title, show_ep) = (aie.getName(), aie.getEpisode())
|
|
209
|
+
if not show_title:
|
|
210
|
+
return (utils.TRACKER_UNRECOGNIZED, None) # Format not recognized
|
|
211
|
+
|
|
212
|
+
playing_show = utils.guess_show(show_title, self.list)
|
|
213
|
+
if playing_show:
|
|
214
|
+
return (utils.TRACKER_PLAYING, (playing_show, show_ep))
|
|
215
|
+
else:
|
|
216
|
+
# Show not in list
|
|
217
|
+
if self.not_found_prompt:
|
|
218
|
+
return (utils.TRACKER_NOT_FOUND, (show_title, show_ep))
|
|
219
|
+
else:
|
|
220
|
+
return (utils.TRACKER_NOT_FOUND, None)
|
|
221
|
+
else:
|
|
222
|
+
self.last_filename = None
|
|
223
|
+
return (utils.TRACKER_NOVIDEO, None) # Not playing
|
trackma/tracker/win32.py
ADDED
|
@@ -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
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|