WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Podcast Channels] Enclosures not automatically added (16 posts)

  1. shalako
    Member
    Posted 5 years ago #

    Hello Alan,

    I set up podcast-channels a few months ago and have since been producing two podcasts successfully. However, there are some issues with the setup that I haven't had the bandwidth to address. Hopefully this is something you can help me with.

    I have read that WordPress automatically attaches enclosures when it detects the URL of a media file. This has never worked for me and so I don't what is supposed to happen when it does work; when you save a post with a media URL does WP add a custom field called 'enclosure' and a value which includes info about the media file?

    This is my current process:
    1. Upload an mp3 file (they tend to be 100-130MB)
    2. Draft the post and add the file to the post by first using Add From Server plugin to import mp3 into Media Library, then add to post from Media Library. Now I have a link to the file in my post
    3. I add the [audio: url-of-file.mp3] for the wpaudioplayer plugin
    4. Save draft

    At this point I would expect that, based on what little I know about WP enclosure feature, the enclosure would be added - I don't know how this happens or in what way it manifests.

    5. What I have been doing is adding a custom field called 'enclosure' and putting the URL of the file in there along with the file size and 'audio/mpeg' separated by carriage returns.

    Once I saw a custom field with this info in it; I thought maybe it came from another podcasting plugin I tried. In any case I do this manually now for each post and it seems to work. Would be great if I didn't have to do it manually because I have no idea about the spec of the enclosure; maybe there's other information I'm not including? There must be a better way and for a feature which is supposed to be built-in to WP, I can't find any documentation.

  2. shalako
    Member
    Posted 5 years ago #

    I should add that I'm using WP 2.7.1, not 2.6.5

  3. alanft
    Member
    Posted 5 years ago #

    yep. steps 1-4 are pretty much what i do. having a full and valid "url-of-file.mp3" in your post should indeed add an enclosure automatically.

    what WP does is fetch the header of the URL and if it gets a good reply it puts in a custom field "enclosure" which contains URL+bytes+MIMEtype separated by carriage returns.

    in my experience if you put in a URL and quickly go back in to edit the post you won't see the custom field, but if you save, wait a few seconds and go back into edit the file the field should be there.

    if this isn't happening, the code on your server must be falling over at the point of getting the media HEAD. which would be hard to troubleshoot, but i can dig through the code to find out exactly how it does this.

    ...

  4. alanft
    Member
    Posted 5 years ago #

    the core code is in the function do_enclose() in wp-includes/functions.php:

    if ( $headers = wp_get_http_headers( $url) ) {
    	$len = (int) $headers['content-length'];
    	$type = $wpdb->escape( $headers['content-type'] );
    	$allowed_types = array( 'video', 'audio' );
    	if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
    		$meta_value = "$url\n$len\n$type\n";
    		$wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->postmeta ( 'post_id' , 'meta_key' , 'meta_value' )
    		VALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value ) );
    	}
    }

    where the crucial wp_get_http_headers ends up using the standard WP_Http object code (in wp-includes/http.php).

    so if that's not working to make enclosures, there are probably other things not working too. like can you use the RSS widget to get RSS feeds from the same domain?

  5. alanft
    Member
    Posted 5 years ago #

    alternatively it's possible that the enclosure field IS being made, but then hidden from you. i believe there are plugins that selectively remove custom fields from the edit post page. just look at the RSS feed and see if there is an enclosure element to check.

  6. shalako
    Member
    Posted 5 years ago #

    Thank you for your recommendations.

    I have verified that saving the post and waiting does not result in an enclosure being added automatically.

    Without adding the enclosure manually, there is no enclosure item in the feed XML.

    Adding the RSS Widget for the feed URL http://redlightmusic.com/category/podcasts/vintage-mixtapes/feed/ doesn't work. The widget isn't displayed in the sidebar and looking at the widget admin again I see the URL has been replaced with "Error: could not find an RSS or ATOM feed at that URL." However, if I replace the URL with the feedburner URL, http://feeds2.feedburner.com/RedlightMusicPresentsVintageMixtapes, it works. The first URL is redirected to the second by your plugin.

    Any ideas?

  7. alanft
    Member
    Posted 5 years ago #

    that doesn't really shed any light unfortunately. what's the URL you are putting in your post?

    i don't suppose you have 'shell access' to your web server? (that way you could try a few things to troubleshoot why it is that it can't read media served by itself!)

  8. shalako
    Member
    Posted 5 years ago #

    The URL for the media file is http://redlightmusic.com/wp-content/uploads/onionz_sweetmix.mp3

    I do have shell access and am somewhat familiar with the LAMP stack; what would you look for?

    Thank you.

  9. alanft
    Member
    Posted 5 years ago #

    ok, get into your server and try

    curl --head http://redlightmusic.com/wp-content/uploads/onionz_sweetmix.mp3

    if you get anything (significantly) different to

    HTTP/1.1 200 OK
    Date: Sun, 22 Mar 2009 21:57:40 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Wed, 18 Mar 2009 19:36:47 GMT
    ETag: "28a0048-7e9aa49-46569cde2b1c0"
    Accept-Ranges: bytes
    Content-Length: 132753993
    Connection: close
    Content-Type: audio/mpeg

    something is up with the way your host routes to itself, but then i'm starting to reach the edge of my troubleshooting use to you! and if it's not much different then i am stumped - as the WP code should work if that does.

  10. shalako
    Member
    Posted 5 years ago #

    well, looks like i got something pretty similar

    HTTP/1.1 200 OK
    Date: Sun, 22 Mar 2009 23:19:27 GMT
    Server: Apache/2.2.3 (CentOS)
    Last-Modified: Wed, 18 Mar 2009 19:36:47 GMT
    ETag: "28a0048-7e9aa49-46569cde2b1c0"
    Accept-Ranges: bytes
    Content-Length: 132753993
    Connection: close
    Content-Type: audio/mpeg

    I appreciate your help; guess i'll keep adding the enclosure manually until I figure it out. Thanks again!

  11. alanft
    Member
    Posted 5 years ago #

    the post info says you are on 2.6.5 - have you tried out a test 2.7 install to see if that improves things?

  12. shalako
    Member
    Posted 5 years ago #

    That's weird; where does it say that? I'm running 2.7.1

  13. alanft
    Member
    Posted 5 years ago #

    up there ^^^^ over to the right in the post definition "WordPress version: 2.6.5 / This topic is not resolved".

    never mind tho.

    it occurs to me that another thing you could try to troubleshoot this is running some code in a page template:

    $media_head=wp_remote_head('http://redlightmusic.com/wp-content/uploads/onionz_sweetmix.mp3');
    echo "<PRE>"; print_r($media_head); echo "</PRE>";
  14. shalako
    Member
    Posted 5 years ago #

    Oh yeah. that was a mistake when I created the topic.

    Results of your code:

    Array
    (
        [headers] => Array
            (
                [date] => Tue, 24 Mar 2009 02:49:47 GMT
                [server] => Apache/2.2.3 (CentOS)
                [last-modified] => Wed, 18 Mar 2009 19:36:47 GMT
                [etag] => "28a0048-7e9aa49-46569cde2b1c0"
                [accept-ranges] => bytes
                [content-length] => 132753993
                [connection] => close
                [content-type] => audio/mpeg
            )
    
        [body] =>
        [response] => Array
            (
                [code] => 200
                [message] => OK
            )
    
    )
  15. alanft
    Member
    Posted 5 years ago #

    woah. well that's progress. so here's the chain of events inside WP. see if you can spot where it might be going wrong

    1 - add_action('publish_post', '_publish_post_hook', 5, 1);
    so when you publish a post it runs this function
    2 - function _publish_post_hook()
    this sets wp_schedule_single_event(time(), 'do_pings');
    3 - add_action('do_pings', 'do_all_pings', 10, 1);
    this action is set to run this function
    4 - function do_all_pings()
    runs do_enclose() on possible valid URLs in the post
    5 - do_enclose()
    adds enclosure field if wp_get_http_headers (which uses wp_remote_head) gives the info needed

    if this chain of events looks longwinded, i guess what's happening here is that sometimes pings can take a looong time, so rather than simply call 'do_all_pings' at the point of pressing publish, it is queued up to happen via cron in a separate server process.

    and that's a good candidate for the break in your chain. WP-cron stuff won't run if the server time has drifted or if there is some server misconfiguration.

    as an experiment you could try adding to your theme's functions.php:

    add_action('publish_post', 'do_all_pings');

    this might slow down the publish process, but if it works - if it adds your enclosures - then that's progress, and perhaps you can check the cron issue!

  16. alanft
    Member
    Posted 4 years ago #

    any follow up on this?

Topic Closed

This topic has been closed to new replies.

About this Topic