def get_pin(): """ For plex.tv sign-in: returns 4-digit code and identifier as 2 str """ code = None identifier = None # Download xml = DU().downloadUrl('https://plex.tv/pins.xml', authenticate=False, action_type="POST") try: xml.attrib except AttributeError: LOG.error("Error, no PIN from plex.tv provided") return None, None code = xml.find('code').text identifier = xml.find('id').text LOG.info('Successfully retrieved code and id from plex.tv') return code, identifier
def check_pin(identifier): """ Checks with plex.tv whether user entered the correct PIN on plex.tv/pin Returns False if not yet done so, or the XML response file as etree """ # Try to get a temporary token xml = DU().downloadUrl('https://plex.tv/pins/%s.xml' % identifier, authenticate=False) try: temp_token = xml.find('auth_token').text except AttributeError: LOG.error("Could not find token in plex.tv answer") return False if not temp_token: return False # Use temp token to get the final plex credentials xml = DU().downloadUrl('https://plex.tv/users/account', authenticate=False, parameters={'X-Plex-Token': temp_token}) return xml