Add check to see if serverTo and serverFrom are the same. If same, then

use ratingKey instead of searching by name.
This commit is contained in:
Blacktwin 2019-06-04 09:02:21 -04:00
parent a7a6a9381d
commit 5179aa7175

View File

@ -348,31 +348,39 @@ def check_users_access(access, user, server_name, libraries=None):
exit() exit()
def sync_watch_status(watched, section, accountTo, userTo): def sync_watch_status(watched, section, accountTo, userTo, same_server=False):
""" """
Parameters Parameters
---------- ----------
watched: list watched: list
List of watched items either from Tautulli or Plex List of watched items either from Tautulli or Plex
section: class section: str
Section class of sync from server Section title of sync from server
accountTo: class
User's account that will be synced to
userTo: str userTo: str
User's server class of sync to user User's server class of sync to user
same_server: bool
Are serverFrom and serverTo the same
""" """
print('Marking watched...') print('Marking watched...')
sectionTo = accountTo.library.section(section) sectionTo = accountTo.library.section(section)
for item in watched: for item in watched:
print(item)
try: try:
if item.type == 'episode': if same_server:
show_name = item.grandparentTitle fetch_check = sectionTo.fetchItem(item.ratingKey)
show = sectionTo.get(show_name)
watch_check = show.episode(season=int(item.parentIndex), episode=int(item.index))
else: else:
title = item.title if item.type == 'episode':
watch_check = sectionTo.get(title) show_name = item.grandparentTitle
# .get retrieves a partial object show = sectionTo.get(show_name)
# .fetchItem retrieves a full object watch_check = show.episode(season=int(item.parentIndex), episode=int(item.index))
fetch_check = sectionTo.fetchItem(watch_check.key) else:
title = item.title
watch_check = sectionTo.get(title)
# .get retrieves a partial object
# .fetchItem retrieves a full object
fetch_check = sectionTo.fetchItem(watch_check.key)
# If item is already watched ignore # If item is already watched ignore
if not fetch_check.isWatched: if not fetch_check.isWatched:
# todo-me should watched count be synced? # todo-me should watched count be synced?
@ -407,6 +415,7 @@ if __name__ == '__main__':
libraries = [] libraries = []
all_sections = {} all_sections = {}
watchedFrom = '' watchedFrom = ''
same_server = False
count = 25 count = 25
start = 0 start = 0
plex_admin = Plex(PLEX_TOKEN) plex_admin = Plex(PLEX_TOKEN)
@ -486,7 +495,9 @@ if __name__ == '__main__':
for user in plexTo: for user in plexTo:
username, server = user username, server = user
sync_watch_status(watched_lst, _library.title, server, username) if server == serverFrom:
same_server = True
sync_watch_status(watched_lst, _library.title, server, username, same_server)
elif opts.ratingKey and serverFrom == "Tautulli": elif opts.ratingKey and serverFrom == "Tautulli":
plexTo = [] plexTo = []