Beispiel #1
0

def example_008_get_stream_url(plex):
    """ Example 8: Get a URL you can open in VLC, MPV, etc. """
    jurassic_park = plex.library.section('Movies').get('Jurassic Park')
    print('Try running the following command:')
    print('vlc "%s"' % jurassic_park.getStreamUrl(videoResolution='800x600'))


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Run PlexAPI examples.')
    parser.add_argument('-r',
                        '--resource',
                        help='Name of the Plex resource (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, user = fetch_server(args)
    for example in iter_tests(__name__, args):
        example(plex)
Beispiel #2
0
    jurassic_park = movies.get('Jurassic Park')
    director = jurassic_park.directors[0]
    for movie in movies.search(None, director=director):
        print(movie.title)


def example_007_list_files(plex):
    """ Example 7: List files for the latest episode of Friends. """
    the_last_one = plex.library.section('TV Shows').get('Friends').episodes()[-1]
    for part in the_last_one.iter_parts():
        print(part.file)


def example_008_get_stream_url(plex):
    """ Example 8: Get a URL you can open in VLC, MPV, etc. """
    jurassic_park = plex.library.section('Movies').get('Jurassic Park')
    print('Try running the following command:')
    print('vlc "%s"' % jurassic_park.getStreamUrl(videoResolution='800x600'))


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Run PlexAPI examples.')
    parser.add_argument('-r', '--resource', help='Name of the Plex resource (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, user = fetch_server(args)
    for example in iter_tests(__name__, args):
        example(plex)
@register()
def most_active_users(plex):
    """ Example 10: List the most active users. """
    users = defaultdict(int)
    for item in plex.history():
        print(item.TYPE)
        users[item.username] += 1
    users = sorted(users.items(), key=lambda x:x[1], reverse=True)
    for user, count in users[:5]:
        print('%s (%s plays)' % (user, count))
    

if __name__ == '__main__':
    # There are three ways to authenticate:
    #  1. If the server is running on localhost, just run without any auth.
    #  2. Pass in --username, --password, and --resource.
    #  3. Pass in --baseurl, --token
    parser = argparse.ArgumentParser(description='Run PlexAPI examples.')
    parser.add_argument('-u', '--username', help='Username for your MyPlex account.')
    parser.add_argument('-p', '--password', help='Password for your MyPlex account.')
    parser.add_argument('-r', '--resource', help='Name of the Plex resource (requires user/pass).')
    parser.add_argument('-b', '--baseurl', help='Baseurl needed for auth token authentication')
    parser.add_argument('-t', '--token', help='Auth token (instead of user/pass)')
    parser.add_argument('-q', '--example', help='Only run the specified example.')
    parser.add_argument('-v', '--verbose', default=False, action='store_true', help='Print verbose logging.')
    args = parser.parse_args()
    plex, account = fetch_server(args)
    for example in iter_tests(args.example):
        example['func'](plex)
Beispiel #4
0
    #  2. Pass in --username, --password, and --resource.
    #  3. Pass in --baseurl, --token
    parser = argparse.ArgumentParser(description='Run PlexAPI examples.')
    parser.add_argument('-u',
                        '--username',
                        help='Username for your MyPlex account.')
    parser.add_argument('-p',
                        '--password',
                        help='Password for your MyPlex account.')
    parser.add_argument('-r',
                        '--resource',
                        help='Name of the Plex resource (requires user/pass).')
    parser.add_argument('-b',
                        '--baseurl',
                        help='Baseurl needed for auth token authentication')
    parser.add_argument('-t',
                        '--token',
                        help='Auth token (instead of user/pass)')
    parser.add_argument('-q',
                        '--example',
                        help='Only run the specified example.')
    parser.add_argument('-v',
                        '--verbose',
                        default=False,
                        action='store_true',
                        help='Print verbose logging.')
    args = parser.parse_args()
    plex, account = fetch_server(args)
    for example in iter_tests(args.example):
        example['func'](plex)