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

HamaMapper.map()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 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