@staticmethod
def _get_closest_size(medias, width, height=0):
    """
        Try to extract a image/video object that will most match the resolution returned by the public API

        :param medias: list of images/videos
        :param width: desired width
        :param height: desired height
        :return:
        """
    current = None
    for media in medias:
        if not current:
            current = media
        if abs(media['width'] - width) < abs(current['width'] - width
            ) or media['width'] == current['width'
            ] and not height and not media['height'] == current['width'
            ] or media['width'] == current['width'] and height and abs(
            media['height'] - height) < abs(current['height'] - height):
            current = media
    return current
