Index: modules/media_internet/media_internet.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/media/modules/media_internet/media_internet.module,v
retrieving revision 1.2
diff -u -p -r1.2 media_internet.module
--- modules/media_internet/media_internet.module	3 Sep 2010 21:51:13 -0000	1.2
+++ modules/media_internet/media_internet.module	16 Sep 2010 23:29:13 -0000
@@ -165,10 +165,10 @@ function media_internet_add_validate($fo
  *  @see media_parse_to_file().
  */
 function media_internet_add_submit($form, &$form_state) {
-  $emebed_code = $form_state['values']['embed_code'];
+  $embed_code = $form_state['values']['embed_code'];
   try {
     // Save the remote file
-    $provider = media_internet_get_provider($emebed_code);
+    $provider = media_internet_get_provider($embed_code);
     // Providers decide if they need to save locally or somewhere else.
     // This method returns a file object
     $file = $provider->save();
@@ -179,10 +179,52 @@ function media_internet_add_submit($form
   }
 
   if (!$file->fid) {
-    form_set_error('url', 'Unknown error: unable to add file, please check URL / Embed code and try again ' . $emebed_code);
+    form_set_error('url', 'Unknown error: unable to add file, please check URL / Embed code and try again ' . $embed_code);
     return;
   }
 
+  // If the media entity for this file has title or descriptions fields, then
+  // populate them with the data retrieved from the provider.
+  // @todo Optimize this to be lightweight when the fields do not exist. There
+  //   is no need to ask the provider for meta information if the media entity
+  //   doesn't have any fields to populate. However, this optimization is not a
+  //   high priority, because this code only runs when the "From URL" form is
+  //   submitted, so this is not a performance-critical area to worry about.
+  $values = array();
+  if ($rss = $provider->getMRSS()) {
+    // @todo See MediaInternetBaseHandler::getMRSS() about the desired change
+    //   of $rss to an array instead of a SimpleXML element.
+    // MRSS is an extension of RSS, so the title field is available in the
+    // default (ATOM) namespace.
+    $values['media_title'] = (string) $rss->title;
+    // The MRSS extensions are in their own namespace.
+    $mrss = $rss->children('http://search.yahoo.com/mrss/');
+    $values['media_description'] = (string) $mrss->group->description;
+  }
+  elseif ($oembed = $provider->getOEmbed()) {
+    $values = array(
+      'media_title' => $oembed['title'],
+    );
+  }
+  $values = array_filter($values, 'strlen');
+  if ($values) {
+    $media = media_load($file->fid);
+    $needs_save = FALSE;
+    foreach ($values as $field_name => $value) {
+      $field = field_info_field($field_name);
+      // Limiting value population only if the field is of type 'text' or
+      // 'text_long' isn't as extensible as would be ideal, but we need some
+      // protection against populating a field with incompatible content.
+      if (isset($field) && in_array($field['type'], array('text', 'text_long')) && isset($field['bundles']['media']) && in_array($file->type, $field['bundles']['media']) && !isset($media->{$field_name}[LANGUAGE_NONE][0]['value'])) {
+        $media->{$field_name}[LANGUAGE_NONE][0]['value'] = $value;
+        $needs_save = TRUE;
+      }
+    }
+    if ($needs_save) {
+      media_save($media);
+    }
+  }
+
   $form_state['redirect'] = array('media/browser', array('query' => array('render' => 'media-popup', 'fid' => $file->fid)));
 }
 
@@ -336,6 +378,31 @@ abstract class MediaInternetBaseHandler 
   public function preSave($file_obj) {
     
   }
+
+  /**
+   * Returns information about the media. See http://www.oembed.com/.
+   *
+   * @return
+   *   If oEmbed information is available, an array containing 'title', 'type',
+   *   'url', and other information as specified by the oEmbed standard.
+   *   Otherwise, NULL.
+   */
+  public function getOEmbed() {
+  }
+
+  /**
+   * Returns information about the media. See http://video.search.yahoo.com/mrss.
+   *
+   * @return
+   *   If ATOM+MRSS information is available, a SimpleXML element containing
+   *   ATOM and MRSS elements, as per those respective specifications.
+   *
+   * @todo Would be better for the return value to be an array rather than a
+   *   SimpleXML element, but media_retrieve_xml() needs to be upgraded to
+   *   handle namespaces first.
+   */
+  public function getMRSS() {
+  }
 }
 
 class MediaInternetValidationException extends Exception {
@@ -344,4 +411,4 @@ class MediaInternetValidationException e
 
 class MediaInternetNoHandlerException extends Exception {
   
-}
\ No newline at end of file
+}
