Skip to content

Commit

Permalink
Added ability to read downloaded status from Radarr (#468)
Browse files Browse the repository at this point in the history
* Bumped up version number to reflect latest release.

version.txt is still at 1.20.2 when it should be 1.20.3

* Bump version number

* Fix adding movies to CouchPotato

As well restores the ability to create movie requests even when
CouchPotato or Radarr aren't available.

* Fix indentation

* Fix update.txt

* Added the ability to read downloaded status from Radarr.

* Reverting to avoid future issues.

* Bumped version number.

Turned off logging for SyncedCron (had it turned on for testing).
Changed radarr timeout for response back to 15000.
  • Loading branch information
ohmar authored and RickyGrassmuck committed Sep 27, 2017
1 parent 2bd3098 commit 1e48ecf
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 38 deletions.
8 changes: 4 additions & 4 deletions lib/exports/radarrExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Radarr.radarrProfilesGet = function() {
return Meteor.call('radarrProfilesGet', {})
}

Radarr.radarrMovieStats = function(id) {
return Meteor.call('radarrMovieStats', id, {})
}

Radarr.radarrMovieGet = function(id) {
return Meteor.call('radarrMovieGet', id, {})
}

Radarr.radarrMovieStatus = function(id) {
return Meteor.call('radarrMovieStatus', id, {})
}

// Radarr.seriesDelete = function(tmdbId) {
// return Meteor.call("radarrMovieDelete", tmdbId, {});
// };
Expand Down
5 changes: 3 additions & 2 deletions server/methods/cronjobs/updateRadarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Meteor.methods({
var movies = Movies.find({downloaded: false, approval_status: 1})

movies.forEach(function (movie) {
var result = Radarr.mediaGet(movie.imdb)
var status = result.status == 'done'
var result = Radarr.radarrMovieStatus(movie.id)
var status = result.status === true

if (result.status === 'false') {
// Not in Radarr anymore
Expand All @@ -18,5 +18,6 @@ Meteor.methods({
Movies.update(movie, {$set: {downloaded: status}})
}
})
return true
}
})
119 changes: 89 additions & 30 deletions server/methods/helpers/movies/radarrMethods.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@


Meteor.methods({

radarrProfilesGet: function() {
try {
check(Radarr.url, String)
Expand Down Expand Up @@ -33,28 +30,28 @@ Meteor.methods({
},

radarrMovieAdd: function(request, settings) {
check(request, Object) //TODO - create true check that verifies the values needed are actually set.
check(settings, Object)
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)

check(request.id, Number)
check(request.title, String)
check(request.year, String)
try {
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)

check(settings.radarrQUALITYPROFILEID, Number)
check(settings.radarrROOTFOLDERPATH, String)
check(settings.radarrMINAVAILABILITY, String)
check(request.id, Number)
check(request.title, String)
check(request.year, String)
check(settings.radarrQUALITYPROFILEID, Number)
check(settings.radarrROOTFOLDERPATH, String)

} catch (e) {
logger.debug('Radarr Movie Post -> ' + e.message)
return false
}
//Workaround to allow self-signed SSL certs, however can be dangerous and should not be used in production, looking into better way
//But it's possible there's nothing much I can do
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

var options = {'searchForMovie': 'true'}

try {

var response = HTTP.post(Radarr.url + ':' + Radarr.port + Radarr.directory + '/api/movie', {
headers: {'X-Api-Key':Radarr.api},
data: {
Expand All @@ -63,15 +60,13 @@ Meteor.methods({
'year': request.year,
'qualityProfileId': settings.radarrQUALITYPROFILEID,
'rootFolderPath': settings.radarrROOTFOLDERPATH,
'minimumAvailability': settings.radarrMINAVAILABILITY,
'titleSlug': request.title,
'monitored': 'true',
'images': [],
'addOptions': options
},
timeout: 15000
}
)
})

} catch (e) {
logger.debug('Radarr Movie Post -> ' + e.message)
Expand All @@ -82,13 +77,17 @@ Meteor.methods({
},

radarrSystemStatus: function() {
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)
try {
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)
} catch (e) {
logger.debug('Radarr Status -> ' + e.message)
return false
}

//Workaround to allow self-signed SSL certs, however can be dangerous and should not be used in production, looking into better way
//But it's possible there's nothing much I can do
// TODO - Need to create a settings option that enables this only when needed
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

try {
Expand All @@ -103,11 +102,20 @@ Meteor.methods({
},

radarrMovieGet: function(tmdbId) {
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)
check(tmdbId, Number)

/*
Returns JSON object of movie data if found
else:
false if not
*/
try {
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)
check(tmdbId, Number)
} catch (e) {
logger.debug('Radarr Movie Get -> ' + e.message)
return false
}

//Workaround to allow self-signed SSL certs, however can be dangerous and should not be used in production, looking into better way
//But it's possible there's nothing much I can do
Expand Down Expand Up @@ -136,7 +144,58 @@ Meteor.methods({
logger.log('debug', 'Returned false')
return false
}
}
},

})
radarrMovieStatus: function(tmdbId) {
try {
check(Radarr.url, String)
check(Radarr.port, Number)
check(Radarr.api, String)
check(tmdbId, Number)
} catch (e) {
logger.debug('Radarr Movie Get -> ' + e.message)
return false
}

var result = {}

//Workaround to allow self-signed SSL certs, however can be dangerous and should not be used in production, looking into better way
//But it's possible there's nothing much I can do
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

try {
var allMovies = HTTP.get(Radarr.url + ':' + Radarr.port + Radarr.directory + '/api/movie', {headers: {'X-Api-Key':Radarr.api}, timeout: 15000} )
} catch (e) {
logger.debug('Radarr Movie Get -> ' + e.message)
return false
}

var radarrId

_.each(allMovies.data, function (movie) {
if (movie.tmdbId === tmdbId) {
radarrId = movie.id
}
})

try {
var response = HTTP.call('GET', Radarr.url + ':' + Radarr.port + Radarr.directory + '/api/movie/' + radarrId, {headers: {'X-Api-Key':Radarr.api}, timeout: 15000} )
} catch (e) {
logger.debug(e)
return false
}

if (response.data.downloaded) {
result.status = response.data.downloaded
result.title = response.data.title
result.year = response.data.year || ''
result.id = response.data.id
result.imdb = response.data.imdbId || ''
result.tmdb_id = response.data.tmdbId || ''
} else {
result = false
}

return result
}
})
2 changes: 1 addition & 1 deletion server/startup/cronjobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ SyncedCron.add({
},
job: function() {
Meteor.call('updateCP')
Meteor.call('updateRadarr')
Meteor.call('updateSickRage')
Meteor.call('updateSonarr')
Meteor.call('updateRadarr')
logger.info('Updating download status')
return true
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20.8
1.20.9

0 comments on commit 1e48ecf

Please sign in to comment.