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

Episodes

Complexity

Total Complexity 0

Size/Duplication

Total Lines 2
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 2
ccs 2
cts 2
cp 1
wmc 0
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.ratings.base import RatingsHandler
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, RatingsHandler):
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 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, p_value, 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
        if action == 'changed':
23
            data['p_value'] = p_value
24
25
        data.update(kwargs)
26
        return data
27
28 1
    def rate(self, key, value):
29
        action_mode = self.configuration['sync.action.mode']
30
31
        if action_mode == SyncActionMode.Update:
32
            return Plex['library'].rate(key, value)
33
34
        if action_mode == SyncActionMode.Log:
35
            log.info('[%s] rate(%r)', key, value)
36
            return True
37
38
        raise NotImplementedError('Unable to update plex, action mode %r not supported', action_mode)
39
40
    #
41
    # Handlers
42
    #
43
44 1
    @bind('added')
45
    def on_added(self, key, t_value, **kwargs):
46
        log.debug('%s.on_added(%r, %r)', self.media, key, t_value)
47
48
        return self.rate(key, t_value)
49
50 1
    @bind('changed', [SyncMode.Full, SyncMode.FastPull])
51
    def on_changed(self, key, p_value, t_previous, t_value, **kwargs):
52
        log.debug('%s.on_changed(%r, %r, %r, %r)', self.media, key, p_value, t_previous, t_value)
53
54
        return self.rate(key, t_value)
55
56 1
    @bind('removed', [SyncMode.Full, SyncMode.FastPull])
57
    def on_removed(self, key, **kwargs):
58
        log.debug('%s.on_removed(%r)', self.media, key)
59
60
        return self.rate(key, 0)
61
62
63 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 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...
64 1
    media = SyncMedia.Movies
65
66
67 1
class Shows(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 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...
68 1
    media = SyncMedia.Shows
69
70
71 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 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.Episodes
73
74
75 1
class Pull(DataHandler):
76 1
    data = SyncData.Ratings
77 1
    mode = [SyncMode.FastPull, SyncMode.Pull]
78
79 1
    children = [
80
        Movies,
81
82
        Shows,
83
        Episodes
84
    ]
85