birgire / wpse-playlist

WordPress - Playlist shortcode with external audio or video files. Wrapper for the native playlist in WordPress.
19 stars 8 forks source link

playlist from rss feed #11

Closed Glodarin closed 8 years ago

Glodarin commented 8 years ago

I would like to generate the playlist out of an podcast rss feed. So the url to the podcast xml file would be given as a parameter and then the player could generate the playlist out of the ABC URL ... in the file. I think it should be possible but I'm new to php - But this would be very helpful to me.

birgire commented 8 years ago

Hi @Glodarin

That might be possible, but with custom programming.

You could look into fetch_feed() core function in WordPress and create a loop to generate the [_playlist] and [_track] shortcodes.

Then take the output through do_shortcode().

Another approach might be to work directly with the shortcode callbacks.

Good luck with your project.

Glodarin commented 8 years ago

Thanks for the help! This is how I did it:

[_playlist type="audio" current="no" tracklist="yes" tracknumbers="no" images="no" artist="no"]

<?php
//include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
include_once( ABSPATH . WPINC . '/feed.php' );

//Function for feed cash reset (10 sec for debug)
function return_10( $seconds ) {
  return 10;
}
add_filter( 'wp_feed_cache_transient_lifetime', 'return_10' );

$rss= fetch_feed('http://cck-town.org/wordpress/feed/podcast/the-book-of-john/'); // specify feed url

if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
    $maxitems = $rss->get_item_quantity();  //get all items from the feed
    $rss_items = $rss->get_items(0, $maxitems);

    //create a _track shortcut for each item 
    if ($rss_items):
        foreach ( $rss_items as $item ) : 
            if ($enclosure = $item->get_enclosure()):
                printf('[_track title="%s" src="%s"]',$item->get_title(),$enclosure->get_link());
            endif;
        endforeach;           
    endif;
endif;  

?>

[/_playlist]
birgire commented 8 years ago

@Glodarin

Glad to hear you worked it out.

Thanks for sharing your solution.