You could use `modulestore().get_course(course_id)`.