__init__.py 2.73 KB
Newer Older
1
# Author: echel0n <[email protected]>
echel0n's avatar
echel0n committed
2
# URL: https://sickrage.ca
3
#
echel0n's avatar
echel0n committed
4
# This file is part of SiCKRAGE.
5
#
echel0n's avatar
echel0n committed
6
# SiCKRAGE is free software: you can redistribute it and/or modify
7
8
9
10
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
echel0n's avatar
echel0n committed
11
# SiCKRAGE is distributed in the hope that it will be useful,
12
13
14
15
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
echel0n's avatar
echel0n committed
17
# along with SiCKRAGE.  If not, see <http://www.gnu.org/licenses/>.
18

19
import re
echel0n's avatar
echel0n committed
20
21

import sickrage
22
from sickrage.indexers.config import indexerConfig
echel0n's avatar
echel0n committed
23
from sickrage.indexers.ui import ShowListUI
echel0n's avatar
echel0n committed
24
25


26
class IndexerApi(object):
27
    def __init__(self, indexerID=1):
28
        self.indexerID = indexerID
29
        self.module = indexerConfig[self.indexerID]['module']
echel0n's avatar
echel0n committed
30
31

    def indexer(self, *args, **kwargs):
32
33
        self.module.settings(*args, **kwargs)
        return self.module
echel0n's avatar
echel0n committed
34
35
36

    @property
    def config(self):
37
        return indexerConfig[self.indexerID]
echel0n's avatar
echel0n committed
38
39
40

    @property
    def name(self):
41
        return indexerConfig[self.indexerID]['name']
echel0n's avatar
echel0n committed
42

echel0n's avatar
echel0n committed
43
44
45
46
    @property
    def trakt_id(self):
        return indexerConfig[self.indexerID]['trakt_id']

echel0n's avatar
echel0n committed
47
48
    @property
    def api_params(self):
49
50
        if sickrage.app.config.proxy_setting and sickrage.app.config.proxy_indexers:
            indexerConfig[self.indexerID]['api_params']['proxy'] = sickrage.app.config.proxy_setting
echel0n's avatar
echel0n committed
51

52
        return indexerConfig[self.indexerID]['api_params']
echel0n's avatar
echel0n committed
53
54
55

    @property
    def cache(self):
56
        return self.api_params['cache']
echel0n's avatar
echel0n committed
57
58
59

    @property
    def indexers(self):
60
        return dict((int(x['id']), x['name']) for x in indexerConfig.values())
echel0n's avatar
echel0n committed
61

echel0n's avatar
echel0n committed
62
63
64
65
    @property
    def indexersByTraktID(self):
        return dict((x['trakt_id'], int(x['id'])) for x in indexerConfig.values())

66
    def search_for_show_id(self, show_name, custom_ui=None):
67
68
69
        """
        Contacts indexer to check for information on shows by showid

70
71
        :param show_name: Name of show
        :param custom_ui: Custom UI for indexer use
72
73
74
        :return:
        """

75
        show_name = re.sub('[. -]', ' ', show_name)
76
77
78

        # Query Indexers for each search term and build the list of results
        lINDEXER_API_PARMS = self.api_params.copy()
79
        lINDEXER_API_PARMS['custom_ui'] = custom_ui or ShowListUI
80

81
        sickrage.app.log.debug("Trying to find show ID for show {} on indexer {}".format(show_name, self.name))
82

83
84
85
86
87
88
        t = self.indexer(**lINDEXER_API_PARMS)
        indexer_data = t[show_name]
        if not indexer_data:
            return

        return indexer_data['id']