iTunes und Roku Feed-Generatoren

Dieses Thema enthält PHP-Beispielcode für die Erzeugung von Feeds für iTunes und Roku

Einleitung

Im Folgenden finden Sie zwei PHP-Apps zum Generieren von Feeds für iTunes und Ruku, wobei die Playback-API als Quelle für Videoinformationen verwendet wird.

iTunes-Feed-Generator

');
  echo"\n";
  print('');
  echo"\n";
  print('');
  echo"\n";
  print('	'. $titel. '');
  echo"\n";
  print('	'. $verknüpfung. '');
  echo"\n";
  print('	'. $lang. '');
  echo"\n";
  print('	'. $ Urheberrecht. '');
  echo"\n";
  print('	'. $untertitel. '');
  echo"\n";
  print('	'. $autor. '');
  echo"\n";
  print('	'. $Veröffentlichungsdatum. '');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('		'. $Besitzername. '');
  echo"\n";
  print('		'. $owner-E-Mail. '');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('	');
  echo"\n";
  print('	'. $explizit. '');
 echo "\ n“;
 echo "\ n“;
  
  
 Funktion formatSeconds ($sekunden)
 {
$sekunden = ($sekunden/1000);
 $Stunden = 0;
 $Millisekunden = str_replace („0. „, „, $sekunden - floor ($sekunden));
  
 if ($sekunden > 3600)
 {
$hours = floor ($sekunden/3600);
}
 $sekunden = $sekunden% 3600;
  
  
 return str_pad ($hours, 2, '0', STR_PAD_LEFT). gmdate (':i:s', $sekunden);
}
  
  
  
 $ch = curl_init ();
 $timeout = 5;//auf Null setzen für kein Timeout 
curl_setopt ($ch), CURLOPT_URL, $baseURL. $accountID. '/playlists/'. $playlist);
 curl_setopt ($ch), CURLOPT_HTTPHEADER, array ('Autorisierung: BCOV-Richtlinie'). $policyKey), ('BCoV-Richtlinie: '. $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 ($ch) returndata->videos als $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, ($artikel-> {"veröffentlicht_am"})));
 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-Feed-Generator

');
  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('');
  
  ?>