[mythtvnz] Python 3

Stephen Worthington stephen_agent at jsw.gen.nz
Wed Mar 10 10:01:26 GMT 2021


On Wed, 10 Mar 2021 16:48:55 +1300, you wrote:

>On Wed, 10 Mar 2021 15:10:28 +1300
>Stephen Worthington <stephen_agent at jsw.gen.nz> wrote:
>
>> On Wed, 10 Mar 2021 11:46:18 +1300, Austin Green wrote:
>> >Recently decided to make Python 3 the default on my system, since Python 2.7 is officially dead.  The EPG update stopped working.  Is there a Python 3 version of the MythTV module?  Currently working round it by forcing mhegepgsnoop.py to run with python2, but would prefer a 'proper' fix.
>> 
>> That is what I am doing.  I did try making a Python 3 version of
>> mhegepgsnoop.py but did not get it fully working as I do not
>> understand the MHEG5 protocol so I did not understand what some of the
>> code was supposed to be doing.  The problem was that the MHEG-5
>> standards documents are paywalled - and cost heaps.  But today I did
>> another search and found one that says it is the final draft of
>> MHEG-5, which would probably be good enough for me to use.  So I will
>> have another look at getting mhegepgsnoop.py working with Python 3.
>
>No big deal to convert mhegepgsnoop.py, just the format of 'print' calls and one IO exception; don't need to understand what it's trying to do (fortunately!).  The problem arises when it tries to use the Python MythTV API - it complains "No module named 'MythTV'".  There is indeed no Python3 version of the MythTV module, or if there is, the pip installer doesn't know where to find it (and nor do I).  But surely someone will have done a Python 3 version of it by now?

So do I understand from this that you have a Python 3 version of
mhegepgsnoop.py that runs and only fails on not finding a MythTV
module?  I think that because it is not finding that module, it is
actually failing very early, before most of the problem code even gets
executed.  You need to try running mhegepgsnoop.py in the mode where
it does not use the MythTV bindings.  This is how I run it:

root at mypvr:/tmp# cat /usr/local/bin/do_mhegepgsnoop.sh
#!/bin/bash

# DVB-T multiplex frequency (kHz)
DVB_T_FREQ=610000

# Adapter number of DVB-T card.
ADAPTER=17

# Number of times to try mhegepgsnoop.py if it fails.
TRIES=5

# Amount of time to sleep between tries.
SLEEP_TIME=5m

# Output file to store the xmltv EPG data.
TEMP_FILE=/tmp/xmltv.xml
OUTPUT_FILE=/var/www/html/epg/listings-mheg5.xml

# Channel map file.
MAP_FILE=/home/stephen/bin/mhegepgsnoop_channel_map.txt


retval=0

#PWD=`pwd`

if [ -e "$TEMP_FILE" ] && [ -f "$TEMP_FILE" ] ; then
    rm "$TEMP_FILE"
fi

for ((i=1; i<=$TRIES; i++)); do
    # Get the MHEG5 EPG data from the DVT-T multiplex.
    echo "Try $i, Running dvbtune"
    dvbtune -f $DVB_T_FREQ -qam 64 -gi 16 -cr 3_4 -bw 8 -tm 8 -m -c
$ADAPTER 2>&1 &
    DVBTUNE_PID=$!
    sleep 1
    echo "Try $i, running mhegepgsnoop.py now"
    mhegepgsnoop.py2 -v -z -d /dev/dvb/adapter${ADAPTER}/demux0 -o
$TEMP_FILE -f $MAP_FILE
    retval=$?
    kill $DVBTUNE_PID
    if [ $retval -eq 0 ]; then
        break
    fi
    rm $TEMP_FILE
    echo "Warning: mhegepgsnoop failed (retval=$retval), retrying
after sleep $SLEEP_TIME"
    sleep $SLEEP_TIME
done
if [ $retval -ne 0 ]; then
    echo "Error: mhegepgsnoop failed after $TRIES tries
(retval=$retval)!"
else
    # Temporary fix for bad <channel id> values in the MHEG5 EPG data.
    sed -f /usr/local/bin/mhegepgsnoop_sed_replacements --in-place
$TEMP_FILE

    mv $TEMP_FILE $OUTPUT_FILE
    chmod a+rw $OUTPUT_FILE
fi

exit $retval


For me, the conversion to Python 3 was not simple - mhegepgsnoop.py
uses some nice coding tricks to extract the data structures in the
data it downloads, prior to outputting the data as XML.  Those coding
tricks did not convert at all to Python 3 as they involve strings and
bytes and that is a place where there are big changes between Python 2
and Python 3.  So my Python 3 version works up until the point where
it has completed downloading the data, and then crashes as it tries to
convert the data to XML.  The proper fix would be a rewrite to use the
new Python 3 features that handle structures in data, but I would be
happy if I could just work out how to adjust the exiting code for
Python 3.



More information about the mythtvnz mailing list