[mythtv-users] Errors from myhproto when using mythvidexport.py

Stephen Worthington stephen_agent at jsw.gen.nz
Tue Aug 25 09:46:06 UTC 2020


On Mon, 24 Aug 2020 13:25:27 -0400, you wrote:

>Greetings!
>
>I just upgraded from v30 to v31, and have run in to a problem as described in the subject. I haven’t had any other problems yet surface from my upgrade (knock on wood!).
>
>
>I have tweaked the mythvidexport.py script to use python3, and I am getting an error from mythproto when trying to open the movie file to copy to the videos directory. 
>
>2020-08-24 11:24:53.249257 I [11137] mythvidexport.py Using recording -- b'The Closer' - b'Mom Duty'
>2020-08-24 11:24:53.321444 I [11137] mythvidexport.py Forcing TV export with local data.
>2020-08-24 11:24:53.648925 I [11137] mythvidexport.py Import complete
>2020-08-24 11:24:53.649381 I [11137] mythvidexport.py Copying myth://Default@mythpc/44303_20200811220000.mp4 to myth://Videos@mythpc/Television/The Closer/Season 02/The Closer - S02E02 - Mom Duty-44303-20200811180000.mp4
>2020-08-24 11:24:53.969356 C [11137] mythvidexport.py 
>    Traceback (most recent call last):
>      File "/usr/local/bin/mythvidexport.py", line 438, in main
>        export = VIDEO(opts,int(args[0]))
>      File "/usr/local/bin/mythvidexport.py", line 77, in __init__
>        self.copy()
>      File "/usr/local/bin/mythvidexport.py", line 269, in copy
>        dstfp.write(srcfp.read(tsize))
>      File "/usr/lib/python3.6/codecs.py", line 321, in decode
>        (result, consumed) = self._buffer_decode(data, self.errors, final)
>    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 41: invalid start byte
>
>
>I haven’t been able to track through all the steps as to where the file is being opened as I think that is where the problem is according to my search abilities.
>
>Any ideas where I need to check? Or? 
>
>Thanks!

I have never used mythvidexport.py, but I have been converting my
Python 2 programs to Python 3.  One of the things you have to watch
out for is that Python 3 needs to have things either using unicode
strings (the default), or byte data.  Your problem looks like a case
where unicode strings were used when it should have been byte data
(type "bytes").  I am just guessing from the code in the traceback,
but it looks like it is copying a video file.  A video file is byte
data and will occasionally contain data that does not represent valid
unicode, causing an error as above.  So you need to find where the
source (srcfp) and destination (dstfp) files are opened and change the
open mode to binary ('rb' instead of 'r', 'wb' instead of 'w').  That
may be the entire fix that is needed as that will cause strings read
from the file to be created as "bytes" type, but if you still get
errors, ensure that "bytes" types are used for the buffers used for
the copying.

See here for more about the problem:

https://medium.com/better-programming/strings-unicode-and-bytes-in-python-3-everything-you-always-wanted-to-know-27dc02ff2686


More information about the mythtv-users mailing list