Passed
Push — develop ( 09db92...a965d8 )
by Dean
02:19
created

Base.on_removed()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.048
Metric Value
cc 2
dl 0
loc 9
ccs 1
cts 5
cp 0.2
crap 4.048
rs 9.6666
1 1
from plugin.sync.core.enums import SyncData, SyncMedia, SyncMode, SyncActionMode
2 1
from plugin.sync.handlers.core import DataHandler, PullHandler, bind
3 1
from plugin.sync.handlers.watched.base import WatchedHandler
4
5 1
from plex import Plex
6 1
import logging
7
8 1
log = logging.getLogger(__name__)
9
10
11 1
class Base(PullHandler, WatchedHandler):
0 ignored issues
show
Bug introduced by
The method full which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method on_changed which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method push which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
12 1
    @staticmethod
13
    def build_action(action, p_item, t_value, **kwargs):
0 ignored issues
show
Unused Code introduced by
The argument p_item seems to be unused.
Loading history...
14
        data = {}
15
16
        if action in ['added', 'changed']:
17
            data['t_value'] = t_value
18
19
        data.update(kwargs)
20
        return data
21
22 1
    def scrobble(self, key):
23
        action_mode = self.configuration['sync.action.mode']
24
25
        if action_mode == SyncActionMode.Update:
26
            return Plex['library'].scrobble(key)
27
28
        if action_mode == SyncActionMode.Log:
29
            log.info('[%s] scrobble()', key)
30
            return True
31
32
        raise NotImplementedError('Unable to update plex, action mode %r not supported', action_mode)
33
34 1
    def unscrobble(self, key):
35
        action_mode = self.configuration['sync.action.mode']
36
37
        if action_mode == SyncActionMode.Update:
38
            return Plex['library'].unscrobble(key)
39
40
        if action_mode == SyncActionMode.Log:
41
            log.info('[%s] unscrobble()', key)
42
            return True
43
44
        raise NotImplementedError('Unable to update plex, action mode %r not supported', action_mode)
45
46
    #
47
    # Handlers
48
    #
49
50 1
    @bind('added')
51
    def on_added(self, key, p_value, t_value, **kwargs):
52
        log.debug('%s.on_added(%r, %r, %r)', self.media, key, p_value, t_value)
53
54
        if p_value is not None:
55
            # Already scrobbled
56
            return
57
58
        return self.scrobble(key)
59
60 1
    @bind('removed', [SyncMode.Full, SyncMode.FastPull])
61
    def on_removed(self, key, p_value, **kwargs):
62
        log.debug('%s.on_removed(%r, %r)', self.media, key, p_value)
63
64
        if p_value is None:
65
            # Already un-scrobbled
66
            return
67
68
        return self.unscrobble(key)
69
70
71 1
class Movies(Base):
0 ignored issues
show
Bug introduced by
The method full which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method on_changed which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method push which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
72 1
    media = SyncMedia.Movies
73
74
75 1
class Episodes(Base):
0 ignored issues
show
Bug introduced by
The method full which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method on_changed which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
Bug introduced by
The method push which was declared abstract in the super-class MediaHandler
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
76 1
    media = SyncMedia.Episodes
77
78
79 1
class Pull(DataHandler):
80 1
    data = SyncData.Watched
81 1
    mode = [SyncMode.FastPull, SyncMode.Pull]
82
83 1
    children = [
84
        Movies,
85
        Episodes
86
    ]
87