Contact Support | System Status
Page Contents

    iTunes and Roku Feed Generators

    This topic contains sample PHP code for generating feeds for iTunes and Roku

    Introduction

    Below are two PHP apps for generating feeds for iTunes and Ruku, using the Playback API as a source of video information.

    iTunes feed generator

    ');
      echo"\n";
      print('');
      echo"\n";
      print('');
      echo"\n";
      print('	'. $title .'');
      echo"\n";
      print('	'. $link .'');
      echo"\n";
      print('	'. $lang .'');
      echo"\n";
      print('	'. $copyright .'');
      echo"\n";
      print('	'. $subtitle .'');
      echo"\n";
      print('	'. $author .'');
      echo"\n";
      print('	'. $pubDate .'');
      echo"\n";
      print('	');
      echo"\n";
      print('	');
      echo"\n";
      print('	');
      echo"\n";
      print('		'. $ownername .'');
      echo"\n";
      print('		'. $owneremail .'');
      echo"\n";
      print('	');
      echo"\n";
      print('	');
      echo"\n";
      print('	');
      echo"\n";
      print('	'. $explicit .'');
      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('		');
      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 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('');
      
      ?> 

    Page last updated on 05 Aug 2021