|
1
|
1 |
|
from plugin.core.session_status import SessionStatus |
|
2
|
1 |
|
from plugin.sync.core.enums import SyncData, SyncMedia, SyncMode |
|
3
|
1 |
|
from plugin.sync.handlers.core import DataHandler, PushHandler, bind |
|
4
|
1 |
|
from plugin.sync.handlers.watched.base import WatchedHandler |
|
5
|
|
|
|
|
6
|
1 |
|
import logging |
|
7
|
|
|
|
|
8
|
1 |
|
log = logging.getLogger(__name__) |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
1 |
|
class Base(PushHandler, WatchedHandler): |
|
|
|
|
|
|
12
|
1 |
|
def push(self, p_item, t_item, key, **kwargs): |
|
13
|
|
|
# Ensure item isn't currently being watched in plex |
|
14
|
|
|
if SessionStatus.is_watching(self.current.account.id, key): |
|
15
|
|
|
log.debug('Item %r is currently being watched, ignoring push watched handler', key) |
|
16
|
|
|
return |
|
17
|
|
|
|
|
18
|
|
|
super(Base, self).push( |
|
19
|
|
|
p_item, t_item, |
|
20
|
|
|
key=key, |
|
21
|
|
|
**kwargs |
|
22
|
|
|
) |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
1 |
|
class Movies(Base): |
|
|
|
|
|
|
26
|
1 |
|
media = SyncMedia.Movies |
|
27
|
|
|
|
|
28
|
1 |
|
@bind('added', [SyncMode.Full, SyncMode.Push]) |
|
29
|
|
|
def on_added(self, key, guid, p_item, p_value, t_value, **kwargs): |
|
30
|
|
|
# Retrieve plex `view_count` |
|
31
|
|
|
p_settings = p_item.get('settings', {}) |
|
32
|
|
|
p_view_count = p_settings.get('view_count', 0) |
|
33
|
|
|
|
|
34
|
|
|
log.debug('Movies.on_added(%r, ...) - p_view_count: %r, p_value: %r, t_value: %r', key, p_view_count, p_value, t_value) |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
if t_value: |
|
37
|
|
|
return |
|
38
|
|
|
|
|
39
|
|
|
self.store_movie('add', guid, |
|
40
|
|
|
p_item, |
|
41
|
|
|
watched_at=p_value |
|
42
|
|
|
) |
|
43
|
|
|
|
|
44
|
1 |
|
@bind('removed', [SyncMode.Full, SyncMode.Push]) |
|
45
|
|
|
def on_removed(self, key, t_value, **kwargs): |
|
|
|
|
|
|
46
|
|
|
log.debug('Movies.on_removed(%r, ...)', key) |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
1 |
|
class Episodes(Base): |
|
|
|
|
|
|
50
|
1 |
|
media = SyncMedia.Episodes |
|
51
|
|
|
|
|
52
|
1 |
|
@bind('added', [SyncMode.Full, SyncMode.Push]) |
|
53
|
|
|
def on_added(self, key, guid, identifier, p_show, p_item, p_value, t_value, **kwargs): |
|
54
|
|
|
# Retrieve plex `view_count` |
|
55
|
|
|
p_settings = p_item.get('settings', {}) |
|
56
|
|
|
p_view_count = p_settings.get('view_count', 0) |
|
57
|
|
|
|
|
58
|
|
|
log.debug('Episodes.on_added(%r, ...) - p_view_count: %r, p_value: %r, t_value: %r', key, p_view_count, p_value, t_value) |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
if t_value: |
|
61
|
|
|
return |
|
62
|
|
|
|
|
63
|
|
|
self.store_episode('add', guid, |
|
64
|
|
|
identifier, p_show, |
|
65
|
|
|
watched_at=p_value |
|
66
|
|
|
) |
|
67
|
|
|
|
|
68
|
1 |
|
@bind('removed', [SyncMode.Full, SyncMode.Push]) |
|
69
|
|
|
def on_removed(self, key, t_value, **kwargs): |
|
|
|
|
|
|
70
|
|
|
log.debug('Episodes.on_removed(%r, ...)', key) |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
1 |
|
class Push(DataHandler): |
|
74
|
1 |
|
data = SyncData.Watched |
|
75
|
1 |
|
mode = SyncMode.Push |
|
76
|
|
|
|
|
77
|
1 |
|
children = [ |
|
78
|
|
|
Movies, |
|
79
|
|
|
Episodes |
|
80
|
|
|
] |
|
81
|
|
|
|
Methods which raise
NotImplementedErrorshould be overridden in concrete child classes.