'Return format selector for the media URL.'

def get_stream_selector(self):

    from youtube_dl import YoutubeDL
    from youtube_dl.utils import DownloadError, ExtractorError
    ydl = YoutubeDL({'quiet': True, 'logger': _LOGGER})
    try:
        all_media = ydl.extract_info(self.get_media_url(), process=False)
    except DownloadError:
        raise MEDownloadException()
    if ('entries' in all_media):
        _LOGGER.warning('Playlists    are    not    supported,    looking    for    the    first    video')
        entries = list(all_media['entries'])
        if (len(entries) > 0):
            selected_media = entries[0]
        else:
            _LOGGER.error('Playlist    is    empty')
            raise MEDownloadException()
    else:
        selected_media = all_media
    def stream_selector(query):
        'Find    stream    url    that    matches    query.'
        try:
            ydl.params['format'] = query
            requested_stream = ydl.process_ie_result(selected_media, download=False)
        except (ExtractorError, DownloadError):
            _LOGGER.error('Could    not    extract    stream    for    the    query:    %s', query)
            raise MEQueryException()
        return requested_stream['url']
    return stream_selector
