@@ -181,33 +181,59 @@ UpdateConfiguration();
181181// these requests in a background page instead of the content script?
182182// This is because Movieo is served over HTTPS, so it won't accept requests to
183183// HTTP servers. Unfortunately, many people use CouchPotato over HTTP.
184- function Open_CouchPotato ( request , sendResponse ) {
184+ function Query_CouchPotato ( request , sendResponse ) {
185185 fetch ( `${ request . url } ?id=${ request . imdbId } ` , {
186186 headers : new Headers ( request . basicAuth ) ,
187187 mode : cors ( request . url )
188188 } )
189189 . then ( response => response . json ( ) )
190190 . then ( json => {
191+ let { success } = json ;
192+
191193 sendResponse ( { success, status : ( success ? json . media . status : null ) } ) ;
192194 } )
193195 . catch ( error => {
194- sendResponse ( { error : String ( error ) , location : '@0B: Open_CouchPotato ' } ) ;
196+ sendResponse ( { error : String ( error ) , location : '@0B: Query_CouchPotato ' } ) ;
195197 } ) ;
196198}
197199
198200function Push_CouchPotato ( request , sendResponse ) {
199- fetch ( `${ request . url } ?identifier=${ request . imdbId } ` , {
201+ let headers = {
202+ 'Content-Type' : 'application/json' ,
203+ 'X-Api-Key' : request . token ,
204+ ...( new Headers ( request . basicAuth ) )
205+ } ,
206+ query = `identifier=${ request . imdbId } ` ,
207+ debug = { headers, query, request } ;
208+
209+ fetch ( debug . url = `${ request . url } ?${ query } ` , {
210+ method : 'POST' ,
211+ mode : cors ( request . url ) ,
212+ // body: JSON.stringify(body),
213+ headers,
214+ } )
215+ . then ( response => response . json ( ) )
216+ . catch ( error => sendResponse ( { error : 'Movie not found' , location : '@0B: Push_CouchPotato => fetch.then.catch' , silent : true } ) )
217+ . then ( response => {
218+ sendResponse ( { success : response . success } ) ;
219+ } )
220+ . catch ( error => {
221+ sendResponse ( {
222+ error : String ( error ) ,
223+ location : '@0B: Push_CouchPotato => fetch("${ request.url }", { headers }).catch(error => { sendResponse })' ,
224+ debug
225+ } ) ;
226+ } ) ;
227+ }
228+
229+ function Charge_CouchPotato ( request , sendResponse ) {
230+ fetch ( request . url , {
200231 headers : new Headers ( request . basicAuth ) ,
201232 mode : cors ( request . url )
202233 } )
203234 . then ( response => response . json ( ) )
204- . catch ( error => sendResponse ( { error : 'Item not found' , location : '@0B: Push_CouchPotato => fetch.then.catch' , silent : true } ) )
205- . then ( response => {
206- sendResponse ( { success : response . success } ) ;
207- } )
208- . catch ( error => {
209- sendResponse ( { error : String ( error ) , location : '@0B: Push_CouchPotato' } ) ;
210- } ) ;
235+ . then ( json => sendResponse ( json ) )
236+ . catch ( error => sendResponse ( { error : String ( error ) , location : '@0B: Charge_CouchPotato' } ) ) ;
211237}
212238
213239/** Watcher - Movies **/
@@ -303,7 +329,7 @@ function Push_Radarr(request, sendResponse) {
303329 . then ( body => {
304330 return fetch ( `${ request . url } ?apikey=${ request . token } ` , debug . requestHeaders = {
305331 method : 'POST' ,
306- mode : cors ( request . url ) ,
332+ // mode: cors(request.url),
307333 body : JSON . stringify ( body ) ,
308334 headers
309335 } ) ;
@@ -383,7 +409,7 @@ function Push_Sonarr(request, sendResponse) {
383409 . then ( body => {
384410 return fetch ( `${ request . url } ?apikey=${ request . token } ` , debug . requestHeaders = {
385411 method : 'POST' ,
386- mode : cors ( request . url ) ,
412+ // mode: cors(request.url),
387413 body : JSON . stringify ( body ) ,
388414 headers
389415 } ) ;
@@ -455,7 +481,7 @@ function Push_Medusa(request, sendResponse) {
455481 . then ( body => {
456482 return fetch ( `${ request . url } ` , debug . requestHeaders = {
457483 method : 'POST' ,
458- mode : cors ( request . url ) ,
484+ // mode: cors(request.url),
459485 body : JSON . stringify ( { id : { tvdb : id } } ) ,
460486 headers
461487 } ) ;
@@ -529,7 +555,7 @@ function addMedusa(request, sendResponse) {
529555 . then ( body => {
530556 return fetch ( `${ request . url } ` , debug . requestHeaders = {
531557 method : 'POST' ,
532- mode : cors ( request . url ) ,
558+ // mode: cors(request.url),
533559 body : JSON . stringify ( { id : { tvdb : id } } ) ,
534560 headers
535561 } ) ;
@@ -611,7 +637,7 @@ function Push_SickBeard(request, sendResponse) {
611637
612638 return fetch ( `${ request . url } ?cmd=show.${ request . exists ? 'addexisting' : 'addnew' } &${ body } ` , debug . requestHeaders = {
613639 method : 'POST' ,
614- mode : cors ( request . url ) ,
640+ // mode: cors(request.url),
615641 // body: JSON.stringify(body),
616642 headers
617643 } ) ;
@@ -659,8 +685,8 @@ function Push_Ombi(request, sendResponse) {
659685 } ,
660686 type = request . contentType ,
661687 id = ( type == 'movie' ? request . tmdbId : request . tvdbId ) ,
662- body = ( { [ type == 'movie' ? 'theMovieDbId' : 'theTvDbId ' ] : id } ) ,
663- debug = { headers, request } ;
688+ body = ( { [ type == 'movie' ? 'theMovieDbId' : 'tvDbId ' ] : id , requestAll : true , lastestSeason : true , firstSeason : true } ) ,
689+ debug = { headers, body , request } ;
664690 // setup stack trace for debugging
665691
666692 if ( request . contentType == 'movie' && ( id || null ) === null )
@@ -670,11 +696,11 @@ function Push_Ombi(request, sendResponse) {
670696
671697 fetch ( debug . url = request . url , {
672698 method : 'POST' ,
673- mode : cors ( request . url ) ,
699+ // mode: cors(request.url),
674700 body : JSON . stringify ( body ) ,
675701 headers
676702 } )
677- . catch ( error => sendResponse ( { error : `${ type } not found` , location : '@0B: Push_Ombi => fetch.then.catch' , silent : true } ) )
703+ . catch ( error => sendResponse ( { error : `${ type } not found` , location : '@0B: Push_Ombi => fetch.then.catch' , debug , silent : true } ) )
678704 . then ( response => response . text ( ) )
679705 . then ( data => {
680706 debug . data =
@@ -859,7 +885,7 @@ browser.contextMenus.onClicked.addListener(item => {
859885 url = external . SEARCH_PROVIDER == 'VO' ?
860886 `google.com/search?q=${ p ( tl ) } +site:vumoo.to` :
861887 external . SEARCH_PROVIDER == 'GX' ?
862- `gostream.site/ ?s=${ p ( tl ) } ` :
888+ `gostream.site?s=${ p ( tl ) } ` :
863889 `google.com/search?q="${ p ( tl , ' ' ) } ${ yr } "+${ pv } db` ;
864890 break ;
865891 case 'dl' :
@@ -911,8 +937,12 @@ browser.runtime.onMessage.addListener((request = {}, sender, callback) => {
911937 Search_Plex ( request , callback ) ;
912938 break ;
913939
914- case 'VIEW_COUCHPOTATO' :
915- Open_CouchPotato ( request , callback ) ;
940+ case 'CHARGE_COUCHPOTATO' :
941+ Charge_CouchPotato ( request , callback ) ;
942+ break ;
943+
944+ case 'QUERY_COUCHPOTATO' :
945+ Query_CouchPotato ( request , callback ) ;
916946 break ;
917947
918948 case 'PUSH_COUCHPOTATO' :
0 commit comments