<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_video_info_for_course_and_profiles(course_id, profiles):
 """ Returns a dict of edx_video_ids with a dict of requested profiles. Args: course_id (str):
 id of the course profiles (list):
 list of profile_names Returns: (dict):
 Returns all the profiles attached to a specific edx_video_id { edx_video_id: { 'duration': length of the video in seconds, 'profiles': { profile_name: { 'url': url of the encoding 'file_size': size of the file in bytes }, } }, } Example: Given two videos with two profiles each in course_id 'test_course': { u'edx_video_id_1': { u'duration: 1111, u'profiles': { u'mobile': { 'url': u'http: //www.example.com/meow', 'file_size': 2222 }, u'desktop': { 'url': u'http: //www.example.com/woof', 'file_size': 4444 } } }, u'edx_video_id_2': { u'duration: 2222, u'profiles': { u'mobile': { 'url': u'http: //www.example.com/roar', 'file_size': 6666 }, u'desktop': { 'url': u'http: //www.example.com/bzzz', 'file_size': 8888 } } } } """

    # In case someone passes in a key (VAL doesn't really understand opaque keys)
    course_id = six.text_type(course_id)
    try:
        encoded_videos = EncodedVideo.objects.filter(
            profile__profile_name__in=profiles,
            video__courses__course_id=course_id
        ).select_related()
    except Exception:
        error_message = u"Could not get encoded videos for course: {0}".format(course_id)
        logger.exception(error_message)
        raise ValInternalError(error_message)

    # DRF serializers were causing extra queries for some reason...
    return_dict = {}
    for enc_vid in encoded_videos:
        # Add duration to edx_video_id
        return_dict.setdefault(enc_vid.video.edx_video_id, {}).update(
            {
                "duration": enc_vid.video.duration,
            }
        )
        # Add profile information to edx_video_id's profiles
        return_dict[enc_vid.video.edx_video_id].setdefault("profiles", {}).update(
            {enc_vid.profile.profile_name: {
                "url": enc_vid.url,
                "file_size": enc_vid.file_size,
            }}
        )
    return return_dict