Skip to content

Commit

Permalink
Created watch session rating_key getter/setter to cleanly handle mi…
Browse files Browse the repository at this point in the history
…grations
  • Loading branch information
fuzeman committed Feb 28, 2015
1 parent 4cb561c commit 7452433
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
53 changes: 37 additions & 16 deletions Trakttv.bundle/Contents/Code/data/watch_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WatchSession(Model):
actions_sent = Property(lambda: [])
actions_performed = Property(lambda: [])

rating_key = Property(None)
rating_key_ = Property(None)

def __init__(self, key, metadata, guid, rating_key, state, session=None):
super(WatchSession, self).__init__(key)
Expand Down Expand Up @@ -62,17 +62,9 @@ def __init__(self, key, metadata, guid, rating_key, state, session=None):
self.identifier_ = None
self.user_ = None

@property
def type(self):
if not self.metadata or not self.metadata.type:
return None

media_type = self.metadata.type

if media_type == 'episode':
return 'show'

return media_type
#
# Properties
#

@property
def identifier(self):
Expand All @@ -84,6 +76,20 @@ def identifier(self):

return self.identifier_

@property
def rating_key(self):
if self.rating_key_:
return self.rating_key_

if self.metadata:
return self.metadata.rating_key

return None

@rating_key.setter
def rating_key(self, value):
self.rating_key_ = value

@property
def title(self):
if not self.metadata:
Expand All @@ -94,6 +100,18 @@ def title(self):

return self.metadata.title

@property
def type(self):
if not self.metadata or not self.metadata.type:
return None

media_type = self.metadata.type

if media_type == 'episode':
return 'show'

return media_type

@property
def user(self):
if self.session:
Expand All @@ -105,6 +123,10 @@ def user(self):
def user(self, value):
self.user_ = value

#
# Methods
#

def reset(self):
self.active = False

Expand Down Expand Up @@ -164,13 +186,13 @@ def process_actions(self):
# Build action key
if self.type == 'show':
action_key = self.action_manager.build_key(
self.metadata.rating_key,
self.rating_key,
self.cur_episode,
self.identifier
)
else:
action_key = self.action_manager.build_key(
self.metadata.rating_key,
self.rating_key,
)

# Queue action with `ActionManager`
Expand Down Expand Up @@ -228,8 +250,7 @@ def is_active(cls, rating_key, f_validate=None):

sessions = cls.all(lambda ws:
ws.metadata and
(ws.rating_key == rating_key or
ws.metadata.rating_key == rating_key)
ws.rating_key == rating_key
)

for key, ws in sessions:
Expand Down
2 changes: 1 addition & 1 deletion Trakttv.bundle/Contents/Code/pts/scrobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def match(session, key, f_current, f_validate, f_check=None, f_transform=None, n

if f_validate(value, f_allow, f_deny):
log.info('Ignoring item [%s](%s) played by filtered "%s": %s' % (
session.metadata.rating_key if session.metadata else None,
session.rating_key,
session.title,
key, repr(f_current())
))
Expand Down

0 comments on commit 7452433

Please sign in to comment.