iTunes 和 Roku Feed 生成器

本主題包含用於為 iTunes 和 Roku 生成提要的示例 PHP 代碼

簡介

下面是兩個用於為 iTunes 和 Ruku 生成提要的 PHP 應用程序,使用 Playback API 作為視頻信息源。

iTunes 提要生成器

');
  迴聲"\n";
  打印('');
  echo"\n";
  print('');
  echo"\n";
  print('	'. $標題。');
  echo"\n";
  print('	'. $鏈接。');
  echo"\n";
  print('	'. $朗。');
  echo"\n";
  print('	'. $版權。');
  echo"\n";
  print('	'. $副標題。');
  echo"\n";
  print('	'. $作者。');
  echo"\n";
  print('	'. $發布日期。');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('		'. $所有者名稱。');
  echo"\n";
  print('		'. $所有者電子郵件。');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('	'. $顯式。');
  echo"\n";
  echo"\n";
  
  
  function formatSeconds( $seconds )
  {
    $seconds = ($seconds / 1000);
    $hours = 0;
    $milliseconds = str_replace( "0.", '', $seconds - floor( $seconds ) );
  
    if ( $seconds > 3600 )
    {
      $hours = floor( $seconds / 3600 );
    }
    $seconds = $seconds % 3600;
  
  
    return str_pad( $hours, 2, '0', STR_PAD_LEFT ) . gmdate( ':i:s', $seconds );
  }
  
  
  
  $ch = curl_init();
  $timeout = 5; // set to zero for no timeout
  curl_setopt ($ch, CURLOPT_URL, $baseURL . $accountId . '/playlists/'. $playlistid);
  curl_setopt ($ch, CURLOPT_HTTPHEADER, array(('Authorization:BCOV-Policy '. $policyKey),('BCOV-Policy:'. $policyKey),('Accept:application/json;pk='. $policyKey)));
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $file_contents = curl_exec($ch);
  curl_close($ch);
  
  $returndata = json_decode($file_contents);
  
  foreach($returndata->videos as $items)
  {
  print('	');
  echo"\n";
  print('		');
  print_r($items->{"name"});
  print('');
  echo"\n";
   
  print('		');
  print_r($items->custom_fields->{"itunesartist"});
  print('');
  echo"\n";
   
  print('		');
  print_r($items->{"description"});
  print('');
  echo"\n";
  
  print('		');
  print_r($items->{"description"});
  print('');
  echo"\n";
   
  print('		');
  print_r($items->{"poster"});
  print('');
  echo"\n";
   
  print('		<enclosure url="');
  $newurl = $items->sources[4]->{"src"};
  print_r($newurl);
  print('" length="');
  print_r($items->{"duration"});
  print('" type="video/mp4" />');
  echo"\n";
   
  print('		');
  print_r($items->{"id"});
  print('');
  echo"\n";
   
  print('		');
  print_r(date(DATE_RFC2822,($items->{"published_at"})));
  print('');
  echo"\n";
   
  print('		');
  print($duration = formatSeconds($items->{"duration"}));
  print('');
  echo"\n";
  
  print('		');
  print_r($items->custom_fields->{"explicit"});
  print('');
  echo"\n";
  
   
  print('	');
  echo"\n";
  }
  
  echo"\n";
  
  print('');
  echo"\n";
  print('');
  
  ?>

Roku 提要生成器

');
  echo"\n";
  print('');
  echo"\n";
  print('	'. $title .'');
  echo"\n";
  print('	'. $link .'');
  echo"\n";
  print('	');
  echo"\n";
  
  $ch = curl_init();
  $timeout = 5; // set to zero for no timeout
  curl_setopt ($ch, CURLOPT_URL, $baseURL . $accountId . '/playlists/'. $playlistid);
  curl_setopt ($ch, CURLOPT_HTTPHEADER, array(('Authorization:BCOV-Policy '. $policyKey),('BCOV-Policy:'. $policyKey),('Accept:application/json;pk='. $policyKey)));
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $file_contents = curl_exec($ch);
  curl_close($ch);
  
  $returndata = json_decode($file_contents);
  
  foreach($returndata->videos as $items)
  {
  print('	');
  echo"\n";
  
  print('		');
  print_r($items->{"id"});
  print('');
  echo"\n";
  
  print('		');
  print_r(date(DATE_RFC2822,($items->{"published_at"})));
  print('');
  echo"\n";
  
  print('		');
  print_r($items->{"name"});
  print('');
  echo"\n";
  
  print('		');
  print_r($items->{"description"});
  print('');
  echo"\n";
  
  print('		');
  print_r($items->custom_fields->{"roku_category"});
  print('');
  echo"\n";
  
  print('		');
  echo"\n";
  
  
  print('		');
  echo"\n";
  
  
  print('		');
  echo"\n";
  
  // print_r($items);  DUMP THE ENTIRE ARRAY FOR TESTING
   
  print('	');
  echo"\n";
  }
  
  echo"\n";
  
  print('');
  echo"\n";
  print('');
  
  ?>