MT-Enclosures: A Movable Type Plugin

Current version is 1.4.5.0 released on 2005-12-14

Contents

What This Plugin Does

Podcasting is starting to take off. Currently, Movable Type has no support for podcasting so I decided to whip up a quick plugin to provide the capability.

The missing link here is automating the process of adding the special <enclosure> link into your RSS 2.0 feed. That is the job of this plugin.

To start audio blogging, you have to do the hard part first -- record the audio file. Be interesting. Let\'s say you recorded as an MP3 file. Then upload the MP3 file to your web server so that it is available for download. Then create a new blog entry that announces your post and has a link to the MP3. The link should be a standard <a> tag with the HREF pointing to the MP3. Save and rebuild your index files. Your RSS 2.0 index will now have an <enclosure> tag in it pointing to the MP3. You are all done!

The plugin supports a wide variety of file types -- not just MP3! It handles audio, video, image and other file types.

If you have Movable Type 3.0, the plugin will also ping audio.weblogs.com for you when you post a new enclosure. Currently, only entries with a category of "Podcasts" will trigger pings. You can change this in the source if you like.

Requirements

  • This plugin works with Movable Type version 2.x and 3.x.
  • Perl version 5.8.5 or higher. This is what I use. It may work on lower versions. Let me know if it does and I will lower this.
  • You must have the Perl module, Storable, installed.
  • This plugin will only work in static (not dynamic) templates.

WARNING WARNING WARNING: If you put media URLs into your blog entries, be careful -- you may experience issues rebuilding pages. Some plugins (such as MTLinkTitles) and the Movable Type configuration setting "Enable TrackBack Auto-Discovery" do not play nicely with any URLs to large media files. This has nothing to do with this plugin specifically. What happens is that if you have a plugin that validates URLs or the auto-discover on, Movable Type will go out and try and retrieve the "page" (it thinks) but it is really a big media file that will take a long time to download. Your request ends up timing out. I suggest you disable this feature or go into the Movable Type or plugin code and add a if statement to skip certain file extensions where this might happen.

