Lasso Soft Inc. > Home

[podcast]

Linkpodcast
AuthorJason Huck
CategoryXML
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted18 Nov 2006
Updated18 Nov 2006
More by this author...

Description

Three tags to make generating podcast feeds in Lasso easier:

[podcast_categories] - A constant which is a map of all allowed top-level categories. The value of each item in the map is an array of allowed subcategories.

[podcast_item] - A custom type for creating item nodes for the feeds -- the block of xml that describes an individual episode in your podcast.

[podcast] - A custom type for assembling and serving the complete feed.

All of the parameters specified in the Apple spec are supported. See the official documentation and the sample code below. Requires [xml_tree].

Sample Usage

var('myitem') = podcast_item(
	-title='test title',
	-author='me',
	-enclosure=map(
		'href' = 'http://www.somewhere.com/',
		'length' = 123456,
		'type' = 'audio/mpeg'
	),
	-summary='Much ado about nothing.',
	-guid='90210',
	-pubDate=date,
	-duration=duration('00:03:35')
);

var('items') = array($myitem);

var('myfeed') = podcast(
	-title='mypodcast',
	-link='http://somewhere.com/',
	-language='en-us',
	-copyright='©2006 Somebody.',
	-description='The podcast about nothing. Just like all the rest.',
	-summary='Really, it is just a bunch of talking.',
	-ownername='me',
	-image='blah.gif',
	-category='Arts',
	-subcats=(: 'Design', 'Visual Arts'),
	-items=$items
);

content_type('text/xml;charset=utf-8');
$myfeed;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

!lasso_tagexists('podcast_categories') ?
define_constant(
	'categories', 
	-namespace='podcast_',
	map(
		'Arts' = (: 'Design', 'Fashion & Beauty', 'Food', 'Literature', 'Performing Arts', 'Visual Arts'),
		'Business' = (: 'Business News', 'Careers', 'Investing', 'Management & Marketing', 'Shopping'),
		'Comedy' = array,
		'Education' = (: 'Education Technology', 'Higher Education', 'K-12', 'Language Courses', 'Training'),
		'Games & Hobbies' = (: 'Automotive', 'Aviation', 'Hobbies', 'Other Games', 'Video Games'),
		'Government & Organizations' = (: 'Local', 'National', 'Non-Profit', 'Regional'),
		'Health' = (: 'Alternative Health', 'Fitness & Nutrition', 'Self-Help', 'Sexuality'),
		'Kids & Family' = array,
		'Music' = array,
		'News & Politics' = array,
		'Religion & Spirituality' = (: 'Buddhism', 'Christianity', 'Hinduism', 'Islam', 'Judaism', 'Other', 'Spirituality'),
		'Science & Medicine' = (: 'Medicine', 'Natural Sciences', 'Social Sciences'),
		'Society & Culture' = (: 'History', 'Personal Journals', 'Philosophy', 'Places & Travel'),
		'Sports & Recreation' = (: 'Amateur', 'College & High School', 'Outdoor', 'Professional'),
		'Technology' = (: 'Gadgets', 'Tech News', 'Podcasting', 'Software How-To'),
		'TV & Film' = array
	)
);



