MythTV and EPG Data

From Blue-IT.org Wiki

Revision as of 13:15, 8 June 2009 by Apos (talk | contribs) (Grabber script 1)

MyhtTV

MythTV is the well known linux HPTC software.

One of the major advantages is the availability of an electronic program guide, that is fetched from grabbing tv-guide web pages with an external program: the 'grabber'.

On of the major problems setting up the mythtv program guide is, that the 'grabbers' are not part of myhttv and it is not trivial to install them.

None of these grabbers - for a list see xmltv - runs out of the box after installation.

Xmltv_prisma

After a having a lot of problems with the xmltv grabber, my favorite grabber is xmltv_prisma. It uses the webpage of the Prisma TV Guide.

Alter the mythtv channels table

The very first thing you have to do is to add an 'xmltvid' to each channel in the table 'channels' in the mythtv database. This database is named per default is 'mythconverg'.

What is the 'xmltvid' for a certain channel? Very easy. It is exact the string that you can read in your configuration file after you called

tv_grab_de_prisma --configure --gui

This file is located per default in '~/.xmltv/tv_grab_de_prisma.conf'. It looks like this

[...] 
channel 3.br-online.de #BR
channel 3sat.de #3SAT
channel ard.de #ARD
channel arte-tv.com #arte
channel dsf.com #DSF
channel einsplus.ard.de #Einsplus (ARD digital)
channel eurosport.de #Eurospor
[...]

The string after channel is the 'xmltvid'. The following command will give you these id's (uses mawk):

cat /home/whoever/.xmltv/tv_grab_de_prisma.conf  | mawk '{gsub(/^channel /,"");system("echo " $0 "")}'

You have to enter it manually into your database.

This could be done ether by editing the table with e.g. phpmyadmin or add them into the 'configuration' page of 'mythweb' (a plugin for myhttv).

Two scripts for running the grabber

Grabber script 1

#!/bin/sh
ACTUAL_PATH='pwd'
XMLDIR="$HOME/.xmltv/xml"
DATE=`date +%F`
DAYS=1
OFFSET=$1
chmod 770 $XMLDIR

if [ "${OFFSET}" = "" ]
then 

echo WARNING: No offset specified. echo WARNING: An offset of 0 will be assumed. OFFSET='0'

else

[ ${OFFSET} -lt 0 ] && OFFSET='0'

fi
 
echo ---------------------------------------------------------------------
echo This is user $USER on $HOSTNAME.
echo "This is running $0 script at ${DATE} with offset of ${OFFSET} days."
echo "This is running $0 script at ${DATE} with offset of ${OFFSET} days." >> /var/log/mythtv/xmltv.log

cd ~/.xmltv
[ -d $XMLDIR ] || mkdir -p $XMLDIR

XML=$XMLDIR/prisma_${DATE}-${OFFSET}.xml

tv_grab_de_prisma --days ${DAYS} --offset ${OFFSET} --slow --output $XML || exit 1

if [ -f $XML ]; then
   mythfilldatabase --update --file 1 $XML || exit 1
   #mythfilldatabase --update --no-delete --file 1 0 $XML || exit 1
   #mythfilldatabase --update --no-delete --file 1 -1 $XML
fi

exit 0

Script with defined offset

The next script I use in conjunction with several crontab entries. It grabs only 3 days an runs every day. The script uses an offset parameter that controls the prisma grabber to grab date in future.

Prerequisites

The following scripts imply that you

  • have a fully configured tv_grab_de_prisma
  • use /home/mythtv/.xml/ directory to store the data and scripts
  • know how to edit your crontab as root
#!/bin/sh
ACTUAL_PATH='pwd'
XMLDIR="$HOME/.xmltv/xml"
DATE=`date +%F`
DAYS=1
OFFSET=$1
chmod 770 $XMLDIR

if [ "${OFFSET}" = "" ]
then 
	echo WARNING: No offset specified. 
	echo WARNING: An offset of 0 will be assumed.
	OFFSET='0'
else
	[ ${OFFSET} -lt 0 ] && OFFSET='0'
fi

echo ---------------------------------------------------------------------
echo This is user $USER on $HOSTNAME.
echo "This is running $0 script at ${DATE} with offset of ${OFFSET} days."
echo "This is running $0 script at ${DATE} with offset of ${OFFSET} days." >> /var/log/mythtv/xmltv.log

cd ~/.xmltv
[ -d $XMLDIR ] || mkdir -p $XMLDIR

XML=$XMLDIR/prisma_${DATE}-${OFFSET}.xml

tv_grab_de_prisma --days ${DAYS} --offset ${OFFSET}  --output $XML || exit 0

if [ -f $XML ]; then
   mythfilldatabase --update --file 1 $XML || exit 0
fi

sleep 5

exit 1

It will be invoked running as user mythtv using something like

ssh mythtv@localhost
mythtv@mythbackend# for day in 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; \
   do /bin/bash ~/.xmltv/xmltv_prisma_offset.sh $day; done

Use with cron

To grab the data every day in the early morning (5 o'clock) you can use cron.

Change to user root and edit your crontab entry with

crontab -e -u mythtv

Than add the following data

# m h  dom mon dow   command
## Mythtv EPG Daten grabben
0 5 * * 1 for day in 0 1 2 3; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done
0 5 * * 2 for day in 4 5 6 7; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done
0 5 * * 3 for day in 8 9 10 11; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done
0 5 * * 4 for day in 12 13 14 15; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done
0 5 * * 5 for day in 16 17 18 19; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done
0 5 * * 6 for day in 20 21 22 23; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done
0 5 * * 7 for day in 24 25 26 27; do /bin/bash /home/mythtv/.xmltv/xmltv_prisma_offset.sh $day; done

I use the following scheme to grab the data.

|> = day where the grabber runs with a defined offset
|  = offset days
o  = days that will be really grabbed
Mo  Di  Mi  Do  Fr  Sa  So  Mo  Di  Mi  Do  Fr  Sa  So  Mo  Di  Mi  Do  Fr  Sa  So

|>offset 0
o---o---o

    |>offset 2
    |---|---o---o---o

        |>offset 4
        |---|---|---|---o---o---o

            |>offset 6
            |---|---|---|---|---|---o---o---o

                |>offset 8
                |---|---|---|---|---|---|---|---o---o---o      

                    |>offset 10
                    |---|---|---|---|---|---|---|---|---|---o---o---o

                        |>offset 12
                        |---|---|---|---|---|---|---|---|---|---|---|---o---o---o

Secure Mythweb (german)

I got the next informations from a german wiki:[1] After you installed mythweb, the following points should be considered.

[...] Damit Digest überhaupt funktioniert, muss der Apache entsprechend konfiguriert sein.

Unter Debian Sarge mit Apache 1.3.x genügt hierzu ein

echo "LoadModule digest_auth_module /usr/lib/apache/1.3/mod_auth_digest.so" \

>> /etc/apache/modules.conf

Für apache2 geht es folgendermaßen:

a2enmod auth_digest
a2enmod authn_file
a2enmod authz_user
/etc/init.d/apache2 force-reload               

Die .htaccess mit dem Editor öffnen:

vi /usr/share/mythtv/mythweb/.htaccess

Folgender Auszug muss auskommentieren werden:

AuthType           Digest
AuthName           "MythTv"
AuthDigestFile     /var/www/htdigest <- UNBEDINGT IN /var/htdigest ÄNDERN! 
Require            valid-user

Dies bedeutet, dass wir mit dem Tool htdigest eine Datei mit dem Namen /var/htdigest anlegen müssen. Im Gegensatz zur alten Methode spielt hier allerdings auch die AuthName-Zeile eine Rolle, die bei htdigest unter der Bezeichnung Realm (zu deutsch: Bereich) angegeben werden muss.

htdigest akzeptiert laut man-page folgende Parameter:

htdigest [ -c ] passwdfile realm username

was uns also im konkreten Beispiel zu folgender Befehlszeile führt (mit verändertem Pfad):

htdigest -c /var/htdigest MythTV mythtv

Achtung! Die Option -c überschreibt die angegebene Datei, also Vorsicht! Danach ruft man die mythweb.php erneut auf und loggt sich mit seinem Usernamen(hier: mythtv) und dem angegebenen Passwort ein [...]

Troubleshooting

Database cannot connect

Considering a master backend without frontend the following settings are crucial.

mythtv-setup

Both ip's in the gneral setting page 1 MUST point to the servers ip address (NOT 127.0.0.1).

database->mythconverg->settings table

Attention:

  • "OLDPASSWORD" is really written into the field hostname
  • "NULL" means this is a NULL field (e.g you have to check the null checkbox field in e.g. phpmyadmin)
  • Even if the backend server ip settings is the real server ip, here 127.0.0.1 is the right setting.
value                 data            hostname
BackendServerIP  	127.0.0.1  	OLDPASSWORD
BackendServerPort 	6543 	        OLDPASSWORD
BackendStatusPort 	6544 	        OLDPASSWORD
MasterServerIP 	192.168.0.3 	NULL
MasterServerPort 	6543 	        NULL
RecordFilePrefix 	/mythtv/tv 	NULL

/root/.mythtv

config.xml

<Configuration>
  <UPnP>
    <UDN>
      <MediaRenderer>04f9028d-752c-45e1-abca-534adaf8a8ba</MediaRenderer>
    </UDN>
    <MythFrontend>
      <DefaultBackend>
        <USN>uuid:04f9028d-752c-45e1-abca-534adaf8a8ba::urn:schemas-upnp-org:device:MediaServer:1</USN>
        <SecurityPin></SecurityPin>
	<DBHostName>localhost</DBHostName>
        <DBUserName>mythtv</DBUserName>
        <DBPassword>mythtv</DBPassword>
        <DBName>mythconverg</DBName>
        <DBPort>3306</DBPort>
      </DefaultBackend>
    </MythFrontend>
  </UPnP>
</Configuration>

mysql.txt

DBHostPing=no
DBHostName=localhost
DBUserName=mythtv
DBPassword=PASSWORD
DBName=mythconverg
DBType=

/home/mythtv/.mythtv/

mysql.txt

DBHostName=localhost
DBHostPing=no
DBUserName=mythtv
DBPassword=PASSWORD
DBName=mythconverg
DBType=QMYSQL3

Error editing videos- No Seektable

Myhttv stores the information about video length and seeks in an external databse, called seek table (see [2] for a detailed explanation).

If you get the error no seektable, when you like to edit your videos, this is because mythtv has no data about the length of your video. There are several ways to fix this.

Check, if you mysql seektable databas=e is o.k.

mysqlcheck -u mythtv -p -r  mythconverg  recordedseek

If you get the output

mythconverg.recordedseek        OK

Then everything is fine. If not, you should run

mysqlcheck -u mythtv -p --auto-repair  mythconverg  recordedseek && \
mysqlcheck -u mythtv -p -r  mythconverg  recordedseek

Now you should start the commercial detection (as user mythtv) with

mythcommflag --rebuild -f  1501_20070601004300.mpg

1501_20070601004300.mpg is a sample filename for a recording.

Now you should be able to edit you video as usual ;)