Installation Instructions

  1. Download the latest version of the plugin.
  2. Unzip the contents of the file.
  3. Copy the file Enclosures.pl to your Movable Type "plugins" directory.(If you don\'t have a plugins directory, create a plugins directory in the same directory where your mt.cgi file is located. Then upload Enclosures.pl into the newly created plugins directory.)
  4. Add the new MTEntryEnclosures tag into your RSS 2.0 template as shown in the example below.
  5. Add a media link URL to one of your blog entries. The plugin will search all URLs inside of HREFs.
  6. Rebuild your templates and look for the new <enclosure> tag inside of your RSS 2.0 Index file.
  7. If you have any trouble, be sure to check the Movable Type Activity Log for errors.

How To Use The Tags

This plugin will only work in static (not dynamic) templates.

  • MTEntryEnclosures
    Add this tag into your RSS 2.0 Index template inside of the item element. This tag will create <enclosure> elements for each media URL found within your blog\'s entry and extended entry text. This tag MUST be placed within a <MTEntries> block. To customize, you can provide one of the following attributes:

    • log="0|1"
      The default value is 1. Set the parameter to 0 if you do not want errors logged to your Movable Type activity log. It is recommended that you leave this logging turned on so you can diagnose issues.

    • mime_exclude="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically exclude matching MIME types found in the search for enclosures.

    • mime_include="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically include matching MIME types found in the search for enclosures.

    • remote="0|1"
      The default value is 1. Set the parameter to 0 if you want to exclude remote links. Remote vs. local is determined by comparing the URL of the enclosure file with the URL of your weblog from your weblog\'s configuration.

    • url_exclude="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically exclude matching URLs found in the search for enclosures.

    • url_include="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically include matching URLs found in the search for enclosures.

  • MTBlogEnclosures
    This is a container tag that will iterate through all the entires in your weblog and process the enclosures for each entry. This tag has no output itself because it is a container tag. You must put one of the MTEnclosure* tags inside of it. To customize, you can provide one of the following attributes:

    • log="0|1"
      The default value is 1. Set the parameter to 0 if you do not want errors logged to your Movable Type activity log. It is recommended that you leave this logging turned on so you can diagnose issues.

    • mime_exclude="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically exclude matching mime types found in the search for enclosures.

    • mime_include="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically include matching mime types found in the search for enclosures.

    • remote="0|1"
      The default value is 1. Set the parameter to 0 if you want to exclude remote links. Remote vs. local is determined by comparing the URL of the enclosure file with the URL of your weblog from your weblog\'s configuration.

    • url_exclude="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically exclude matching URLs found in the search for enclosures.

    • url_include="pattern"
      You can enter a Perl regular expression pattern that will be used to specifically include matching URLs found in the search for enclosures.

  • MTEnclosureURL
    This tag prints out the URL of the enclosure. This tag must be used inside of a container tag, such as MTBlogEnclosures.

  • MTEnclosureLength
    This tag prints the length/size of the enclosure. This tag must be used inside of a container tag, such as MTBlogEnclosures. To customize, you can provide one of the following attributes:

    • format="b|k|m|g"
      You can specify the format of the length in units. b for bytes, k for kilobytes, m for megabytes and g for gigabytes.

    • label="0|1"
      Set to 1 if you want the tag to output a text label indicating the units. The default value is 0.

  • MTEnclosureMIME
    This tag outputs the MIME type associated with the current enclosure. This tag must be used inside of a container tag, such as MTBlogEnclosures.

Frequently Asked Questions

  • Q: Is there any way to tell the plugin to ignore all other media types except audio?
    A: There are several ways to accomplish this using the include or exclude tag parameters. If you want to exclude images, you could add:
    <$MTEntryEnclosures mime_exclude="image"$>
    If you want to only include audio, you could add:
    <$MTEntryEnclosures mime_include="audio"$>
    Alternatively, you can also just specify the MIME type of the items you would like to list, such as:
    <$MTEntryEnclosures mime_include="audio/mpeg"$>
    These parameters allow you to match the MIME types to refine what is considered to be an enclosure.

  • Q: I did a test post with a fake MP3 file and it is not working. Why?
    A: You cannot use fake files or fake links. The plugin goes out on the web and validates that the file you linked to actually exists. It does this to prevent bad links but more importantly it does it to figure out the size of the file. The size is a required attribute of the <enclosure> tag.

  • Q: How does the plugin know what URLs on my page to use for the enclosures?
    A: The plugin will look for a variety of HTML tags and use the URLs in them. I suggest that you enter your URLs as complete URLs (http://mysite.com/sample.mp3) but you can use relative paths as well. Here are some samples.
    1. <a href="http://mysite.com/sample.mp3">
    2. <embed href="http://mysite.com/sample.mov"></embed>
    3. <embed src="http://mysite.com/sample.mov"></embed>
    4. <img src="http://mysite.com/sample.jpg">
    When the plugin processes the URL, it needs to take a peek at the file itself and see what the size of the file is. The plugin will either do this by checking the file through the file system or if the file is remote, it will do a HTTP query for the information. A match of the URL in your weblog\'s site path is used to determine if it is local or remote.

Examples

1. To simply add enclosures to your RSS 2.0 feed, this is all you have to do! Add the MTEntryEnclosures tag into your RSS 2.0 Index file anywhere inside of the item element.

<MTEntries lastn="15">   <item>      ...      <$MTEntryEnclosures$>   </item></MTEntries>

2. To create a list of all enclosures ever published through your blog, create a new index template and then insert this code.

<table>   <MTBlogEnclosures>      <tr>         <td><$MTEnclosureURL$></td>         <td><$MTEnclosureMIME$></td>         <td><$MTEnclosureLength format="m"$></td>      </tr>   </MTBlogEnclosures></table>

Donate

This software is free for personal use. However, if you enjoy using this plugin and would like to see it enhanced, please donate a buck or two...or fifty.

Commercial use requires a $20.00 donation.

License

This software is licensed under the CC-GNU LGPL.

CC-GNU LGPL

Download

Download the current version from the link below. Past versions are not archived.

Version History

1.4.5.0 -- 2005-12-14
  • Added support for .m4v file extension, which is used for iPod video.
1.4.4.1 -- 2005-09-28
  • Removing IP address logging to avoid MT::App errors.
1.4.4.0 -- 2005-09-16
  • Added audio/aa mime type.
1.4.3.0 -- 2005-09-04
  • Updated plugin info to take advantage of MT 3.2 enhancements.
1.4.2.0 -- 2005-07-17
  • Added single quote parsing to search patterns.
  • Renamed include parameter to url_include.
  • Renamed exclude parameter to url_exclude.
  • Renamed mime parameter to mime_include.
  • Added new mime_exclude parameter.
1.4.1.3 -- 2005-06-26
  • Fixed error Can\'t locate object method "remote_ip" via package "MT::App" at...
1.4.1.2 -- 2004-12-10
  • Fixed bug where plugin reported error in MT-Medic.
1.4.1.1 -- 2004-11-20
  • Fixed bug where enclosure size of remote enclosures was always 100,000. Introduced in 1.4.0.0.
1.4.1.0 -- 2004-11-12
  • Added Ogg Vorbis MIME type.
  • Added escapes of forward slash to include, exclude and mime patterns.
1.4.0.0 -- 2004-11-11
  • Added ability to extract enclosures from anywhere in blog.
  • Added MIME type matching pattern parameter.
  • Added include pattern parameter.
  • Added Windows Media Video (WMV) MIME type support.
1.3.2.0 -- 2004-11-01
  • Added a parameter so you can exclude a pattern from the enclosure search.
  • Added a check to prevent duplicate enclosure URLs in the same entry.
1.3.1.0 -- 2004-11-01
  • Added enclosure support for various image types, such as JPEG and GIF.
1.3.0.2 -- 2004-10-28
  • Fixed bug introduced in v1.1.0.0 where relative links would show up with backslashes in the hostname.
1.3.0.1 -- 2004-10-24
  • Added IP address to activity log messages.
1.3.0.0 -- 2004-10-15
1.2.0.0 -- 2004-10-15
  • Added support for enclosures specified as EMBED tags in posts.
1.1.2.0 -- 2004-10-14
  • Added log parameter to enable or disable logging to Movable Type\'s activity log on errors.
1.1.1.0 -- 2004-10-11
  • Added remote parameter to filter out remote links.
1.1.0.0 -- 2004-10-04
  • Changed the methods for getting the content length to try local files methods first.
1.0.1.0 -- 2004-09-26
  • Changed to use MT error handler.
1.0.0.2 -- 2004-09-20
  • Added log messages to the Movable Type Activity Log when the plugin is unable to validate the URL.
1.0.0.1 -- 2004-09-20
  • Removed some debugging code that was preventing operation.
  • Added BitTorrent mime type support.
1.0.0.0 -- 2004-09-17
  • Works for me.

Contact

For questions, suggestions, bug reports, and anything else related to this plugin, please e-mail brandon@fuller.name or leave a comment.

Updated: 2009-11-25 at 10:53 MDT in Hacks
Tags: movabletype