title: Drupal 7 - create node programatically, adding a youtube embed to a field
body: <p>I'm trying to create nodes programatically. Using Media module with the youtube extension, I'd like to populate a field with youtube data. From what I've read so far, it's going to look something like this:</p>
  
  <pre><code>   &lt;?php
      // $value in this case is the youtube ID.
      $file = new stdClass();
        $file-&gt;uid = 1;
        $file-&gt;filename = $value;
        $file-&gt;uri = 'youtube://v/' . $value;
        $file-&gt;filemime =  'video/youtube';
        $file-&gt;type = 'video';
        $file-&gt;status = 1;
        $youtube = file_save($file);
  
      node-&gt;field_youtube[$node-&gt;language]['0']['fid'] = (array) $youtube-&gt;fid;
      ?&gt;
  </code></pre>
  
  <p>I learned this by looking at the information in the $content variable in the bartik theme. However, this results in a "Bad file extension" error. I also tried putting the whole url in $file->uri and using file_get_mimetype on it, then it didn't throw an error but the video didn't work either. Does anyone know how to do this?</p>