From 50e59e73944f317ee95dfc39d76e110abbe67315 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 28 Jul 2018 09:47:23 +1000 Subject: [PATCH] Updated API keys for external services, allow API key override (#309) --- src/js/app.coffee | 4 ++++ .../apps/settings/show/local/local_controller.js.coffee | 9 +++++++++ src/js/entities/external/fanarttv.js.coffee | 4 ++-- src/js/entities/external/themoviedb.js.coffee | 6 +++--- src/js/entities/external/youtube.js.coffee | 4 ++-- src/js/helpers/config.js.coffee | 5 +++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/js/app.coffee b/src/js/app.coffee index 0c3cc79e..06050094 100755 --- a/src/js/app.coffee +++ b/src/js/app.coffee @@ -26,6 +26,10 @@ showDeviceName: false refreshIgnoreNFO: true largeBreakpoint: 910 + apiKeyTMDB: '' + apiKeyTVDB: '' + apiKeyFanartTv: '' + apiKeyYouTube: '' } ## The App Instance diff --git a/src/js/apps/settings/show/local/local_controller.js.coffee b/src/js/apps/settings/show/local/local_controller.js.coffee index 0a448962..66c4cf3d 100755 --- a/src/js/apps/settings/show/local/local_controller.js.coffee +++ b/src/js/apps/settings/show/local/local_controller.js.coffee @@ -74,6 +74,15 @@ {id: 'refreshIgnoreNFO', title: tr("Refresh Ignore NFO"), type: 'checkbox', defaultValue: true, description: tr('Ignore local NFO files when manually refreshing media.')} ] } + { + title: 'API Keys' + id: 'apikeys' + children:[ + {id: 'apiKeyTMDB', title: tr("The Movie DB"), type: 'textfield', defaultValue: '', description: tr("Set your own TMDB API key.")} + {id: 'apiKeyFanartTv', title: tr("FanartTV"), type: 'textfield', defaultValue: '', description: tr("Set your own FanartTv API key.")} + {id: 'apiKeyYouTube', title: tr("YouTube"), type: 'textfield', defaultValue: '', description: tr("Set your own YouTube API key.")} + ] + } ] ## Get settings from local storage diff --git a/src/js/entities/external/fanarttv.js.coffee b/src/js/entities/external/fanarttv.js.coffee index 971c2d69..4e3946f8 100755 --- a/src/js/entities/external/fanarttv.js.coffee +++ b/src/js/entities/external/fanarttv.js.coffee @@ -3,7 +3,7 @@ API = # Using the Kodi API key - apiKey: 'ed4b784f97227358b31ca4dd966a04f1' + apiKey: 'ZWQ0Yjc4NGY5NzIyNzM1OGIzMWNhNGRkOTY2YTA0ZjE=' # V3 of API baseURL: 'http://webservice.fanart.tv/v3/' @@ -18,7 +18,7 @@ ## Make a call to API call: (path, params, callback) -> defaultParams = - api_key: @apiKey + api_key: config.getAPIKey('apiKeyFanartTv', @apiKey) params = _.extend defaultParams, params url = @baseURL + path + helpers.url.buildParams(params) req = $.getJSON url, (resp) -> diff --git a/src/js/entities/external/themoviedb.js.coffee b/src/js/entities/external/themoviedb.js.coffee index f11f8c73..686695f7 100755 --- a/src/js/entities/external/themoviedb.js.coffee +++ b/src/js/entities/external/themoviedb.js.coffee @@ -2,8 +2,8 @@ API = - # Using the Kodi API key - apiKey: 'ecbc86c92da237cb9faff6d3ddc4be6d' + # API Key + apiKey: 'NzFiYTFmMDdlZDBmYzhmYjM2MWNmMDRhNThkNzUwNTE=' # V3 of API baseURL: 'https://api.themoviedb.org/3/' @@ -29,7 +29,7 @@ ## Make a call to API call: (path, params, callback) -> defaultParams = - api_key: @apiKey + api_key: config.getAPIKey('apiKeyTMDB', @apiKey) params = _.extend defaultParams, params url = @baseURL + path + helpers.url.buildParams(params) + '&callback=?' $.getJSON url, (resp) -> diff --git a/src/js/entities/external/youtube.js.coffee b/src/js/entities/external/youtube.js.coffee index 2f23a62d..5f7128d7 100755 --- a/src/js/entities/external/youtube.js.coffee +++ b/src/js/entities/external/youtube.js.coffee @@ -5,7 +5,7 @@ API = - apiKey: 'AIzaSyBxvaR6mCnUWN8cv2TiPRmuEh0FykBTAH0' + apiKey: 'QUl6YVN5Qnh2YVI2bUNuVVdOOGN2MlRpUFJtdUVoMEZ5a0JUQUgw' searchUrl: 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&videoDefinition=any&videoEmbeddable=true&order=relevance&safeSearch=none' maxResults: 5 @@ -13,7 +13,7 @@ ytURL: 'https://youtu.be/' getSearchUrl: -> - @searchUrl + '&key=' + @apiKey + @searchUrl + '&key=' + config.getAPIKey('apiKeyYouTube', @apiKey) parseItems: (response) -> items = [] diff --git a/src/js/helpers/config.js.coffee b/src/js/helpers/config.js.coffee index 65875543..8e3c3ce8 100755 --- a/src/js/helpers/config.js.coffee +++ b/src/js/helpers/config.js.coffee @@ -29,6 +29,11 @@ config.setLocal = (id, data, callback) -> config.setLocalApp = () -> config.set 'static', id, data, callback +# A wrapper for getting an API Key. +config.getAPIKey = (id, defaultData = '') -> + key = config.getLocal id, '' + return if key is '' then atob(defaultData) else key + # Wrapper for getting a config value before app has started. # Should always try and use config.get() before this. config.preStartGet = (id, defaultData = '') ->