From fbbe339c70a1cda70efcc53d0ece52f5378ab6f0 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Wed, 17 Mar 2021 20:58:36 -0600 Subject: [PATCH 1/3] Added Watch Together URL --- plexapi/myplex.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plexapi/myplex.py b/plexapi/myplex.py index 84970dafd..2cfed5c7a 100644 --- a/plexapi/myplex.py +++ b/plexapi/myplex.py @@ -83,6 +83,7 @@ class MyPlexAccount(PlexObject): NEWS = 'https://news.provider.plex.tv/' # get PODCASTS = 'https://podcasts.provider.plex.tv/' # get MUSIC = 'https://music.provider.plex.tv/' # get + TOGETHER = 'https://together.plex.tv/' # get # Key may someday switch to the following url. For now the current value works. # https://plex.tv/api/v2/user?X-Plex-Token={token}&X-Plex-Client-Identifier={clientId} key = 'https://plex.tv/users/account' From 4242e69ada9b29f45d4ef7ab5a620b257e99f42f Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Wed, 17 Mar 2021 20:50:14 -0600 Subject: [PATCH 2/3] Basic implementation of Watch Together (get live details) --- plexapi/myplex.py | 8 ++++++- plexapi/together.py | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 plexapi/together.py diff --git a/plexapi/myplex.py b/plexapi/myplex.py index 2cfed5c7a..517df1986 100644 --- a/plexapi/myplex.py +++ b/plexapi/myplex.py @@ -2,6 +2,7 @@ import copy import threading import time +from typing import List from xml.etree import ElementTree import requests @@ -14,6 +15,7 @@ from plexapi.server import PlexServer from plexapi.sonos import PlexSonosClient from plexapi.sync import SyncItem, SyncList +from plexapi.together import Together from plexapi.utils import joinArgs from requests.status_codes import _codes as codes @@ -690,12 +692,16 @@ def podcasts(self): return self.findItems(elem) def tidal(self): - """ Returns a list of tidal Hub items :class:`~plexapi.library.Hub` + """ Returns a list of Tidal Hub items :class:`~plexapi.library.Hub` """ req = requests.get(self.MUSIC + 'hubs/', headers={'X-Plex-Token': self._token}) elem = ElementTree.fromstring(req.text) return self.findItems(elem) + @property + def watch_together(self) -> Together: + return Together(endpoint=self.TOGETHER, token=self._token) # returns JSON, not XML + def link(self, pin): """ Link a device to the account using a pin code. diff --git a/plexapi/together.py b/plexapi/together.py new file mode 100644 index 000000000..5ad7df6cd --- /dev/null +++ b/plexapi/together.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +import os +from typing import List +from urllib.parse import quote_plus, urlencode +from datetime import datetime +import requests + +from plexapi import media, utils, settings, library +from plexapi.base import PlexObject, Playable, PlexPartialObject +from plexapi.exceptions import BadRequest, NotFound +from plexapi.media import Session +from plexapi.video import Video +from requests.status_codes import _codes as codes + + +class RoomUser: + """ Represents a single RoomUser.""" + + def __init__(self, data): + self._data = data + self.id = data.get('id') + self.subscription = data.get('subscription') + self.thumbUri = data.get('thumb') + self.username = data.get('title') + self.uuid = data.get('uuid') + + +class Room: + """ Represents a single Room.""" + + def __init__(self, data): + self._data = data + self.endsAt = utils.toDatetime(data.get('endsAt')) + self.id = data.get('id') + self.sourceUri = data.get('sourceUri') + self.startsAt = utils.toDatetime(data.get('startsAt')) + self.syncplayHost = data.get('syncplayHost') + self.syncplayPort = data.get('syncplayPort') + self.title = data.get('title') + self.users = [RoomUser(user) for user in data.get('users', [])] + self.updatedAt = utils.toDatetime(data.get('updatedAt')) + self.source = data.get('source') + + +class Together: + def __init__(self, endpoint, token): + self.endpoint = endpoint + self._token = token + + @property + def rooms(self): + rooms = [] + res = requests.get(self.endpoint + 'rooms', headers={'X-Plex-Token': self._token}) + if res: + data = res.json() + for room in data.get('rooms', []): + rooms.append(Room(room)) + return rooms From f091c0a034e9edb21f8cf7543ce00d55e91b6287 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Wed, 17 Mar 2021 21:09:36 -0600 Subject: [PATCH 3/3] Remove unnecessary imports from together.py --- plexapi/together.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/plexapi/together.py b/plexapi/together.py index 5ad7df6cd..899556a56 100644 --- a/plexapi/together.py +++ b/plexapi/together.py @@ -1,16 +1,7 @@ # -*- coding: utf-8 -*- -import os -from typing import List -from urllib.parse import quote_plus, urlencode -from datetime import datetime import requests -from plexapi import media, utils, settings, library -from plexapi.base import PlexObject, Playable, PlexPartialObject -from plexapi.exceptions import BadRequest, NotFound -from plexapi.media import Session -from plexapi.video import Video -from requests.status_codes import _codes as codes +from plexapi import utils class RoomUser: