Passed
Push — master ( b25270...aeb165 )
by Dean
03:03
created

Base.on_added()   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
            if type(t_value) is tuple:
18
                data['t_previous'], data['t_value'] = t_value
19
            else:
20
                data['t_value'] = t_value
21
22
        data.update(kwargs)
23
        return data
24
25 1
    def scrobble(self, key):
26
        action_mode = self.configuration['sync.action.mode']
27
28
        if action_mode == SyncActionMode.Update:
29
            return Plex['library'].scrobble(key)
30
31
        if action_mode == SyncActionMode.Log:
32
            log.info('[%s] scrobble()', key)
33
            return True
34
35
        raise NotImplementedError('Unable to update plex, action mode %r not supported', action_mode)
36
37 1
    def unscrobble(self, key):
38
        action_mode = self.configuration['sync.action.mode']
39
40
        if action_mode == SyncActionMode.Update:
41
            return Plex['library'].unscrobble(key)
42
43
        if action_mode == SyncActionMode.Log:
44
            log.info('[%s] unscrobble()', key)
45
            return True
46
47
        raise NotImplementedError('Unable to update plex, action mode %r not supported', action_mode)
48
49
    #
50
    # Handlers
51
    #
52
53 1
    @bind('added')
54
    def on_added(self, key, p_value, t_value, **kwargs):
55
        log.debug('%s.on_added(%r, %r, %r)', self.media, key, p_value, t_value)
56
57
        if p_value is not None:
58
            # Already scrobbled
59
            return
60
61
        return self.scrobble(key)
62
63 1
    @bind('removed', [SyncMode.Full, SyncMode.FastPull])
64
    def on_removed(self, key, p_value, **kwargs):
65
        log.debug('%s.on_removed(%r, %r)', self.media, key, p_value)
66
67
        if p_value is None:
68
            # Already un-scrobbled
69
            return
70
71
        return self.unscrobble(key)
72
73
74 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...
75 1
    media = SyncMedia.Movies
76
77
78 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...
79 1
    media = SyncMedia.Episodes
80
81
82 1
class Pull(DataHandler):
83 1
    data = SyncData.Watched
84 1
    mode = [SyncMode.FastPull, SyncMode.Pull]
85
86 1
    children = [
87
        Movies,
88
        Episodes
89
    ]
90