You are here

function _video_cck_myspace_scrape_thumbnail in Embedded Media Field 5

this scrapes the thumbnail from the video page and caches it

1 call to _video_cck_myspace_scrape_thumbnail()
video_cck_myspace_thumbnail in contrib/video_cck/providers/myspace.inc

File

contrib/video_cck/providers/myspace.inc, line 34

Code

function _video_cck_myspace_scrape_thumbnail($video, $cached = true) {
  if (!$cached || !($cache = cache_get('myspace:thumbnail:' . $video, 'cache'))) {
    $vidid = substr($video, 0, 10);
    if ($str = file_get_contents("http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid={$vidid}")) {

      // grab videos channel-id first
      $channel_id = preg_replace('/.*tvchanid=([0-9]+);.*/si', '\\1', $str);
      if (is_numeric($channel_id)) {

        // now from channel-page grab videos thumbnail
        $str2 = file_get_contents("http://vids.myspace.com/index.cfm?fuseaction=vids.viewVideos&channelid={$channel_id}");
        if ($str2) {
          $picturelink = preg_replace('@.*href="[^"]+' . $vidid . '"[^>]+><img[^>]+src="([^"]+)".*@si', '\\1', $str2);
          if ($picturelink) {
            $thumbnail = $picturelink;
            cache_set('myspace:thumbnail:' . $video, 'cache', $thumbnail, time() + 3600);
          }
        }
      }
    }
  }
  else {
    $thumbnail = $cache->data;
  }
  return $thumbnail;
}