|
11 | 11 | from . import kodimonitor
|
12 | 12 | from . import sync, library_sync
|
13 | 13 | from . import websocket_client
|
| 14 | +from . import plex_db |
14 | 15 | from . import plex_companion
|
15 | 16 | from . import plex_functions as PF
|
16 | 17 | from . import playback_starter
|
|
19 | 20 | from . import loghandler
|
20 | 21 | from . import backgroundthread
|
21 | 22 | from . import skip_plex_markers
|
| 23 | +from . import downloadutils |
22 | 24 | from .windows import userselect
|
23 | 25 |
|
24 | 26 | ###############################################################################
|
@@ -240,6 +242,53 @@ def toggle_plex_tv(self):
|
240 | 242 | # Enable the main loop to continue
|
241 | 243 | app.APP.suspend = False
|
242 | 244 |
|
| 245 | + def watchlist_add(self, raw_params): |
| 246 | + return self.watchlist_modify('addToWatchlist', raw_params) |
| 247 | + |
| 248 | + def watchlist_remove(self, raw_params): |
| 249 | + return self.watchlist_modify('removeFromWatchlist', raw_params) |
| 250 | + |
| 251 | + def watchlist_modify(self, api_type, raw_params): |
| 252 | + params = dict(utils.parse_qsl(raw_params)) |
| 253 | + kodi_id = params.get('kodi_id') |
| 254 | + kodi_type = params.get('kodi_type') |
| 255 | + |
| 256 | + LOG.info('watchlist_modify %s %s %s', api_type, kodi_id, kodi_type) |
| 257 | + |
| 258 | + watchlist_plex_guid = None |
| 259 | + |
| 260 | + with plex_db.PlexDB(lock=False) as plexdb: |
| 261 | + plex_item = plexdb.item_by_kodi_id(kodi_id, kodi_type) |
| 262 | + if not plex_item: |
| 263 | + return False |
| 264 | + |
| 265 | + plex_guid = plex_item['plex_guid'] |
| 266 | + if not plex_guid: |
| 267 | + return False |
| 268 | + |
| 269 | + plex_type = plex_item['plex_type'] |
| 270 | + |
| 271 | + if plex_type == v.PLEX_TYPE_MOVIE or plex_type == v.PLEX_TYPE_SHOW: |
| 272 | + watchlist_plex_guid = plex_guid |
| 273 | + |
| 274 | + elif plex_type == v.PLEX_TYPE_SEASON or plex_type == v.PLEX_TYPE_EPISODE: |
| 275 | + plex_show_item = plexdb.item_by_id(plex_item['show_id'], v.PLEX_TYPE_SHOW) |
| 276 | + if plex_show_item: |
| 277 | + watchlist_plex_guid = plex_show_item['plex_guid'] |
| 278 | + |
| 279 | + if watchlist_plex_guid is None: |
| 280 | + return False |
| 281 | + |
| 282 | + # ratingKey query param accepts the last section in the plex_guid |
| 283 | + watchlist_rating_key = watchlist_plex_guid.split('/')[-1] |
| 284 | + |
| 285 | + downloadutils.DownloadUtils().downloadUrl('https://discover.provider.plex.tv/actions/%s?ratingKey=%s' % (api_type, watchlist_rating_key), |
| 286 | + action_type = 'PUT', |
| 287 | + authenticate=False, |
| 288 | + headerOptions={'X-Plex-Token': utils.window('plex_token')}) |
| 289 | + |
| 290 | + xbmc.executebuiltin('UpdateLibrary(video)') |
| 291 | + |
243 | 292 | def authenticate(self):
|
244 | 293 | """
|
245 | 294 | Authenticate the current user or prompt to log-in
|
@@ -473,6 +522,12 @@ def ServiceEntryPoint(self):
|
473 | 522 | task = playback_starter.PlaybackTask(
|
474 | 523 | 'dummy?mode=context_menu&%s'
|
475 | 524 | % plex_command.replace('CONTEXT_menu?', ''))
|
| 525 | + elif plex_command.startswith('WATCHLIST_ADD?'): |
| 526 | + task = backgroundthread.FunctionAsTask( |
| 527 | + self.watchlist_add, None, plex_command.replace('WATCHLIST_ADD?', '')) |
| 528 | + elif plex_command.startswith('WATCHLIST_REMOVE?'): |
| 529 | + task = backgroundthread.FunctionAsTask( |
| 530 | + self.watchlist_remove, None, plex_command.replace('WATCHLIST_REMOVE?', '')) |
476 | 531 | elif plex_command == 'choose_pms_server':
|
477 | 532 | task = backgroundthread.FunctionAsTask(
|
478 | 533 | self.choose_pms_server, None)
|
|
0 commit comments