You are here

function emvideo_wattv_emvideo_parse in Asset 7

Implements hook_emvideo_parse().

File

modules/emvideo/modules/emvideo_wattv/emvideo_wattv.module, line 10
Emvideo wattv module.

Code

function emvideo_wattv_emvideo_parse($data) {
  $ret = FALSE;
  $page_url = '';

  // Note, as we are searching in whole string, possible to find that url within embed and it will works.
  if (preg_match('@http://www\\.wat\\.tv/video/(.+?\\.html)@i', $data, $matches)) {
    $page_url = 'http://www.wat.tv/video/' . $matches[1];
  }
  elseif (preg_match('@http://wat\\.tv/p/([0-9a-z]+)@i', $data, $matches)) {
    $page_url = 'http://wat.tv/p/' . $matches[1];
  }
  if ($page_url) {
    $video_page_data = @file($page_url);
    if ($video_page_data) {
      $video_page_data = implode("\n", $video_page_data);
      $matches = array();
      if (preg_match('@<meta name="twitter:player" content="(.*?)"@i', $video_page_data, $matches)) {
        $ret = array(
          'source' => $matches[1],
          'provider' => 'wattv',
        );
        $matches = array();

        // @todo: We have a problem with different https/http urls for snapshot. Seems we need redo whole storage system.
        if (preg_match('@<meta property="og:image" content="(.*?)"@i', $video_page_data, $matches)) {
          $ret['snapshot'] = $matches[1];
        }
      }
    }
  }
  elseif (preg_match('@<iframe src="(.*?)"@i', $data, $matches)) {
    $ret = array(
      'source' => $matches[1],
      'provider' => 'wattv',
    );
  }
  elseif (preg_match('@src="http://www\\.wat\\.tv/swf2/([0-9a-z]+)"@i', $data, $matches)) {
    $ret = array(
      'source' => 'http://www.wat.tv/swf2/' . $matches[1],
      'provider' => 'wattv',
    );
  }
  return $ret;
}