How to use the plexapi.myplex.MyPlexAccount function in PlexAPI

To help you get started, we’ve selected a few PlexAPI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blacktwin / JBOPS / utility / purge_removed_plex_friends.py View on Github external
PLEX_USERNAME = ''
PLEX_PASSWORD = ''

# Do you want to back up the database before deleting?
BACKUP_DB = True

# Do not edit past this line #

# Grab config vars if not set in script
TAUTULLI_URL = TAUTULLI_URL or CONFIG.data['auth'].get('tautulli_baseurl')
TAUTULLI_API_KEY = TAUTULLI_API_KEY or CONFIG.data['auth'].get('tautulli_apikey')
PLEX_USERNAME = PLEX_USERNAME or CONFIG.data['auth'].get('myplex_username')
PLEX_PASSWORD = PLEX_PASSWORD or CONFIG.data['auth'].get('myplex_password')

account = MyPlexAccount(PLEX_USERNAME, PLEX_PASSWORD)

session = Session()
session.params = {'apikey': TAUTULLI_API_KEY}
formatted_url = f'{TAUTULLI_URL}/api/v2'

request = session.get(formatted_url, params={'cmd': 'get_user_names'})

tautulli_users = None
try:
    tautulli_users = request.json()['response']['data']
except JSONDecodeError:
    exit("Error talking to Tautulli API, please check your TAUTULLI_URL")

plex_friend_ids = [friend.id for friend in account.users()]
plex_friend_ids.extend((0, int(account.id)))
removed_users = [user for user in tautulli_users if user['user_id'] not in plex_friend_ids]
github home-assistant / home-assistant / homeassistant / components / sensor / plex.py View on Github external
def __init__(self, name, plex_url, plex_user, plex_password,
                 plex_server, plex_token):
        """Initialize the sensor."""
        from plexapi.myplex import MyPlexAccount
        from plexapi.server import PlexServer

        self._name = name
        self._state = 0
        self._now_playing = []

        if plex_token:
            self._server = PlexServer(plex_url, plex_token)
        elif plex_user and plex_password:
            user = MyPlexAccount(plex_user, plex_password)
            server = plex_server if plex_server else user.resources()[0].name
            self._server = user.resource(server).connect()
        else:
            self._server = PlexServer(plex_url)
github pkkid / python-plexapi / plexapi / myplex.py View on Github external
def __init__(self, username=None, password=None, token=None, session=None, timeout=None):
        self._token = token
        self._session = session or requests.Session()
        data, initpath = self._signin(username, password, timeout)
        super(MyPlexAccount, self).__init__(self, data, initpath)
github pkkid / python-plexapi / tools / plex-gettoken.py View on Github external
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Plex-GetToken is a simple method to retrieve a Plex account token.
"""
from plexapi.myplex import MyPlexAccount

username = input("Plex username: ")
password = input("Plex password: ")

account = MyPlexAccount(username, password)
print(account.authenticationToken)
github Haynie-Research-and-Development / jarvis / deps / lib / python3.4 / site-packages / plexapi / utils.py View on Github external
from plexapi.myplex import MyPlexAccount
    # 1. Check command-line options
    if opts and opts.username and opts.password:
        print('Authenticating with Plex.tv as %s..' % opts.username)
        return MyPlexAccount(opts.username, opts.password)
    # 2. Check Plexconfig (environment variables and config.ini)
    config_username = CONFIG.get('auth.myplex_username')
    config_password = CONFIG.get('auth.myplex_password')
    if config_username and config_password:
        print('Authenticating with Plex.tv as %s..' % config_username)
        return MyPlexAccount(config_username, config_password)
    # 3. Prompt for username and password on the command line
    username = input('What is your plex.tv username: ')
    password = getpass('What is your plex.tv password: ')
    print('Authenticating with Plex.tv as %s..' % username)
    return MyPlexAccount(username, password)
github pkkid / python-plexapi / plexapi / server.py View on Github external
def myPlexAccount(self):
        """ Returns a :class:`~plexapi.myplex.MyPlexAccount` object using the same
            token to access this server. If you are not the owner of this PlexServer
            you're likley to recieve an authentication error calling this.
        """
        if self._myPlexAccount is None:
            from plexapi.myplex import MyPlexAccount
            self._myPlexAccount = MyPlexAccount(token=self._token)
        return self._myPlexAccount
github home-assistant / home-assistant / homeassistant / components / plex / server.py View on Github external
def _connect_with_token():
            account = plexapi.myplex.MyPlexAccount(token=self._token)
            available_servers = [
                (x.name, x.clientIdentifier)
                for x in account.resources()
                if "server" in x.provides
            ]

            if not available_servers:
                raise NoServersFound
            if not self._server_name and len(available_servers) > 1:
                raise ServerNotSpecified(available_servers)

            self.server_choice = (
                self._server_name if self._server_name else available_servers[0][0]
            )
            self._plex_server = account.resource(self.server_choice).connect()