Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic support for Watch Together feature #698

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion plexapi/myplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy
import threading
import time
from typing import List
from xml.etree import ElementTree

import requests
Expand All @@ -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

Expand Down Expand Up @@ -83,6 +85,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'
Expand Down Expand Up @@ -689,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.

Expand Down
49 changes: 49 additions & 0 deletions plexapi/together.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
import requests

from plexapi import utils


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