Monday, May 17, 2010

Asterisk CallerID look up script for NZ.

It works with by scraping results from yellow pages, where you can feed it a number and if there is a listing that matchs then it returns the company details.


FreePBX Setup

Go to CallerID Lookup Sources and define your own source as following:
Source type: HTTP
cache results: yes ( populates PhoneBook automatically and saves bandwidth)
Host: localhost
Port: 8071
Path: /
Query: [NUMBER]&${CALLERID(name)}

Go to Inboud Routes:
Set the CID Lookup Source to your own source in all Inbound Routes
Internet Services Setup

Since we are using xinetd, put the following in your /etc/services:
asterisklookup 8071/tcp # asterisk lookup
and put the following in xinetd.conf:
service asterisklookup
{
socket_type = stream
protocol = tcp
wait = no
user = asterisk
group = asterisk
server = /usr/local/bin/callerid.sh
disable = no
}

Then restart the xinetd daemon with...
/etc/init.d/xinetd -restart

Create and install script:
#!/bin/sh

read THE_REQUEST

NUMBER=`echo -n $THE_REQUEST | cut -d "?" -f 2`
NUMBER=`echo -n $NUMBER | cut -d "&" -f 1`
INNAME=`echo -n $THE_REQUEST | cut -d "&" -f 2`
INNAME=${INNAME// HTTP\/?.?/}
INNAME=`echo -n ${INNAME} | /usr/bin/strings`
NUMBER=`echo -n ${NUMBER} | /usr/bin/strings`

echo

if [ ${#NUMBER} == 0 ]
then
NUMBER="Unknown"
else
#national number add leading zero
if [ ${NUMBER:0:1} != "0" ]
then
NUMBER="0"${NUMBER}
fi

#international number two leading zero
if [ ${#NUMBER} = 12 ]
then
NUMBER="0"${NUMBER}
fi

NAME=`cat /root/caller-id.txt | grep -i "${NUMBER}" | cut -d "," -f 2 | cut -b 2-`

#not found in local lookup check unknown file
if [ "$NAME" == "" ]
then
NAME=`cat /root/caller-id-unknown.txt | grep -i "${NUMBER}" | cut -d "," -f 2 | cut -b 2-`
fi

#name not found in unknown list check yellow pages
if [ "$NAME" == "" ]
then
NAME=`lynx -connect_timeout=3 -dump http://yellow.co.nz/search/new+zealand/${NUMBER}-1.html 2>/dev/null | grep -i "tick to compare" -A 3 | grep -v -F "[_]" | cut -s -d "]" -f 2`

#result from yellow pages add to local lookup list
if [ "$NAME" != "" ]
then
echo ${NUMBER}, ${NAME} >> /root/caller-id.txt
else
echo ${NUMBER}, Unknown >> /root/caller-id-unknown.txt
fi
fi

NAME=`echo -n ${NAME} | /usr/bin/strings`

#test result returned from local lookup or yellow pages
if [ "$NAME" == "" ]
then
if [ "$INNAME" != "" ]
then
echo $INNAME
else
echo ${NUMBER}
fi
else
echo ${NAME}
fi

Save as callerid.sh, copy into /usr/local/bin and make it executable...
chmod a+x /usr/local/bin/callerid.sh
Make two blank files for the retrieved and unknown callers numbers to be saved, and set the file permissions, and owner to the asterisk user.
echo > caller-id.txt
echo Unknown, Unknown > caller-id-unknown.txt
sudo chown asterisk:asterisk caller-id*
sudo chmod a+rw caller-id*

Done.

Wednesday, May 12, 2010

Myth 0.23 - Upgrade woes

Last night the new install for MythTV 0.23 came down the pike, and showed up in the software updates.

Ya! I thought, and after a lot of downloading and installing it finally arrived, but myth backend had gone away and would start as a service, but would not connect to the database. The backend would run as a program if it was started from the command prompt.

After a lot of looking at files, the internet, and comparisons against the test machine, I discovered that it couldn't access the mysql.txt file, as it was looking for it in /.mythtv, where it should have been in /home/mythtv/.mythtv.

The offending log entries...

2010-05-13 00:46:22.857 mythbackend version: branches/release-0-23-fixes...
2010-05-13 00:46:23.001 Using runtime prefix = /usr
2010-05-13 00:46:23.061 Using configuration directory = /.mythtv
2010-05-13 00:46:23.133 Unable to read configuration file mysql.txt
2010-05-13 00:46:23.193 Empty LocalHostName.
2010-05-13 00:46:23.258 Using localhost value of mythtv
2010-05-13 00:46:23.323 New DB connection, total: 1
2010-05-13 00:46:23.380 Unable to connect to database!
2010-05-13 00:46:23.435 Driver error was [1/1045]:
QMYSQL: Unable to connect
Database error was:
Access denied for user 'mythtv'@'localhost' (using password: YES)


The FIX...

sudo kate /etc/default/mythtv-backend

Change the ARGS line and add the --user $USER command.

ARGS="--user $USER --logfile /var/log/mythtv/mythbackend.log"

Restart the backend service.

sudo /etc/init.d/mythtv-backend restart

If the same problem still exists check the logs first, to determine the correct directory, then check file permissions, or the contents of the mysql.txt file.

Ya!, now I am a happy camper, off to watch some MythTV!

Tuesday, May 11, 2010

MythTV - Convert Recordings to Podcast

A work in progress

Start CPAN Pearl Administrator

sudo cpan
install YAML
install String::Approx
install XML::Simple
install Date::Parse
install Date::Format
install Lingua::EN::Keywords
install Getopt::Long
install File::Temp

WWW::TV didn't install so commented it out on line 333 with a #

find where midentify is hiding on the pc
sudo find | grep midentify
cp to /usr/local/bin

Upgrade FFMPEG drivers to support H264 and AAC

Modify myth2ipod script and change the '-me' option to '-me-method'

Works with MP2 data from the PVR500, but not yet from the h264 DVB-T source