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
trackma/engine.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# This file is part of
|
|
1
|
+
# This file is part of Trackma.
|
|
2
2
|
#
|
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
|
@@ -27,7 +27,6 @@ from decimal import Decimal
|
|
|
27
27
|
|
|
28
28
|
from trackma import messenger
|
|
29
29
|
from trackma import data
|
|
30
|
-
from trackma import tracker
|
|
31
30
|
from trackma import utils
|
|
32
31
|
from trackma.extras import AnimeInfoExtractor
|
|
33
32
|
|
|
@@ -50,11 +49,11 @@ class Engine:
|
|
|
50
49
|
"""
|
|
51
50
|
data_handler = None
|
|
52
51
|
tracker = None
|
|
53
|
-
config =
|
|
52
|
+
config = {}
|
|
54
53
|
msg = None
|
|
55
54
|
loaded = False
|
|
56
55
|
playing = False
|
|
57
|
-
hooks_available =
|
|
56
|
+
hooks_available = []
|
|
58
57
|
|
|
59
58
|
name = 'Engine'
|
|
60
59
|
|
|
@@ -67,7 +66,10 @@ class Engine:
|
|
|
67
66
|
'sync_complete': None,
|
|
68
67
|
'queue_changed': None,
|
|
69
68
|
'playing': None,
|
|
70
|
-
'prompt_for_update': None,
|
|
69
|
+
'prompt_for_update': None,
|
|
70
|
+
'prompt_for_add': None,
|
|
71
|
+
'tracker_state': None,
|
|
72
|
+
}
|
|
71
73
|
|
|
72
74
|
def __init__(self, account, message_handler=None):
|
|
73
75
|
"""Reads configuration file and asks the data handler for the API info."""
|
|
@@ -95,18 +97,26 @@ class Engine:
|
|
|
95
97
|
except IOError:
|
|
96
98
|
raise utils.EngineFatal("Couldn't open config file.")
|
|
97
99
|
|
|
98
|
-
# Load hook
|
|
99
|
-
|
|
100
|
+
# Load hook files
|
|
101
|
+
hooks_dir = utils.get_root_filename('hooks')
|
|
102
|
+
if os.path.isdir(hooks_dir):
|
|
100
103
|
import sys
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
import
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
import pkgutil
|
|
105
|
+
|
|
106
|
+
self.msg.info(self.name, "Importing user hooks...")
|
|
107
|
+
for loader, name, ispkg in pkgutil.iter_modules([hooks_dir]):
|
|
108
|
+
# List all the hook files in the hooks folder, import them
|
|
109
|
+
# and call the init() function if they have them
|
|
110
|
+
# We build the list "hooks available" with the loaded modules
|
|
111
|
+
# for later calls.
|
|
112
|
+
try:
|
|
113
|
+
self.msg.debug(self.name, "Importing hook {}...".format(name))
|
|
114
|
+
module = loader.find_module(name).load_module(name)
|
|
115
|
+
if hasattr(module, 'init'):
|
|
116
|
+
module.init(self)
|
|
117
|
+
self.hooks_available.append(module)
|
|
118
|
+
except ImportError:
|
|
119
|
+
self.msg.warn(self.name, "Error importing hook {}.".format(name))
|
|
110
120
|
|
|
111
121
|
def _init_data_handler(self, mediatype=None):
|
|
112
122
|
# Create data handler
|
|
@@ -127,6 +137,12 @@ class Engine:
|
|
|
127
137
|
def _data_queue_changed(self, queue):
|
|
128
138
|
self._emit_signal('queue_changed', queue)
|
|
129
139
|
|
|
140
|
+
def _tracker_detected(self, path, filename):
|
|
141
|
+
self.add_to_library(path, filename)
|
|
142
|
+
|
|
143
|
+
def _tracker_removed(self, path, filename):
|
|
144
|
+
self.remove_from_library(path, filename)
|
|
145
|
+
|
|
130
146
|
def _tracker_playing(self, showid, playing, episode):
|
|
131
147
|
show = self.get_show_info(showid)
|
|
132
148
|
self._emit_signal('playing', show, playing, episode)
|
|
@@ -136,19 +152,36 @@ class Engine:
|
|
|
136
152
|
if self.config['tracker_update_prompt']:
|
|
137
153
|
self._emit_signal('prompt_for_update', show, episode)
|
|
138
154
|
else:
|
|
139
|
-
|
|
155
|
+
try:
|
|
156
|
+
self.set_episode(show['id'], episode)
|
|
157
|
+
except utils.TrackmaError as e:
|
|
158
|
+
self.msg.warn(self.name, "Can't update episode: {}".format(e))
|
|
159
|
+
|
|
160
|
+
def _tracker_unrecognised(self, show_title, episode):
|
|
161
|
+
if self.config['tracker_not_found_prompt']:
|
|
162
|
+
self._emit_signal('prompt_for_add', show_title, episode)
|
|
163
|
+
|
|
164
|
+
def _tracker_state(self, state, timer):
|
|
165
|
+
self._emit_signal('tracker_state', state, timer)
|
|
140
166
|
|
|
141
167
|
def _emit_signal(self, signal, *args):
|
|
142
168
|
try:
|
|
169
|
+
# Call the signal function
|
|
143
170
|
if self.signals[signal]:
|
|
144
171
|
self.signals[signal](*args)
|
|
145
|
-
if self.hooks_available:
|
|
146
|
-
method = getattr(hook, signal)
|
|
147
|
-
self.msg.debug(self.name, "Calling hook %s..." % signal)
|
|
148
|
-
method(self, *args)
|
|
149
172
|
except AttributeError:
|
|
150
173
|
pass
|
|
151
174
|
|
|
175
|
+
# If there are loaded hooks, call the functions in all of them
|
|
176
|
+
for module in self.hooks_available:
|
|
177
|
+
method = getattr(module, signal, None)
|
|
178
|
+
if method is not None:
|
|
179
|
+
self.msg.info(self.name, "Calling hook {}:{}...".format(module.__name__, signal))
|
|
180
|
+
try:
|
|
181
|
+
method(self, *args)
|
|
182
|
+
except Exception as err:
|
|
183
|
+
self.msg.warn(self.name, "Exception on hook {}:{}: {}".format(module.__name__, signal, err))
|
|
184
|
+
|
|
152
185
|
def _get_tracker_list(self, filter_num=None):
|
|
153
186
|
tracker_list = []
|
|
154
187
|
if filter_num:
|
|
@@ -160,9 +193,10 @@ class Engine:
|
|
|
160
193
|
tracker_list.append({'id': show['id'],
|
|
161
194
|
'title': show['title'],
|
|
162
195
|
'my_progress': show['my_progress'],
|
|
196
|
+
'total': show['total'],
|
|
163
197
|
'type': None,
|
|
164
|
-
|
|
165
|
-
|
|
198
|
+
'titles': self.data_handler.get_show_titles(show),
|
|
199
|
+
}) # TODO types
|
|
166
200
|
|
|
167
201
|
return tracker_list
|
|
168
202
|
|
|
@@ -205,18 +239,50 @@ class Engine:
|
|
|
205
239
|
except utils.APIError as e:
|
|
206
240
|
raise utils.APIFatal(str(e))
|
|
207
241
|
|
|
242
|
+
# Rescan library if necessary
|
|
243
|
+
if self.config['library_autoscan']:
|
|
244
|
+
try:
|
|
245
|
+
self.scan_library()
|
|
246
|
+
except utils.TrackmaError as e:
|
|
247
|
+
self.msg.warn(self.name, "Can't auto-scan library: {}".format(e))
|
|
248
|
+
|
|
208
249
|
# Start tracker
|
|
209
250
|
if self.mediainfo.get('can_play') and self.config['tracker_enabled']:
|
|
210
|
-
|
|
251
|
+
# Choose the tracker we want to tart
|
|
252
|
+
if self.config['tracker_type'] == 'plex':
|
|
253
|
+
from trackma.tracker.plex import PlexTracker
|
|
254
|
+
TrackerClass = PlexTracker
|
|
255
|
+
elif os.name == 'nt':
|
|
256
|
+
from trackma.tracker.win32 import Win32Tracker
|
|
257
|
+
TrackerClass = Win32Tracker
|
|
258
|
+
else:
|
|
259
|
+
# Try trackers in this order: pyinotify, inotify, polling
|
|
260
|
+
try:
|
|
261
|
+
from trackma.tracker.pyinotify import pyinotifyTracker
|
|
262
|
+
TrackerClass = pyinotifyTracker
|
|
263
|
+
except ImportError:
|
|
264
|
+
try:
|
|
265
|
+
from trackma.tracker.inotify import inotifyTracker
|
|
266
|
+
TrackerClass = inotifyTracker
|
|
267
|
+
except ImportError:
|
|
268
|
+
from trackma.tracker.polling import PollingTracker
|
|
269
|
+
TrackerClass = PollingTracker
|
|
270
|
+
|
|
271
|
+
self.tracker = TrackerClass(self.msg,
|
|
211
272
|
self._get_tracker_list(),
|
|
212
273
|
self.config['tracker_process'],
|
|
213
274
|
self.config['searchdir'],
|
|
214
275
|
int(self.config['tracker_interval']),
|
|
215
276
|
int(self.config['tracker_update_wait_s']),
|
|
216
277
|
self.config['tracker_update_close'],
|
|
278
|
+
self.config['tracker_not_found_prompt'],
|
|
217
279
|
)
|
|
280
|
+
self.tracker.connect_signal('detected', self._tracker_detected)
|
|
281
|
+
self.tracker.connect_signal('removed', self._tracker_removed)
|
|
218
282
|
self.tracker.connect_signal('playing', self._tracker_playing)
|
|
219
283
|
self.tracker.connect_signal('update', self._tracker_update)
|
|
284
|
+
self.tracker.connect_signal('unrecognised', self._tracker_unrecognised)
|
|
285
|
+
self.tracker.connect_signal('state', self._tracker_state)
|
|
220
286
|
|
|
221
287
|
self.loaded = True
|
|
222
288
|
return True
|
|
@@ -305,7 +371,7 @@ class Engine:
|
|
|
305
371
|
list of show dictionaries with all the matches.
|
|
306
372
|
"""
|
|
307
373
|
showlist = self.data_handler.get()
|
|
308
|
-
return list(v for k, v in showlist.items() if re.
|
|
374
|
+
return list(v for k, v in showlist.items() if re.search(regex, v['title'], re.I))
|
|
309
375
|
|
|
310
376
|
def regex_list_titles(self, pattern):
|
|
311
377
|
# TODO : Temporal hack for the client autocomplete function
|
|
@@ -320,6 +386,16 @@ class Engine:
|
|
|
320
386
|
|
|
321
387
|
return newlist
|
|
322
388
|
|
|
389
|
+
def tracker_status(self):
|
|
390
|
+
"""
|
|
391
|
+
Asks the tracker for its current status.
|
|
392
|
+
"""
|
|
393
|
+
|
|
394
|
+
if self.tracker:
|
|
395
|
+
return self.tracker.get_status()
|
|
396
|
+
else:
|
|
397
|
+
return None
|
|
398
|
+
|
|
323
399
|
def search(self, criteria):
|
|
324
400
|
"""
|
|
325
401
|
Request a remote list of shows matching the criteria
|
|
@@ -516,7 +592,7 @@ class Engine:
|
|
|
516
592
|
|
|
517
593
|
# Check if the status is valid
|
|
518
594
|
_statuses = self.mediainfo['statuses_dict']
|
|
519
|
-
if newstatus not in _statuses
|
|
595
|
+
if newstatus not in _statuses:
|
|
520
596
|
raise utils.EngineError('Invalid status.')
|
|
521
597
|
|
|
522
598
|
# Get the show and update it
|
|
@@ -576,6 +652,9 @@ class Engine:
|
|
|
576
652
|
self._emit_signal('show_deleted', show)
|
|
577
653
|
|
|
578
654
|
def _search_video(self, titles, episode):
|
|
655
|
+
# DEPRECATED !!!
|
|
656
|
+
self.msg.debug(self.name, "DEPRECATED: _search_video")
|
|
657
|
+
|
|
579
658
|
best_candidate = (None, 0, None)
|
|
580
659
|
|
|
581
660
|
matcher = difflib.SequenceMatcher()
|
|
@@ -617,6 +696,9 @@ class Engine:
|
|
|
617
696
|
return best_candidate[0], best_candidate[2]
|
|
618
697
|
|
|
619
698
|
def get_new_episodes(self, showlist):
|
|
699
|
+
# DEPRECATED !
|
|
700
|
+
self.msg.debug(self.name, "DEPRECATED: get_new_episodes")
|
|
701
|
+
|
|
620
702
|
results = list()
|
|
621
703
|
total = len(showlist)
|
|
622
704
|
t = time.time()
|
|
@@ -637,7 +719,7 @@ class Engine:
|
|
|
637
719
|
def library(self):
|
|
638
720
|
return self.data_handler.library_get()
|
|
639
721
|
|
|
640
|
-
def scan_library(self, my_status=None,
|
|
722
|
+
def scan_library(self, my_status=None, rescan=False):
|
|
641
723
|
# Check if operation is supported by the API
|
|
642
724
|
if not self.mediainfo.get('can_play'):
|
|
643
725
|
raise utils.EngineError('Operation not supported by current site or mediatype.')
|
|
@@ -654,48 +736,106 @@ class Engine:
|
|
|
654
736
|
my_status = self.mediainfo['status_start']
|
|
655
737
|
|
|
656
738
|
self.msg.info(self.name, "Scanning local library...")
|
|
739
|
+
self.msg.debug(self.name, "Directory: %s" % self.config['searchdir'])
|
|
657
740
|
tracker_list = self._get_tracker_list(my_status)
|
|
658
741
|
|
|
659
742
|
# Do a full listing of the media directory
|
|
660
743
|
for fullpath, filename in utils.regex_find_videos('mkv|mp4|avi', self.config['searchdir']):
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
744
|
+
(library, library_cache) = self._add_show_to_library(library, library_cache, rescan, fullpath, filename, tracker_list)
|
|
745
|
+
|
|
746
|
+
self.msg.debug(self.name, "Time: %s" % (time.time() - t))
|
|
747
|
+
self.data_handler.library_save(library)
|
|
748
|
+
self.data_handler.library_cache_save(library_cache)
|
|
749
|
+
return library
|
|
750
|
+
|
|
751
|
+
def remove_from_library(self, path, filename):
|
|
752
|
+
library = self.data_handler.library_get()
|
|
753
|
+
library_cache = self.data_handler.library_cache_get()
|
|
754
|
+
tracker_list = self._get_tracker_list()
|
|
755
|
+
fullpath = path+"/"+filename
|
|
756
|
+
# Only remove if the filename matches library entry
|
|
757
|
+
if filename in library_cache and library_cache[filename]:
|
|
758
|
+
(show_id, show_ep) = library_cache[filename]
|
|
759
|
+
if show_id and show_id in library \
|
|
760
|
+
and show_ep and show_ep in library[show_id].keys():
|
|
761
|
+
if library[show_id][show_ep] == fullpath:
|
|
762
|
+
self.msg.debug(self.name, "File removed from local library: %s" % fullpath)
|
|
763
|
+
library_cache.pop(filename, None)
|
|
764
|
+
library[show_id].pop(show_ep, None)
|
|
765
|
+
|
|
766
|
+
def add_to_library(self, path, filename, rescan=False):
|
|
767
|
+
# The inotify tracker tells us when files are created in
|
|
768
|
+
# or moved within our library directory, so we call this.
|
|
769
|
+
library = self.data_handler.library_get()
|
|
770
|
+
library_cache = self.data_handler.library_cache_get()
|
|
771
|
+
tracker_list = self._get_tracker_list()
|
|
772
|
+
fullpath = path+"/"+filename
|
|
773
|
+
self._add_show_to_library(library, library_cache, rescan, fullpath, filename, tracker_list)
|
|
774
|
+
|
|
775
|
+
def _add_show_to_library(self, library, library_cache, rescan, fullpath, filename, tracker_list):
|
|
776
|
+
show_id = None
|
|
777
|
+
if not rescan and filename in library_cache:
|
|
778
|
+
# If the filename was already seen before
|
|
779
|
+
# use the cached information, if there's no information (None)
|
|
780
|
+
# then it means it doesn't correspond to any show in the list
|
|
781
|
+
# and can be safely skipped.
|
|
782
|
+
if library_cache[filename]:
|
|
783
|
+
(show_id, show_ep) = library_cache[filename]
|
|
784
|
+
if type(show_ep) is tuple:
|
|
785
|
+
(show_ep_start, show_ep_end) = show_ep
|
|
670
786
|
else:
|
|
671
|
-
|
|
787
|
+
show_ep_start = show_ep_end = show_ep
|
|
788
|
+
self.msg.debug(self.name, "File in cache: {}".format(fullpath))
|
|
672
789
|
else:
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
790
|
+
self.msg.debug(self.name, "File in cache but skipped: {}".format(fullpath))
|
|
791
|
+
return library, library_cache
|
|
792
|
+
else:
|
|
793
|
+
# If the filename has not been seen, extract
|
|
794
|
+
# the information from the filename and do a fuzzy search
|
|
795
|
+
# on the user's list. Cache the information.
|
|
796
|
+
# If it fails, cache it as None.
|
|
797
|
+
aie = AnimeInfoExtractor(filename)
|
|
798
|
+
show_title = aie.getName()
|
|
799
|
+
(show_ep_start, show_ep_end) = aie.getEpisodeNumbers(True)
|
|
800
|
+
if show_title:
|
|
801
|
+
show = utils.guess_show(show_title, tracker_list)
|
|
802
|
+
if show:
|
|
803
|
+
self.msg.debug(self.name, "Adding to library: {}".format(fullpath))
|
|
804
|
+
|
|
805
|
+
show_id = show['id']
|
|
806
|
+
if show_ep_start == show_ep_end:
|
|
807
|
+
library_cache[filename] = (show['id'], show_ep_start)
|
|
684
808
|
else:
|
|
685
|
-
library_cache[filename] =
|
|
809
|
+
library_cache[filename] = (show['id'], (show_ep_start, show_ep_end))
|
|
686
810
|
else:
|
|
811
|
+
self.msg.debug(self.name, "Not a show, skipping: {}".format(fullpath))
|
|
687
812
|
library_cache[filename] = None
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
813
|
+
else:
|
|
814
|
+
self.msg.debug(self.name, "Not recognized, skipping: {}".format(fullpath))
|
|
815
|
+
library_cache[filename] = None
|
|
816
|
+
|
|
817
|
+
# After we got our information, add it to our library
|
|
818
|
+
if show_id:
|
|
819
|
+
if show_id not in library:
|
|
820
|
+
library[show_id] = {}
|
|
821
|
+
for show_ep in range(show_ep_start, show_ep_end+1):
|
|
693
822
|
library[show_id][show_ep] = fullpath
|
|
823
|
+
return library, library_cache
|
|
694
824
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
825
|
+
def get_episode_path(self, show, episode):
|
|
826
|
+
"""
|
|
827
|
+
This function returns the full path of the requested episode from the requested show.
|
|
828
|
+
"""
|
|
829
|
+
|
|
830
|
+
library = self.library()
|
|
831
|
+
showid = show['id']
|
|
832
|
+
|
|
833
|
+
if showid not in library:
|
|
834
|
+
raise utils.EngineError('Show not in library.')
|
|
835
|
+
if episode not in library[showid]:
|
|
836
|
+
raise utils.EngineError('Episode not in library.')
|
|
837
|
+
|
|
838
|
+
return library[showid][episode]
|
|
699
839
|
|
|
700
840
|
def play_random(self):
|
|
701
841
|
"""
|
|
@@ -709,10 +849,9 @@ class Engine:
|
|
|
709
849
|
|
|
710
850
|
for showid, eps in library.items():
|
|
711
851
|
show = self.get_show_info(showid)
|
|
712
|
-
if show['my_progress'] + 1 in eps
|
|
852
|
+
if show['my_progress'] + 1 in eps:
|
|
713
853
|
newep.append(show)
|
|
714
854
|
|
|
715
|
-
|
|
716
855
|
if not newep:
|
|
717
856
|
raise utils.EngineError('No new episodes found to pick from.')
|
|
718
857
|
|
|
@@ -749,11 +888,16 @@ class Engine:
|
|
|
749
888
|
if show['total'] and playep > show['total']:
|
|
750
889
|
raise utils.EngineError('Episode beyond limits.')
|
|
751
890
|
|
|
752
|
-
self.
|
|
753
|
-
|
|
754
|
-
|
|
891
|
+
if self.config.get('debug_oldsearch'):
|
|
892
|
+
# Deprecated
|
|
893
|
+
self.msg.info(self.name, "Searching for %s %s..." % (show['title'], playep))
|
|
894
|
+
titles = self.data_handler.get_show_titles(show)
|
|
895
|
+
filename, endep = self._search_video(titles, playep)
|
|
896
|
+
else:
|
|
897
|
+
self.msg.info(self.name, "Getting %s %s from library..." % (show['title'], playep))
|
|
898
|
+
filename = self.get_episode_path(show, playep)
|
|
899
|
+
endep = playep
|
|
755
900
|
|
|
756
|
-
filename, endep = self._search_video(titles, playep)
|
|
757
901
|
if filename:
|
|
758
902
|
self.msg.info(self.name, 'Found. Starting player...')
|
|
759
903
|
arg_list = shlex.split(self.config['player'])
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# This file is part of
|
|
1
|
+
# This file is part of Trackma.
|
|
2
2
|
#
|
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
|
4
4
|
# it under the terms of the GNU General Public License as published by
|
|
@@ -46,8 +46,17 @@ class AnimeInfoExtractor():
|
|
|
46
46
|
def getName(self):
|
|
47
47
|
return self.name
|
|
48
48
|
|
|
49
|
-
def getEpisodeNumbers(self):
|
|
50
|
-
|
|
49
|
+
def getEpisodeNumbers(self, force_numbers=False):
|
|
50
|
+
ep_start = self.episodeStart
|
|
51
|
+
ep_end = self.episodeEnd
|
|
52
|
+
if force_numbers:
|
|
53
|
+
if ep_start is None:
|
|
54
|
+
ep_start = 1
|
|
55
|
+
if ep_end is None:
|
|
56
|
+
ep_end = ep_start
|
|
57
|
+
ep_start = int(ep_start)
|
|
58
|
+
ep_end = int(ep_end)
|
|
59
|
+
return ep_start, ep_end
|
|
51
60
|
|
|
52
61
|
def getEpisode(self):
|
|
53
62
|
ep = self.episodeStart if self.episodeEnd is None else self.episodeEnd
|
|
@@ -209,8 +218,8 @@ class AnimeInfoExtractor():
|
|
|
209
218
|
return filename
|
|
210
219
|
|
|
211
220
|
def __extractEpisodeNumbers(self, filename):
|
|
212
|
-
# First check for concurrent episodes (with a +)
|
|
213
|
-
m = re.search('[^0-9a-zA-Z](?:E\.?|Ep(?:i|isode)?s?(?: |\.)?)?(\d{1,4})
|
|
221
|
+
# First check for concurrent episodes (with a + or &)
|
|
222
|
+
m = re.search('[^0-9a-zA-Z](?:E\.?|Ep(?:i|isode)?s?(?: |\.)?)?(\d{1,4})[\+\&](\d{1,4})(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
214
223
|
if m:
|
|
215
224
|
start = int(m.group(1))
|
|
216
225
|
end = int(m.group(2))
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
trackma/lib/libanilist.py
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# GNU General Public License for more details.
|
|
12
12
|
#
|
|
13
13
|
# You should have received a copy of the GNU General Public License
|
|
14
|
-
# along with this program. If not, see <
|
|
14
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
15
15
|
#
|
|
16
16
|
|
|
17
17
|
import json
|
|
@@ -28,7 +28,7 @@ class libanilist(lib):
|
|
|
28
28
|
"""
|
|
29
29
|
API class to communicate with Anilist
|
|
30
30
|
|
|
31
|
-
Website:
|
|
31
|
+
Website: https://anilist.co
|
|
32
32
|
|
|
33
33
|
messenger: Messenger object to send useful messages to
|
|
34
34
|
"""
|
|
@@ -86,7 +86,7 @@ class libanilist(lib):
|
|
|
86
86
|
# Supported signals for the data handler
|
|
87
87
|
signals = { 'show_info_changed': None, }
|
|
88
88
|
|
|
89
|
-
url = "
|
|
89
|
+
url = "https://anilist.co/api/"
|
|
90
90
|
client_id = "z411-gdjc3"
|
|
91
91
|
_client_secret = "MyzwuYoMqPPglXwCTcexG1i"
|
|
92
92
|
|
|
@@ -106,7 +106,7 @@ class libanilist(lib):
|
|
|
106
106
|
self.airing_str = "publishing_status"
|
|
107
107
|
self.status_translate = {
|
|
108
108
|
'publishing': utils.STATUS_AIRING,
|
|
109
|
-
'finished': utils.STATUS_FINISHED,
|
|
109
|
+
'finished publishing': utils.STATUS_FINISHED,
|
|
110
110
|
'not yet published': utils.STATUS_NOTYET,
|
|
111
111
|
'cancelled': utils.STATUS_CANCELLED,
|
|
112
112
|
}
|
|
@@ -252,7 +252,7 @@ class libanilist(lib):
|
|
|
252
252
|
'total': self._c(item[self.mediatype][self.total_str]),
|
|
253
253
|
'image': item[self.mediatype]['image_url_lge'],
|
|
254
254
|
'image_thumb': item[self.mediatype]['image_url_med'],
|
|
255
|
-
'url': str("
|
|
255
|
+
'url': str("https://anilist.co/%s/%d" % (self.mediatype, showid)),
|
|
256
256
|
}
|
|
257
257
|
show.update({k:v for k,v in showdata.items() if v})
|
|
258
258
|
|
|
@@ -304,15 +304,19 @@ class libanilist(lib):
|
|
|
304
304
|
|
|
305
305
|
self.msg.info(self.name, "Searching for {}...".format(criteria))
|
|
306
306
|
param = {'access_token': self._get_userconfig('access_token')}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
#
|
|
311
|
-
#
|
|
312
|
-
|
|
307
|
+
data = self._request("GET", "{0}/search/{1}".format(self.mediatype, urllib.parse.quote_plus(criteria)), get=param)
|
|
308
|
+
|
|
309
|
+
if type(data) == dict:
|
|
310
|
+
# In case of error API returns a small JSON payload
|
|
311
|
+
# which translates into a dict with the key 'error'
|
|
312
|
+
# instead of a list.
|
|
313
|
+
if data['error']['messages'][0] == 'No Results.':
|
|
314
|
+
data = []
|
|
315
|
+
else:
|
|
316
|
+
raise utils.APIError("Error while searching for \
|
|
317
|
+
{0}: {1}".format(criteria, str(data)))
|
|
313
318
|
|
|
314
319
|
showlist = []
|
|
315
|
-
|
|
316
320
|
for item in data:
|
|
317
321
|
show = utils.show()
|
|
318
322
|
showid = item['id']
|
|
@@ -326,7 +330,7 @@ class libanilist(lib):
|
|
|
326
330
|
'total': item[self.total_str],
|
|
327
331
|
'image': item['image_url_lge'],
|
|
328
332
|
'image_thumb': item['image_url_med'],
|
|
329
|
-
'url': str("
|
|
333
|
+
'url': str("https://anilist.co/%s/%d" % (self.mediatype, showid)),
|
|
330
334
|
}
|
|
331
335
|
show.update({k:v for k,v in showdata.items() if v})
|
|
332
336
|
|
|
@@ -352,11 +356,11 @@ class libanilist(lib):
|
|
|
352
356
|
|
|
353
357
|
def _update_entry(self, item, method):
|
|
354
358
|
values = { 'id': item['id'] }
|
|
355
|
-
if 'my_progress' in item
|
|
359
|
+
if 'my_progress' in item:
|
|
356
360
|
values[self.watched_str] = item['my_progress']
|
|
357
|
-
if 'my_status' in item
|
|
361
|
+
if 'my_status' in item:
|
|
358
362
|
values['list_status'] = item['my_status']
|
|
359
|
-
if 'my_score' in item
|
|
363
|
+
if 'my_score' in item:
|
|
360
364
|
values['score'] = item['my_score']
|
|
361
365
|
|
|
362
366
|
data = self._request(method, "{}list".format(self.mediatype), post=values, auth=True)
|
|
@@ -370,7 +374,7 @@ class libanilist(lib):
|
|
|
370
374
|
'title': item['title_romaji'],
|
|
371
375
|
'status': self.status_translate[item[self.airing_str]],
|
|
372
376
|
'image': item['image_url_lge'],
|
|
373
|
-
'url': str("
|
|
377
|
+
'url': str("https://anilist.co/%s/%d" % (self.mediatype, showid)),
|
|
374
378
|
'start_date': self._str2date(item.get('start_date')),
|
|
375
379
|
'end_date': self._str2date(item.get('end_date')),
|
|
376
380
|
'extra': [
|