Archive for the 'Code' Category

Viewing TV on Mac OSX using an HDHomeRun and Plex

Friday, May 10th, 2013

The original HDHomeRun plug-in for Plex Media Server no longer works on the later versions of Plex and V2 is still in need of work. Thanks to those on the PlexApp forums, especially enduser, I am able to easily generate a quick work-around until the plug-in can be finished.

The work around involves creating .strm files for each of the active channels. I wrote a simple bash script, to run as a user on OSX, to find the HDHomeRun device, determine the channel list, and create a number of .strm files in your ~/Movies folder. Make sure to run this app as the person who will be running Plex.

To view a channel, select Video Channels in Plex, then select Movies, and finally select the channel you wish to view.

Copy the following code to a file on your desktop, create-hdhomerun-strms.sh, and when comfortable with the code within, execute the script in the Terminal app, using

sh create-hdhomerun-strms.sh

#!/bin/sh
CleanUp()
{
  rm -rf $SCAN_FILE
}
TUNER_ID=$(hdhomerun_config discover | awk '{ print $3 }')
SCAN_FILE=/tmp/${TUNER_ID}.log
trap CleanUp 1 2 3 15
read -p "Ready to create .strm files for HDHomeRun Tuner ID $TUNER_ID? " -r
if ! [[ "$REPLY" =~ ^[Yy]$ ]]
then
  exit 1
fi
if ! [ -r $SCAN_FILE ]
then
  echo
  echo Please wait while scanning channels. This may take a few minutes
  echo
  hdhomerun_config $TUNER_ID scan /tuner0 $SCAN_FILE
fi
for IDX in 0
do
  sed -En "
    /^SCANNING: [0-9]/ {
      s/^SCANNING: //
      s/ .*//
      h
    }
    /(encrypted)/ d
    /^PROGRAM [0-9]+: 0/ d
    /^PROGRAM [0-9]+: [0-9]+\.[0-9]+ / {
      s/^PROGRAM ([0-9]+): ([0-9]+\.[0-9]+) ([- A-Z0-9a-z.]+)/hdhomerun:\/\/$TUNER_ID-$IDX\/tuner$IDX \2 \3\?channel=auto:##\&program=\1\&range=/
      G
      s/(.+):##(.+)\n([0-9]+)/\1:\3\2/
      P
    }
  " $SCAN_FILE | while read url
  do
    file=$(echo $url | sed -e 's/.* //' -e 's/\?.*//')
    if [ $IDX -gt 0 ]
    then
      file="$file ($IDX)"
    fi
    file="${file}.strm"
    echo $url > ~/Movies/$file
    echo $file
  done
done

Updating to the Release Version of Outlook 2010 from the Beta Removes RSS Feeds

Wednesday, May 12th, 2010

Looks like there is a problem during the installation of the release version of Outlook 2010 in that the RSS feeds are not preserved (it appears it keeps the last added feed). Prior to uninstalling the beta version of Outlook 2010, make sure to export the RSS feeds as an OPML file. Then, after the installation is complete, import the OPML file to restore the RSS feeds.

To export the RSS Feeds, click on the File tab in the Ribbon and click on Open on the left pane. Select “Import” to start the Import and Export Wizard. From there, select Export RSS Feeds to an OPML file and continue as directed. Use the same process to Import the RSS Feeds from an OPML file.

If you are in the same boat as I, try restoring a previous version of the RSS Feeds file. On my Windows 7 box, it exists in:

%USERPROFILE%\AppData\Local\Microsoft\Outlook

My file ends with .sharing.xml.obi and it was about 3k.

First, close all running instances of Outlook.

Navigating to that directory, right click on the file and select Restore previous versions. Select the most recent version prior to the date of the installation.

Next, make sure to copy that file as it will be rewritten by Outlook when it is run again.

I am unable to determine how to get Outlook to recognize this file so the .obi file needs to be converted to an OPML file that can be imported into Outlook. This is simply achieved through an XSL transformation. By applying the following XSL on the .sharing.xml.obi file, an OPML file is created that can be used to import the RSS feeds into Outlook.

Prior to importing the RSS feeds, delete the folders, otherwise duplicate folders will appear under RSS Feeds.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <opml version="1.0">
      <head>
        <title>OPML exported from Outlook</title>
        <dateCreated>Wed, 12 May 2010 16:00:00 -0400</dateCreated>
        <dateModified>Wed, 12 May 2010 16:00:00 -0400</dateModified>
      </head>
      <body>
        <xsl:for-each select="sharing/bindings/binding">
          <xsl:element name="outline">
            <xsl:attribute name="text"><xsl:value-of select="local/@name"/></xsl:attribute>
            <xsl:attribute name="type">rss</xsl:attribute>
            <xsl:attribute name="xmlUrl"><xsl:value-of select="remote/@path"/></xsl:attribute>
          </xsl:element>
        </xsl:for-each>
      </body>
    </opml>
  </xsl:template>
</xsl:stylesheet>

Rewriting the From: E-mail Header Using Sendmail and MIMEDefang

Wednesday, April 21st, 2010

I frequently give out email addresses using <yourdomain@mydomain.com>; this way I am able to track the source of spam I receive. It also easily enables me to reject future email to that account by adding a line to sendmail‘s access file along with a “pleasant” 550 response message when warranted. My problem has been how to send an e-mail using that address.

The solution is quite simple – I specify the address in the Reply-To field of my e-mail client and use MIMEDefang to add an action to change the From: Header to the Reply-To: header.

Fortunately, I already had MIMEDefang added into the mix as I use it and SpamAssassin for processing mail. I had some difficulty understanding where and how to add the logic in the mimedefang-filter perl script but finally found useful information at http://www.mickeyhill.com/mimedefang-howto/ and through searching archives of the MIMEDefang mailing list.

I don’t have any users that use Reply-To and so the determination of when to apply this is quite simple; if the mail originated on the local LAN and the Reply-To header exists and has an email address then change the From header to the Reply-To contents and delete the Reply-To header. You may need to alter the contents of the if logic.

This is accomplished with the following code, placed near the end of sub filter_end:

    # Rewrite From: header with Reply-To: if it exists
    if ($RelayAddr =~ "^192\.168\.1\." && $entity->head->get('Reply-To') =~ /@/) {
        action_change_header('From', $entity->head->get('Reply-To'));
        action_delete_header('Reply-To');
    }

Automatically Scraping Jobs from LinkedIn Using Ruby

Friday, April 16th, 2010

There are a number of job postings on LinkedIn that are of no interest to me; many times I have to go through page after page of jobs to look for the few that are appropriate. To make it less tedious, I have shortened the process by automating this task and filtering out the jobs I do not want. I've done so using Ruby and shell scripting. I run the script every night through cron and mail the results to me.

This process has a few hurdles to jump:

  1. automation of the login and paging of the search results
  2. collecting the interesting job information
  3. html email output
  4. running an interactive browsing session in a cron process

I have tackled these issues with the following tools:

  1. Firefox on Linux (Fedora)
  2. Ruby & Gems: Nokogiri (or Hpricot), FireWatir
  3. sendmail
  4. Xvfb

This process is dependent on Firefox and Linux (Fedora) but can be modified without much difficulty to utilize other platforms. The scripts perform no error checking to keep the size small for the purpose of this blog entry. Read on for the code.

(more…)

stop spam with honeypot!