Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / addons / metadata.tvshows.themoviedb.org.python / libs / settings.py
blob3d6cf7d367c687c85e255dbe3d77ef94ae4b1424
1 # -*- coding: UTF-8 -*-
3 # Copyright (C) 2020, Team Kodi
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # pylint: disable=missing-docstring
19 import json
20 import sys
21 import urllib.parse
22 from .utils import logger
23 from . import api_utils
24 from xbmcaddon import Addon
25 from datetime import datetime, timedelta
28 def _get_date_numeric(datetime_):
29 return (datetime_ - datetime(1970, 1, 1)).total_seconds()
32 def _get_configuration():
33 logger.debug('getting configuration details')
34 return api_utils.load_info('https://api.themoviedb.org/3/configuration', params={'api_key': TMDB_CLOWNCAR}, verboselog=VERBOSELOG)
37 def _load_base_urls():
38 image_root_url = ADDON.getSettingString('originalUrl')
39 preview_root_url = ADDON.getSettingString('previewUrl')
40 last_updated = ADDON.getSettingString('lastUpdated')
41 if not image_root_url or not preview_root_url or not last_updated or \
42 float(last_updated) < _get_date_numeric(datetime.now() - timedelta(days=30)):
43 conf = _get_configuration()
44 if conf:
45 image_root_url = conf['images']['secure_base_url'] + 'original'
46 preview_root_url = conf['images']['secure_base_url'] + 'w780'
47 ADDON.setSetting('originalUrl', image_root_url)
48 ADDON.setSetting('previewUrl', preview_root_url)
49 ADDON.setSetting('lastUpdated', str(
50 _get_date_numeric(datetime.now())))
51 return image_root_url, preview_root_url
54 ADDON = Addon()
55 TMDB_CLOWNCAR = 'af3a53eb387d57fc935e9128468b1899'
56 FANARTTV_CLOWNCAR = 'b018086af0e1478479adfc55634db97d'
57 TRAKT_CLOWNCAR = '90901c6be3b2de5a4fa0edf9ab5c75e9a5a0fef2b4ee7373d8b63dcf61f95697'
58 MAXIMAGES = 200
59 FANARTTV_MAPPING = {'showbackground': 'backdrops',
60 'tvposter': 'posters',
61 'tvbanner': 'banner',
62 'hdtvlogo': 'clearlogo',
63 'clearlogo': 'clearlogo',
64 'hdclearart': 'clearart',
65 'clearart': 'clearart',
66 'tvthumb': 'landscape',
67 'characterart': 'characterart',
68 'seasonposter': 'seasonposters',
69 'seasonbanner': 'seasonbanner',
70 'seasonthumb': 'seasonlandscape'
73 try:
74 source_params = dict(urllib.parse.parse_qsl(sys.argv[2]))
75 except IndexError:
76 source_params = {}
77 source_settings = json.loads(source_params.get('pathSettings', '{}'))
79 KEEPTITLE = source_settings.get(
80 'keeporiginaltitle', ADDON.getSettingBool('keeporiginaltitle'))
81 CATLANDSCAPE = source_settings.get('cat_landscape', True)
82 STUDIOCOUNTRY = source_settings.get('studio_country', False)
83 ENABTRAILER = source_settings.get(
84 'enab_trailer', ADDON.getSettingBool('enab_trailer'))
85 PLAYERSOPT = source_settings.get(
86 'players_opt', ADDON.getSettingString('players_opt')).lower()
87 VERBOSELOG = source_settings.get(
88 'verboselog', ADDON.getSettingBool('verboselog'))
89 LANG = source_settings.get('language', ADDON.getSettingString('language'))
90 CERT_COUNTRY = source_settings.get(
91 'tmdbcertcountry', ADDON.getSettingString('tmdbcertcountry')).lower()
92 IMAGEROOTURL, PREVIEWROOTURL = _load_base_urls()
94 if source_settings.get('usecertprefix', ADDON.getSettingBool('usecertprefix')):
95 CERT_PREFIX = source_settings.get(
96 'certprefix', ADDON.getSettingString('certprefix'))
97 else:
98 CERT_PREFIX = ''
99 primary_rating = source_settings.get(
100 'ratings', ADDON.getSettingString('ratings')).lower()
101 RATING_TYPES = [primary_rating]
102 if source_settings.get('imdbanyway', ADDON.getSettingBool('imdbanyway')) and primary_rating != 'imdb':
103 RATING_TYPES.append('imdb')
104 if source_settings.get('traktanyway', ADDON.getSettingBool('traktanyway')) and primary_rating != 'trakt':
105 RATING_TYPES.append('trakt')
106 if source_settings.get('tmdbanyway', ADDON.getSettingBool('tmdbanyway')) and primary_rating != 'tmdb':
107 RATING_TYPES.append('tmdb')
108 FANARTTV_ENABLE = source_settings.get(
109 'enable_fanarttv', ADDON.getSettingBool('enable_fanarttv'))
110 FANARTTV_CLIENTKEY = source_settings.get(
111 'fanarttv_clientkey', ADDON.getSettingString('fanarttv_clientkey'))