I’m building a site where we have a custom post type of “Podcast”. I made my own simple plugin, which all it does is register a feed and point to a feed template. The template is PHP, but the output is XML for podcast RSS. What I want to do is get the duration of each MP3 file for the <itunes:duration>
element, in HH:MM:SS format, which is how it’s required in the iTunes spec. I also want to get the file size in bytes for the length attribute of the <enclosure>
element.
I’m uploading the MP3 file to a custom field. I’m using the Types plugin for custom fields, and the file is uploaded to an Audio field. I could change it to a File field if it makes any difference.
In the template, here’s the relevant part of what I’ve got:
<item>
<title><?php the_title_rss(); ?></title>
<itunes:author><?php echo get_bloginfo('name'); ?></itunes:author>
<itunes:summary><![CDATA[<?php the_content_rss(); ?>]]></itunes:summary>
<description><![CDATA[<?php the_content_rss(); ?>]]></description>
<?php
$attachment_id = echo types_render_field('pod-audio', array('raw'=>'true'));
$fileurl = wp_get_attachment_url( $attachment_id );
$filesize = filesize( get_attached_file( $attachment_id ) );
?>
<enclosure url="<?php echo $fileurl; ?>" length="<?php echo $filesize; ?>" type="audio/mpeg" />
<guid><?php echo $fileurl; ?></guid>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<itunes:duration>00:00:00</itunes:duration>
</item>
I got this from this post on CSS-Tricks: http://css-tricks.com/roll-simple-wordpress-podcast-plugin/. The author is using the Advanced Custom Fields plugin, so trying to match it using Types isn’t working. For the $attachment_id, How do I get the same info as ACF doing get_field()? I can get the MP3 URL fine on its own for the enclosure, but then I’d be stuck without file size. And in either case, I can’t get duration.
WordPress is able to get the duration and file size with some sort of queries, right? I don’t want to have to try to add something like getID3(), that’s beyond my abilities to add.
And I’m not looking for podcast plugin recommendations. I’ve looked at all the podcast plugins already out there, and there are some good ones, but none of them quite fit my needs.
If anyone can help, I’d really appreciate it.