<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Little Off &#187; stylesheet</title>
	<atom:link href="http://www.bemasher.net/archives/tag/stylesheet/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bemasher.net</link>
	<description>Code, Computers, Photography and Guns</description>
	<lastBuildDate>Mon, 21 Nov 2011 06:38:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Podcast Downloading on FreeNAS.</title>
		<link>http://www.bemasher.net/archives/235?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=podcast-downloading-on-freenas</link>
		<comments>http://www.bemasher.net/archives/235#comments</comments>
		<pubDate>Thu, 05 Mar 2009 08:41:17 +0000</pubDate>
		<dc:creator>bemasher</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bashpodder]]></category>
		<category><![CDATA[dlna]]></category>
		<category><![CDATA[fetch]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[freenas]]></category>
		<category><![CDATA[fuppes]]></category>
		<category><![CDATA[podcast]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[upnp]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.bemasher.net/?p=235</guid>
		<description><![CDATA[I was thinking earlier this week about how files move too and from my file-server. I discovered that it's more convenient to have the server "pull" files to itself. This actually made me think a little bit more about podcast shows I watch on a pretty regular basis. I thought to myself "Wouldn't it be [...]]]></description>
			<content:encoded><![CDATA[<p>I was thinking earlier this week about how files move too and from my file-server. I discovered that it's more convenient to have the server "pull" files to itself. This actually made me think a little bit more about podcast shows I watch on a pretty regular basis. I thought to myself "Wouldn't it be great if my server would get new episodes for me?". Once all that's done I can easily pull up the Podcasts directory on my friend's PS3 (which this will broadcast to using UPnP DLNA) and watch any new episodes that happen to be there.</p>
<p>I then set out almost immediately to figure out the simplest way to do this. I stumbled upon a script called BashPodder written by <a href="http://lincgeek.org/bashpodder/">Linc</a>. So I figured I'd just give it a try in it's original state. That turned out badly since I discovered that this was meant specifically for linux-based systems. My file-server runs FreeNAS a FreeBSD based OS. FreeBSD has an equivalent but different set of basic system tools. Fetch instead of wget, xml instead of xsltproc and so on.</p>
<p>After about 8 hours of learning my way around the basic set of FreeBSD tools and just generally refreshing myself on shell scripting I had heavily modified the BashPodder script to work on FreeNAS.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`dirname &quot;$0&quot;`</span>&quot;</span><br />
<span style="color: #007800;">script_dir</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span><br />
<br />
<span style="color: #007800;">podcast_dir</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>Main<span style="color: #000000; font-weight: bold;">/</span>Content<span style="color: #000000; font-weight: bold;">/</span>TV\ Shows<span style="color: #000000; font-weight: bold;">/</span>Podcasts<span style="color: #000000; font-weight: bold;">/</span><br />
<br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> podcast<br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$script_dir</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">file</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>fetch <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> - <span style="color: #007800;">$podcast</span> <span style="color: #000000; font-weight: bold;">|</span> xml <span style="color: #c20cb9; font-weight: bold;">tr</span> parse_enclosure.xsl<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$podcast_dir</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">data_dir</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>fetch <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> - <span style="color: #007800;">$podcast</span> <span style="color: #000000; font-weight: bold;">|</span> xml sel <span style="color: #660033;">-T</span> <span style="color: #660033;">-t</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;//channel/title&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/ (.*)//&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">\&quot;</span><span style="color: #007800;">$data_dir</span><span style="color: #000000; font-weight: bold;">\&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$data_dir</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chown</span> ftp:wheel <span style="color: #ff0000;">&quot;<span style="color: #007800;">$data_dir</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$data_dir</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> url <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$file</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">filename</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$url</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/^\(.*\)*\///g&quot;</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$filename</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`grep $url &quot;episodes.txt&quot;`</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetch <span style="color: #660033;">-m</span> <span style="color: #660033;">-q</span> <span style="color: #007800;">$url</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$url</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #ff0000;">&quot;episodes.txt&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`echo $filename | grep -v &quot;.m4v&quot;`</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$filename</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$filename</span> m4v<span style="color: #000000; font-weight: bold;">`</span>mp4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chown</span> ftp:wheel <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$filename</span> m4v<span style="color: #000000; font-weight: bold;">`</span>mp4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chown</span> ftp:wheel <span style="color: #007800;">$filename</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span><br />
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> feeds.list<br />
<br />
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.d<span style="color: #000000; font-weight: bold;">/</span>fuppes <span style="color: #c20cb9; font-weight: bold;">updatedb</span></div></td></tr></tbody></table></div>
<p>I think the only thing I didn't end up changing at all was the xml stylesheet Linc had written since it works perfectly. The basic flow of this program is thus:</p>
<ol>
<li>Move into the directory that the script exists in.</li>
<li>For each line in feeds.list do the following.</li>
<ol>
<li>Move into the scripts directory (there are files we need to parse the feed here).</li>
<li>Get the rss feed.</li>
<li>Parse out the title of the feed.</li>
<li>Parse the urls for each episode in the feed.</li>
<li>Move into the podcast directory.</li>
<li>Make a directory of the same name as the title if necessary.</li>
<li>Move into the directory we just made (or already exists).</li>
<li>For each url we parsed do the following.</li>
<ol>
<li>Determine the filename from the url.</li>
<li>If the episode is not in episodes.txt do the following.</li>
<ol>
<li>Download the episode.</li>
<li>Add the episode to episodes.txt</li>
<li>Change the owner to ftp. (We're running this as root).</li>
</ol>
</ol>
</ol>
<li>Update the Fuppes database.</li>
</ol>
<p>After all that was done and over with I just added a new file extension to the Fuppes (UPnP DLNA server) configuration for telling the PS3 that m4v files are really just mp4 files.</p>
<p>Also I wrote a slightly modified version of the above script for just getting lists of episodes. This is useful because if I don't want to download every single episode in each feed (for when I add new feeds to the feeds list) all I have to do is remove the urls from the episodes.txt file that is generated and run the main script. The modification is done in the for loop that handles episodes of each feed:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">filename</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$url</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/^\(.*\)*\///g&quot;</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$filename</span><br />
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-q</span> <span style="color: #007800;">$url</span> <span style="color: #ff0000;">&quot;episodes.txt&quot;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$url</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #ff0000;">&quot;episodes.txt&quot;</span></div></td></tr></tbody></table></div>
<p>So instead of downloading each file it just makes sure it's in the episodes.txt file. If you've got any suggestions for optimization of the script let me know!</p>
<p>If you'd like to check out a read-only copy of the script and necessary configurations:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">svn checkout</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.xp-dev.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>bemasher-FreeNASPodder<span style="color: #000000; font-weight: bold;">/</span> FreeNASPodder</div></td></tr></tbody></table></div>
<p>Keep in mind that the subversion is the most up-to-date copy I'll have available and it may often contain broken code or errors though I'll try to keep that down to a minimum.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bemasher.net/archives/235/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

