import requests
from bs4 import BeautifulSoup


def get_movies_libraries( token, fullURL = 'http://localhost:32400' ):
    """
    Returns a :py:class:`list` of the key numbers of all Plex movie libraries on the Plex_ server.

    :param str token: the Plex_ server access token.
    :param str fullURL: the Plex_ server address.

    :returns: a :py:class:`list` of the Plex_ movie library key numbers.
    :rtype: list.
    """
    params = { 'X-Plex-Token' : token }
    response = requests.get(
        '%s/library/sections' % fullURL, params = params,
        verify = False )
    if response.status_code != 200: return None
    html = BeautifulSoup( response.content, 'lxml' )
    library_dict = { int( direlem['key'] ) : ( direlem['title'], direlem['type'] ) for
                     direlem in html.find_all('directory') }
    return sorted(set(filter(lambda key: library_dict[ key ][1] == 'movie',
                             library_dict ) ) )