myspace thumbnail code is not working (anymore?).

here's my fix:

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

    $str=file_get_contents($vidlink);
    if ($str)
    {
//       $regex = '@src="((?=/' . $vidid . '_thumb1\.jpg)[^"]*)"@';
//       if (preg_match($regex, $str, $matches)) {
//         $thumbnail = $matches[1];
//         cache_set('myspace:thumbnail:' . $video, 'cache', $thumbnail, time() + 3600);
//       }print_r($regex);print_r($matches);

// grab videos channel-id first

		$channelID = preg_replace('/.*tvchanid=([0-9]+);.*/si','\1',$str);
		
		if ( is_numeric( $channelID ) )
		{

// now from channel-page grab videos thumbnail

			$str2 = file_get_contents("http://vids.myspace.com/index.cfm?fuseaction=vids.viewVideos&channelid=".$channelID);

			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;
}

Comments

fjen’s picture

should have mentioned that this is for "providers/myspace.inc".

alex ua’s picture

Status: Active » Needs work

This worked somewhat, but when I first submitted a myspace video with the code above I got the following error:

user warning: MySQL server has gone away query: LOCK TABLES cache WRITE in /home/MySite/public_html/includes/database.mysql.inc on line 172.
trigger_error	/home/MySite/public_html/includes/database.mysql.inc: 172	MySQL server has gone away query: LOCK TABLES cache WRITE, 512
_db_query	/home/MySite/public_html/includes/database.inc: 200	LOCK TABLES cache WRITE
db_query	/home/MySite/public_html/includes/database.mysql.inc: 407	LOCK TABLES {cache} WRITE
db_lock_table	/home/MySite/public_html/includes/cache.inc: 94	cache

I'm guessing it's a problem with the cache_set function, but I'm not really sure, so I'm marking this as code needs work.

Also, this is a duplicate of: http://drupal.org/node/185951

aaron’s picture

Priority: Normal » Critical
aaron’s picture

Status: Needs work » Fixed

tweaked the patch and committed it to the devel version. works for me. reopen if you still get errors.

thanks!
aaron

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

tj2653’s picture

EDIT: Just realized it is the same problem as #2 on http://drupal.org/node/165360, and confirm that it is working for me now.

tj2653’s picture

[Sorry - please delete, problem solved]