diff --git a/src/main.js b/src/main.js index f311eb5..02ef160 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,7 @@ let plexToken = ''; let plexMachineId; let couchpotatoUrlRoot = ''; let couchpotatoToken = ''; +let couchpotatoBasicAuth = null; function isMoviePage() { const path = window.location.pathname; @@ -52,6 +53,12 @@ chrome.storage.sync.get(null, function(items) { plexMachineId = items.plexMachineId; couchpotatoUrlRoot = items.couchpotatoUrlRoot; couchpotatoToken = items.couchpotatoToken; + if (items.couchpotatoBasicAuthUsername) { + couchpotatoBasicAuth = { + username: items.couchpotatoBasicAuthUsername, + password: items.couchpotatoBasicAuthPassword, + }; + } if (!plexToken || !plexMachineId || !items.plexLibraryId || !items.plexUrlRoot) { showNotification('warning', 'Not all options for the Movieo to Plex extension are filled in.'); @@ -170,8 +177,7 @@ function addToCouchpotato(action) { } axios.get(viewUrl, { params: { id: imdbId }, - headers: { - }, + auth: couchpotatoBasicAuth, }) .then((res) => { const movieExists = res.data.success; @@ -191,9 +197,7 @@ function addToCouchpotato(action) { function addToCouchPotatoRequest(url, imdbId) { axios.get(url, { params: { identifier: imdbId }, - headers: { - Authorization: 'Basic a2Vlczpib25rZXJzdGVpbg==', - }, + auth: couchpotatoBasicAuth, }) .then((res) => { showNotification('info', 'Added movie on CouchPotato.'); diff --git a/src/options.html b/src/options.html index 06e7ef3..1186ae2 100644 --- a/src/options.html +++ b/src/options.html @@ -47,6 +47,18 @@ Example: aa756d33242f6g8ffbca2b3963586f21

+

+ CouchPotato basic auth username (optional): +
+ If you password-protected your CouchPotato install, enter the username here. +

+ +

+ CouchPotato basic auth password (optional): +
+ If you password-protected your CouchPotato install, enter the password here. +

+
diff --git a/src/options.js b/src/options.js index cbe13d3..7d97d2d 100644 --- a/src/options.js +++ b/src/options.js @@ -6,6 +6,8 @@ function saveOptions() { var plexLibraryId = document.getElementById('plex_library_id').value; var couchpotatoUrlRoot = document.getElementById('couchpotato_url_root').value; var couchpotatoToken = document.getElementById('couchpotato_token').value; + var couchpotatoBasicAuthUsername = document.getElementById('couchpotato_basic_auth_username').value; + var couchpotatoBasicAuthPassword = document.getElementById('couchpotato_basic_auth_password').value; chrome.storage.sync.set({ plexToken, plexMachineId, @@ -13,6 +15,8 @@ function saveOptions() { plexLibraryId, couchpotatoUrlRoot, couchpotatoToken, + couchpotatoBasicAuthUsername, + couchpotatoBasicAuthPassword, }, function() { // Update status to let user know options were saved. var status = document.getElementById('status'); @@ -34,6 +38,8 @@ function restoreOptions() { document.getElementById('plex_library_id').value = items.plexLibraryId || ''; document.getElementById('couchpotato_url_root').value = items.couchpotatoUrlRoot || ''; document.getElementById('couchpotato_token').value = items.couchpotatoToken || ''; + document.getElementById('couchpotato_basic_auth_username').value = items.couchpotatoBasicAuthUsername || ''; + document.getElementById('couchpotato_basic_auth_password').value = items.couchpotatoBasicAuthPassword || ''; }); } document.addEventListener('DOMContentLoaded', restoreOptions);