|
1
|
1 |
|
from plugin.sync.core.enums import SyncData, SyncMode |
|
2
|
1 |
|
from plugin.sync.modes.core.base import Mode |
|
3
|
|
|
|
|
4
|
1 |
|
from trakt_sync.cache.main import Cache |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
1 |
|
class Base(Mode): |
|
|
|
|
|
|
8
|
1 |
|
mode = SyncMode.FastPull |
|
9
|
|
|
|
|
10
|
1 |
|
def iter_changes(self, media, pk): |
|
11
|
|
|
for key, result in self.trakt.changes: |
|
12
|
|
|
c_media, c_data = key[0:2] |
|
13
|
|
|
|
|
14
|
|
|
if c_media != media: |
|
15
|
|
|
# Ignore changes that aren't for `media` |
|
16
|
|
|
continue |
|
17
|
|
|
|
|
18
|
|
|
if c_data == SyncData.Watchlist: |
|
19
|
|
|
# Ignore watchlist data |
|
20
|
|
|
continue |
|
21
|
|
|
|
|
22
|
|
|
if not self.is_data_enabled(c_data): |
|
23
|
|
|
# Data type has been disabled |
|
24
|
|
|
continue |
|
25
|
|
|
|
|
26
|
|
|
data_name = Cache.Data.get(c_data) |
|
27
|
|
|
|
|
28
|
|
|
if data_name not in result.changes: |
|
29
|
|
|
# No changes for collection |
|
30
|
|
|
continue |
|
31
|
|
|
|
|
32
|
|
|
for c_action, items in result.changes[data_name].items(): |
|
33
|
|
|
t_item = items.get(pk) |
|
34
|
|
|
|
|
35
|
|
|
if t_item is None: |
|
36
|
|
|
# No item found in changes |
|
37
|
|
|
continue |
|
38
|
|
|
|
|
39
|
|
|
yield c_data, c_action, t_item |
|
40
|
|
|
|
|
41
|
1 |
|
def should_pull(self, p_id, p_added_at): |
|
42
|
|
|
if not self.current.kwargs.get('pull'): |
|
43
|
|
|
return False |
|
44
|
|
|
|
|
45
|
|
|
pull = self.current.kwargs['pull'] |
|
46
|
|
|
|
|
47
|
|
|
# Check `p_id` is inside the `ids` parameter |
|
48
|
|
|
if p_id in pull.get('ids', set()): |
|
49
|
|
|
return True |
|
50
|
|
|
|
|
51
|
|
|
# Check `p_added_at` timestamp is after the `created_since` parameter |
|
52
|
|
|
if p_added_at and pull.get('created_since') and p_added_at > pull['created_since']: |
|
53
|
|
|
return True |
|
54
|
|
|
|
|
55
|
|
|
return False |
|
56
|
|
|
|
Methods which raise
NotImplementedErrorshould be overridden in concrete child classes.