Test Failed
Push — beta ( c9094c...317f5f )
by Dean
03:05
created

HamaMapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A map_tvdb3() 0 19 4
A __init__() 0 2 1
A map() 0 9 2
1
class HamaMapper(object):
2
    def __init__(self, mapper):
3
        self.mapper = mapper
4
5
    def map(self, source, key, identifier=None, resolve_mappings=True):
6
        if source == 'tvdb3':
7
            return self.map_tvdb3(
8
                key,
9
                identifier=identifier,
10
                resolve_mappings=resolve_mappings
11
            )
12
13
        return False, None
14
15
    def map_tvdb3(self, key, identifier=None, resolve_mappings=True):
16
        # Find matching anidb service identifier
17
        supported, match = self.mapper.map(
18
            'tvdb', key,
19
            resolve_mappings=False,
20
            use_handlers=False
21
        )
22
23
        if not supported:
24
            return False, None
25
26
        if not match.identifiers or not match.identifiers.get('anidb'):
27
            return False, None
28
29
        # Map episode identifier with the `anidb_id` we've found
30
        return self.mapper.map(
31
            'anidb', match.identifiers['anidb'],
32
            identifier=identifier,
33
            resolve_mappings=resolve_mappings
34
        )
35