2014-12-28 22:21:58 -05:00
|
|
|
"""
|
|
|
|
PlexAPI Examples
|
|
|
|
|
|
|
|
As of Plex version 0.9.11 I noticed that you must be logged in
|
|
|
|
to browse even the plex server locatewd at localhost. You can
|
|
|
|
run this example suite with the following command:
|
|
|
|
|
|
|
|
>> python examples.py -u <USERNAME> -p <PASSWORD> -s <SERVERNAME>
|
|
|
|
"""
|
|
|
|
import argparse, sys
|
|
|
|
from os.path import dirname, abspath
|
|
|
|
sys.path.append(dirname(dirname(abspath(__file__))))
|
|
|
|
from utils import fetch_server, iter_tests
|
|
|
|
|
|
|
|
|
|
|
|
def example_001_list_all_unwatched_content(plex):
|
|
|
|
""" Example 1: List all unwatched content in library """
|
|
|
|
for section in plex.library.sections():
|
2015-02-17 15:35:17 -05:00
|
|
|
print('Unwatched content in %s:' % section.title)
|
2014-12-28 22:21:58 -05:00
|
|
|
for video in section.unwatched():
|
2015-02-17 15:35:17 -05:00
|
|
|
print(' %s' % video.title)
|
2014-12-28 22:21:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
def example_002_mark_all_conan_episodes_watched(plex):
|
|
|
|
""" Example 2: Mark all Conan episodes watched. """
|
|
|
|
plex.library.get('Conan (2010)').markWatched()
|
|
|
|
|
|
|
|
|
|
|
|
def example_003_list_all_clients(plex):
|
|
|
|
""" Example 3: List all Clients connected to the Server. """
|
|
|
|
for client in plex.clients():
|
2015-02-17 15:35:17 -05:00
|
|
|
print(client.name)
|
2014-12-28 22:21:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
def example_004_play_avatar_on_iphone(plex):
|
|
|
|
""" Example 4: Play the Movie Avatar on my iPhone. """
|
|
|
|
avatar = plex.library.section('Movies').get('Avatar')
|
|
|
|
client = plex.client("Michael's iPhone")
|
|
|
|
client.playMedia(avatar)
|
|
|
|
|
|
|
|
|
|
|
|
def example_005_search(plex):
|
|
|
|
""" Example 5: List all content with the word 'Game' in the title. """
|
|
|
|
for video in plex.search('Game'):
|
2015-02-17 15:35:17 -05:00
|
|
|
print('%s (%s)' % (video.title, video.TYPE))
|
2014-12-28 22:21:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
def example_006_follow_the_talent(plex):
|
|
|
|
""" Example 6: List all movies directed by the same person as Jurassic Park. """
|
|
|
|
jurassic_park = plex.library.section('Movies').get('Jurassic Park')
|
|
|
|
director = jurassic_park.directors[0]
|
|
|
|
for movie in director.related():
|
2015-02-17 15:35:17 -05:00
|
|
|
print(movie.title)
|
2014-12-28 22:21:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
def example_007_list_files(plex):
|
|
|
|
""" Example 7: List files for the latest episode of Friends. """
|
2014-12-29 00:15:37 -05:00
|
|
|
the_last_one = plex.library.section('TV Shows').get('Friends').episodes()[-1]
|
2014-12-28 22:21:58 -05:00
|
|
|
for part in the_last_one.iter_parts():
|
2015-02-17 15:35:17 -05:00
|
|
|
print(part.file)
|
2014-12-28 22:21:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='Run PlexAPI examples.')
|
|
|
|
parser.add_argument('-s', '--server', help='Name of the Plex server (requires user/pass).')
|
|
|
|
parser.add_argument('-u', '--username', help='Username for the Plex server.')
|
|
|
|
parser.add_argument('-p', '--password', help='Password for the Plex server.')
|
|
|
|
parser.add_argument('-n', '--name', help='Only run tests containing this string. Leave blank to run all examples.')
|
|
|
|
args = parser.parse_args()
|
|
|
|
plex = fetch_server(args)
|
|
|
|
for example in iter_tests(__name__, args):
|
|
|
|
example(plex)
|
|
|
|
|