define_type(
	'podcast',
	-description='Extends [xml_tree] specifically for the podcast RSS format.'
);
	local('data' = xml_tree);

	define_tag(
		'onCreate',
		-opt='title',
		-opt='link',
		-opt='language',
		-opt='copyright',
		-opt='description',
		-opt='subtitle',
		-opt='author',
		-opt='summary',
		-opt='block',
		-opt='explicit',
		-opt='keywords',
		-opt='image',
		-opt='ownername',
		-opt='owneremail',
		-opt='new-feed-url',
		-opt='items',
		-opt='category',
		-opt='subcats', -type='array'
	);
		self->'data'->setname('rss');
		self->'data'->addattribute('version'='2.0');
		self->'data'->addnamespace('itunes'='http://www.itunes.com/dtds/podcast-1.0.dtd');
		self->'data'->newchild('channel');
		
		iterate((:'title', 'link', 'language', 'copyright', 'description'), local('i'));
			if(local_defined(#i));
				self->'data'->channel->newchild(#i);
				self->'data'->channel->getnode(#i)->addcontent(local(#i));
			/if;
		/iterate;
		
		iterate((:'subtitle', 'author', 'summary', 'block', 'explicit', 'keywords', 'new-feed-url'), local('i'));
			if(local_defined(#i));
				local('nodename' = 'itunes:' + #i);
				self->'data'->channel->newchild(#nodename);
				self->'data'->channel->getnode(#nodename)->addcontent(local(#i));
			/if;
		/iterate;
		
		if(local_defined('image'));
			self->'data'->channel->newchild('itunes:image');
			self->'data'->channel->getnode('itunes:image')->addattribute('href'=#image);
		/if;
		
		// workaround
		iterate((:'ownername', 'owneremail'), local('i'));
			if(local_defined(#i));
				self->'data'->channel->newchild('itunes:owner');
				loop_abort;
			/if;
		/iterate;
		
		iterate((:'ownername', 'owneremail'), local('i'));
			if(local_defined(#i));
				local('nodename' = 'itunes:' + string_removeleading(#i, -pattern='owner'));					
				self->'data'->channel->getnode('itunes:owner')->newchild(#nodename);
				self->'data'->channel->getnode('itunes:owner')->getnode(#nodename)->addcontent(local(#i));
			/if;		
		/iterate;
		
		if(local_defined('category') && podcast_categories->find(#category) != '');
			self->'data'->channel->newchild('itunes:category');
			self->'data'->channel->getnode('itunes:category')->addattribute('text'=#category);
			
			if(local_defined('subcats'));
				iterate(#subcats, local('i'));
					if(podcast_categories->find(#category)->size && podcast_categories->find(#category) >> #i);
						self->'data'->channel->getnode('itunes:category')->newchild('itunes:category');
						self->'data'->channel->getnode('itunes:category')->lastchild->addattribute('text'=#i);
					/if;
				/iterate;
			/if;
		/if;
		
		if(local_defined('items'));
			iterate(#items, local('i'));
				// may have problems getting this to work with xml_tree...
				self->'data'->channel->addchild(xml(#i));
			/iterate;
		/if;
	/define_tag;
	
	define_tag('_unknownTag');
		return(self->'data'->tag_name);
	/define_tag;
	
	define_tag('onConvert');
		return(string(self->'data'));
	/define_tag;
/define_type;



define_type(
	'item',
	-namespace='podcast_',
	-description='Generates XML for a podcast item RSS node.'
);
	local('data' = xml_tree);
	
	define_tag(
		'onCreate',
		-opt='title',
		-opt='author',
		-opt='subtitle',
		-opt='summary',
		-opt='enclosure', -type='map',
		-opt='guid',
		-opt='pubDate', -type='date',
		-opt='duration', -type='duration',
		-opt='keywords',
		-opt='block',
		-opt='explicit'
	);
		self->'data'->setname('item');
		self->'data'->addnamespace('itunes'='http://www.itunes.com/dtds/podcast-1.0.dtd');
		
		iterate((:'title', 'guid'), local('i'));
			if(local_defined(#i));
				self->'data'->newchild(#i);
				self->'data'->getnode(#i)->addcontent(local(#i));
			/if;
		/iterate;
		
		iterate((:'subtitle', 'author', 'summary', 'block', 'explicit', 'keywords', 'duration'), local('i'));
			if(local_defined(#i));
				local('nodename' = 'itunes:' + #i);
				self->'data'->newchild(#nodename);
				self->'data'->getnode(#nodename)->addcontent(local(#i));
			/if;
		/iterate;
		
		if(local_defined('pubDate'));
			self->'data'->newchild('pubDate');
			// Wed, 15 Jun 2005 19:00:00 GMT
			self->'data'->pubDate->addcontent(date_localtogmt(#pubDate)->format('%a, %d %b %Y %H:%M:%S GMT'));
		/if;
		
		if(local_defined('enclosure'));
			self->'data'->newchild('enclosure');
			self->'data'->enclosure->addattribute('url'=#enclosure->find('url'));
			self->'data'->enclosure->addattribute('length'=#enclosure->find('length'));
			self->'data'->enclosure->addattribute('type'=#enclosure->find('type'));
		/if;
		
		// convert to xml type when finished to work around inheritance bugs
		self->'data' = xml(self->'data');
	/define_tag;

	define_tag('_unknownTag');
		return(self->'data'->tag_name);
	/define_tag;
	
	define_tag('onConvert');
		return(string(self->'data'));
	/define_tag;
/define_type;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft