__init__.py 2.24 KB
Newer Older
1
# Author: echel0n <[email protected]>
echel0n's avatar
echel0n committed
2
# URL: https://sickrage.ca
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#
# This file is part of SickRage.
#
# SickRage is free software: you can redistribute it and/or modify
# 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.
#
# SickRage is distributed in the hope that it will be useful,
# 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
# along with SickRage.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

echel0n's avatar
echel0n committed
21
22
23
import os

import sickrage
24
from sickrage.core.common import Quality
25
from sickrage.core.databases import srDatabase
26
27
from sickrage.core.databases.cache.index import CacheLastUpdateIndex, CacheLastSearchIndex, CacheSceneExceptionsIndex, \
    CacheSceneNamesIndex, CacheNetworkTimezonesIndex, CacheSceneExceptionsRefreshIndex, CacheProvidersIndex
28
29
30


class CacheDB(srDatabase):
echel0n's avatar
echel0n committed
31
    _indexes = {
32
33
34
35
36
37
38
        'lastUpdate': CacheLastUpdateIndex,
        'lastSearch': CacheLastSearchIndex,
        'scene_exceptions': CacheSceneExceptionsIndex,
        'scene_names': CacheSceneNamesIndex,
        'network_timezones': CacheNetworkTimezonesIndex,
        'scene_exceptions_refresh': CacheSceneExceptionsRefreshIndex,
        'providers': CacheProvidersIndex,
echel0n's avatar
echel0n committed
39
40
41
42
43
44
45
46
47
48
49
    }

    _migrate_list = {
        'lastUpdate': ['provider', 'time'],
        'lastSearch': ['provider', 'time'],
        'scene_exceptions': ['exception_id', 'indexer_id', 'show_name', 'season', 'custom'],
        'scene_names': ['indexer_id', 'name'],
        'network_timezones': ['network_name', 'timezone'],
        'scene_exceptions_refresh': ['list', 'last_refreshed'],
    }

50
51
    def __init__(self, name='cache'):
        super(CacheDB, self).__init__(name)
52
53
54
55
56
57
58
59
60
        self.old_db_path = os.path.join(sickrage.app.data_dir, 'cache.db')

    def cleanup(self):
        self.cleanup_provider_cache()

    def cleanup_provider_cache(self):
        for item in self.all('providers'):
            if int(item["quality"]) == Quality.UNKNOWN:
                self.delete(item)