A Trick for advanced linuxers: If you have a gigabit connection to your mythtv box and a fast machine, you can mount your myhttv box via nfs and then chroot into it. You can start mythcommflag in that chroot environment and it will use the processor power of your faster machine for

Mytharchive

Mythtranscode not found

On Ubuntu there exists a bug bug #92703. Mythtranscode is part of the mythbackend package. So if you are running mytharchive on the frontend and myhthtranscode fails simply install mythbackend package without configuring it.

sudo apt-get install mythbackend

Error when using mytharchive on seperate frontend

On june/2007 I tried to use mythtarchive on my frontend machine for burning a dvd. The system crashed with the following error:

[...]
AttributeError: 'NoneType' object has no attribute 'endswith'

The reason for this behaviour is, that mytharchive assumes, masterbackend and frontend server are running on the same machine. So the mythconverg database settings table points to the wrong server, when running mytharchive on a sperate frontend machine.

Solution

I googled arround and found bug #118700.

The solution is:

Exclude all other problems and manually edit the mythconverg/settings table and fill in the real name of your frontends network name. This solution works on ubuntu feisty (7.04) - both backend and frontend.

1. Your mythtv masterbackend servers name/ip is: backendserver / 192.168.0.10

2. Your mythtv frontend servers name/ip is: mypc / 192.168.0.5

3. Your backend/frontend servers are configured properly and are working together, user for mysql is mythtv and the password is set to mythtv.

4. The problem might be, that you forget to share the tv-data directory via nfs on both machines. Each paths must be identically and readable for the machine! An /etc/fstab entry on the frontend machine could look like this:

#/etc/fstab
#
[...]
backendserver:/mythtv/tv  /mythtv/tv  nfs  rw,intr,bg,rsize=8192,wsize=8192,user        0       0

Make sure, that the permissions are set correctly (chown -R mythtv:mythtv).

Configure your nfs server on the master backend accordingly e.g:

#/etc/exports
[...]
/mythtv/tv frontendserver(rw,sync,no_root_squash,no_subtree_check)

Additionally it might be usefull to use acl's if your backend runs on different users and make the dierectories read/writable for a common group mythtv . Make shure, that the GID for this group is the same among all machines.

5. The temporary space has enough space and is writable for the frontend. This is also configured in mytharchive settings page.

6. Do the following or manually edit the mythconverg/settings table:

root@mypc$ mysql -h mythtv -u mythtv -p mythconverg
root@mypc$ mysql> insert into settings (value, data, hostname) VALUES ('RecordFilePrefix', '/mythtv/tv', 'backendserver');