@ -1,5 +1,6 @@
from couchpotato . core . helpers . variable import getTitle , getIdentifier
from couchpotato . core . logger import CPLog
from couchpotato . core . media . movie . providers . automation . trakt . main import TraktBase
from couchpotato . core . notifications . base import Notification
log = CPLog ( __name__ )
@ -7,13 +8,12 @@ log = CPLog(__name__)
autoload = ' Trakt '
class Trakt ( Notification ) :
class Trakt ( Notification , TraktBase ) :
urls = {
' base ' : ' http://api.trakt.tv/ %s ' ,
' library ' : ' movie/library/ %s ' ,
' unwatchlist ' : ' movie/unwatchlist/ %s ' ,
' test ' : ' account/test/ %s ' ,
' library ' : ' sync/collection ' ,
' unwatchlist ' : ' sync/watchlist/remove ' ,
' test ' : ' sync/last_activities ' ,
}
listen_to = [ ' movie.snatched ' ]
@ -23,49 +23,22 @@ class Trakt(Notification):
if not data : data = { }
if listener == ' test ' :
post_data = {
' username ' : self . conf ( ' automation_username ' ) ,
' password ' : self . conf ( ' automation_password ' ) ,
}
result = self . call ( ( self . urls [ ' test ' ] % self . conf ( ' automation_api_key ' ) ) , post_data )
result = self . call ( ( self . urls [ ' test ' ] ) )
return result
else :
post_data = {
' username ' : self . conf ( ' automation_username ' ) ,
' password ' : self . conf ( ' automation_password ' ) ,
' movies ' : [ {
' imdb_id ' : getIdentifier ( data ) ,
' title ' : getTitle ( data ) ,
' year ' : data [ ' info ' ] [ ' year ' ]
} ] if data else [ ]
' movies ' : [ { ' ids ' : { ' imdb ' : getIdentifier ( data ) } } ] if data else [ ]
}
result = self . call ( ( self . urls [ ' library ' ] % self . conf ( ' automation_api_key ' ) ) , post_data )
result = self . call ( ( self . urls [ ' library ' ] ) , post_data )
if self . conf ( ' remove_watchlist_enabled ' ) :
result = result and self . call ( ( self . urls [ ' unwatchlist ' ] % self . conf ( ' automation_api_key ' ) ) , post_data )
result = result and self . call ( ( self . urls [ ' unwatchlist ' ] ) , post_data )
return result
def call ( self , method_url , post_data ) :
try :
response = self . getJsonData ( self . urls [ ' base ' ] % method_url , data = post_data , cache_timeout = 1 )
if response :
if response . get ( ' status ' ) == " success " :
log . info ( ' Successfully called Trakt ' )
return True
except :
pass
log . error ( ' Failed to call trakt, check your login. ' )
return False
config = [ {
' name ' : ' trakt ' ,
@ -75,7 +48,7 @@ config = [{
' list ' : ' notification_providers ' ,
' name ' : ' trakt ' ,
' label ' : ' Trakt ' ,
' description ' : ' add movies to your collection once downloaded. Fill in your username and password in the <a href= " ../automation/ " >Automation Trakt settings</a> ' ,
' description ' : ' add movies to your collection once downloaded. Connect your account in <a href= " ../automation/ " >Automation Trakt settings</a> ' ,
' options ' : [
{
' name ' : ' notification_enabled ' ,