|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | import copy |
3 | | -import requests |
4 | 3 | import time |
5 | | -from requests.status_codes import _codes as codes |
6 | | -from plexapi import BASE_HEADERS, CONFIG, TIMEOUT, X_PLEX_IDENTIFIER, X_PLEX_ENABLE_FAST_CONNECT |
7 | | -from plexapi import log, logfilter, utils |
| 4 | + |
| 5 | +import requests |
| 6 | +from plexapi import (BASE_HEADERS, CONFIG, TIMEOUT, X_PLEX_ENABLE_FAST_CONNECT, |
| 7 | + X_PLEX_IDENTIFIER, log, logfilter, utils) |
8 | 8 | from plexapi.base import PlexObject |
9 | 9 | from plexapi.exceptions import BadRequest, NotFound, Unauthorized |
10 | 10 | from plexapi.client import PlexClient |
11 | 11 | from plexapi.compat import ElementTree |
12 | 12 | from plexapi.library import LibrarySection |
13 | 13 | from plexapi.server import PlexServer |
14 | | -from plexapi.sync import SyncList, SyncItem |
| 14 | +from plexapi.sync import SyncItem, SyncList |
15 | 15 | from plexapi.utils import joinArgs |
| 16 | +from requests.status_codes import _codes as codes |
16 | 17 |
|
17 | 18 |
|
18 | 19 | class MyPlexAccount(PlexObject): |
@@ -73,6 +74,12 @@ class MyPlexAccount(PlexObject): |
73 | 74 | REQUESTS = 'https://plex.tv/api/invites/requests' # get |
74 | 75 | SIGNIN = 'https://plex.tv/users/sign_in.xml' # get with auth |
75 | 76 | WEBHOOKS = 'https://plex.tv/api/v2/user/webhooks' # get, post with data |
| 77 | + # Hub sections |
| 78 | + VOD = 'https://vod.provider.plex.tv/' # get |
| 79 | + WEBSHOWS = 'https://webshows.provider.plex.tv/' # get |
| 80 | + NEWS = 'https://news.provider.plex.tv/' # get |
| 81 | + PODCASTS = 'https://podcasts.provider.plex.tv/' # get |
| 82 | + MUSIC = 'https://music.provider.plex.tv/' # get |
76 | 83 | # Key may someday switch to the following url. For now the current value works. |
77 | 84 | # https://plex.tv/api/v2/user?X-Plex-Token={token}&X-Plex-Client-Identifier={clientId} |
78 | 85 | key = 'https://plex.tv/users/account' |
@@ -388,8 +395,8 @@ def updateFriend(self, user, server, sections=None, removeSections=False, allowS |
388 | 395 | params = {'server_id': machineId, 'shared_server': {'library_section_ids': sectionIds}} |
389 | 396 | url = self.FRIENDSERVERS.format(machineId=machineId, serverId=serverId) |
390 | 397 | else: |
391 | | - params = {'server_id': machineId, 'shared_server': {'library_section_ids': sectionIds, |
392 | | - 'invited_id': user.id}} |
| 398 | + params = {'server_id': machineId, |
| 399 | + 'shared_server': {'library_section_ids': sectionIds, 'invited_id': user.id}} |
393 | 400 | url = self.FRIENDINVITE.format(machineId=machineId) |
394 | 401 | # Remove share sections, add shares to user without shares, or update shares |
395 | 402 | if not user_servers or sectionIds: |
@@ -433,7 +440,7 @@ def user(self, username): |
433 | 440 | return user |
434 | 441 |
|
435 | 442 | elif (user.username and user.email and user.id and username.lower() in |
436 | | - (user.username.lower(), user.email.lower(), str(user.id))): |
| 443 | + (user.username.lower(), user.email.lower(), str(user.id))): |
437 | 444 | return user |
438 | 445 |
|
439 | 446 | raise NotFound('Unable to find user %s' % username) |
@@ -617,6 +624,41 @@ def history(self, maxresults=9999999, mindate=None): |
617 | 624 | hist.extend(conn.history(maxresults=maxresults, mindate=mindate, accountID=1)) |
618 | 625 | return hist |
619 | 626 |
|
| 627 | + def videoOnDemand(self): |
| 628 | + """ Returns a list of VOD Hub items :class:`~plexapi.library.Hub` |
| 629 | + """ |
| 630 | + req = requests.get(self.VOD + 'hubs/', headers={'X-Plex-Token': self._token}) |
| 631 | + elem = ElementTree.fromstring(req.text) |
| 632 | + return self.findItems(elem) |
| 633 | + |
| 634 | + def webShows(self): |
| 635 | + """ Returns a list of Webshow Hub items :class:`~plexapi.library.Hub` |
| 636 | + """ |
| 637 | + req = requests.get(self.WEBSHOWS + 'hubs/', headers={'X-Plex-Token': self._token}) |
| 638 | + elem = ElementTree.fromstring(req.text) |
| 639 | + return self.findItems(elem) |
| 640 | + |
| 641 | + def news(self): |
| 642 | + """ Returns a list of News Hub items :class:`~plexapi.library.Hub` |
| 643 | + """ |
| 644 | + req = requests.get(self.NEWS + 'hubs/sections/all', headers={'X-Plex-Token': self._token}) |
| 645 | + elem = ElementTree.fromstring(req.text) |
| 646 | + return self.findItems(elem) |
| 647 | + |
| 648 | + def podcasts(self): |
| 649 | + """ Returns a list of Podcasts Hub items :class:`~plexapi.library.Hub` |
| 650 | + """ |
| 651 | + req = requests.get(self.PODCASTS + 'hubs/', headers={'X-Plex-Token': self._token}) |
| 652 | + elem = ElementTree.fromstring(req.text) |
| 653 | + return self.findItems(elem) |
| 654 | + |
| 655 | + def tidal(self): |
| 656 | + """ Returns a list of tidal Hub items :class:`~plexapi.library.Hub` |
| 657 | + """ |
| 658 | + req = requests.get(self.MUSIC + 'hubs/', headers={'X-Plex-Token': self._token}) |
| 659 | + elem = ElementTree.fromstring(req.text) |
| 660 | + return self.findItems(elem) |
| 661 | + |
620 | 662 |
|
621 | 663 | class MyPlexUser(PlexObject): |
622 | 664 | """ This object represents non-signed in users such as friends and linked |
|
0 commit comments