Skip to content

Commit 9c19cee

Browse files
committed
update for python 3.9 and latest dependency package versions
- pylint removed bad-whitespace error. http://pylint.pycqa.org/en/latest/whatsnew/2.6.html - updating zeroconf from 0.24 to 0.28 required several changes in beacon.py - ServiceInfo address member was deprecated and then removed, addresses should now be used - ServiceInfo ctor argument order changed, and address was replaced by addresses - ServiceListeners will soon require an update_service method although it may do nothing - python 3.9 plistlib module has removed the old API. It's used by metadata in a section of code that I do not think has ever been tested by me after updated from python 2 to 3. I've updated the code as I believe is needed, but it is *still* untested. - python 3.9 xml.xmlparser expat is giving errors (I'm not totally sure these errors didn't exist before). Some googling also made me believe in this instance the pylint errors may be false positives. - `metadata.py:608:23: E1101: Instance of 'module' has no 'codes' member (no-member)` - `metadata.py:608:42: E1101: Instance of 'module' has no 'XML_ERROR_INVALID_TOKEN' member (no-member)` - fixed a typo error in plugins/video/video.py
1 parent e6fc470 commit 9c19cee

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

beacon.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def bytes2str(data):
2323
"""
2424
Convert bytes to str as utf-8. sequence values (and keys) will also be converted.
2525
"""
26-
# pylint: disable=bad-whitespace,multiple-statements
26+
# pylint: disable=multiple-statements
2727

2828
if isinstance(data, bytes): return data.decode('utf-8')
2929
if isinstance(data, dict): return dict(map(bytes2str, data.items()))
@@ -44,7 +44,7 @@ def log_serviceinfo(logger, info):
4444
log_level = logging.INFO
4545

4646
log_info = {'name': info.name,
47-
'address': socket.inet_ntoa(info.address),
47+
'address': socket.inet_ntoa(info.addresses[0]),
4848
'port': info.port}
4949
log_hdr = "\n {address}:{port} {name}\n"
5050
log_fmt = log_hdr
@@ -69,14 +69,23 @@ def log_serviceinfo(logger, info):
6969
class ZCListener:
7070
# pylint: disable=redefined-builtin
7171

72-
def __init__(self, names):
72+
def __init__(self, names, logger=None):
7373
self.names = names
74+
self.logger = logger
75+
76+
def remove_service(self, server, type_, name):
77+
self.names.remove(name.replace('.' + type_, ''))
7478

75-
def remove_service(self, server, type, name):
76-
self.names.remove(name.replace('.' + type, ''))
79+
def add_service(self, server, type_, name):
80+
self.names.append(name.replace('.' + type_, ''))
81+
82+
def update_service(self, server, type_, name):
83+
# method is required, but can be ignored if you don't care about updates. We don't.
84+
if self.logger is not None:
85+
# ex. WARNING:pyTivo.beacon:ZCListener.update_service name='Movies._tivo-videos._tcp.local.' type_='_tivo-videos._tcp.local.'
86+
# WARNING:pyTivo.beacon:ZCListener.update_service name='LivingRoomVox._tivo-videos._tcp.local.' type_='_tivo-videos._tcp.local.'
87+
self.logger.debug(f'ZCListener.update_service {name=} {type_=}')
7788

78-
def add_service(self, server, type, name):
79-
self.names.append(name.replace('.' + type, ''))
8089

8190
class ZCBroadcast:
8291
def __init__(self, logger):
@@ -129,7 +138,7 @@ def __init__(self, logger):
129138

130139
info = zeroconf.ServiceInfo('_%s._tcp.local.' % tt,
131140
'%s._%s._tcp.local.' % (title, tt),
132-
address, port, 0, 0, desc)
141+
port=port, addresses=[address], properties=desc)
133142

134143
log_serviceinfo(self.logger, info)
135144
self.rz.register_service(info)
@@ -144,7 +153,7 @@ def scan(self):
144153
self.logger.info('Scanning for TiVos...\n')
145154

146155
# Get the names of servers offering TiVo videos
147-
browser = zeroconf.ServiceBrowser(self.rz, VIDS, None, ZCListener(names))
156+
browser = zeroconf.ServiceBrowser(self.rz, VIDS, None, ZCListener(names, logger=self.logger))
148157

149158
# Give them a second (or more if no one has responded in the 1st second) to respond
150159
time.sleep(1)
@@ -164,13 +173,17 @@ def scan(self):
164173
log_serviceinfo(self.logger, info)
165174

166175
if info:
176+
# zeroconf v2.7 removed ServiceInfo address member says use addresses instead.
177+
# Some debug logging to see if there is always at least the currently assumed 1 address (and maybe more?)
178+
self.logger.debug(f'Found zeroconf.ServiceInfo with {len(info.addresses)} IP addresses\n')
179+
167180
tsn = info.properties.get(b'TSN')
168181
if config.get_togo('all'):
169182
tsn = info.properties.get(b'tsn', tsn)
170183
if tsn:
171184
if isinstance(tsn, bytes):
172185
tsn = tsn.decode('utf-8')
173-
address = socket.inet_ntoa(info.address)
186+
address = socket.inet_ntoa(info.addresses[0])
174187
port = info.port
175188
config.tivos[tsn] = {'name': name, 'address': address,
176189
'port': port}

config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ def get_tsn(name, tsn=None, raw=False):
383383
# For example, 2K==2000, 2Ki==2048, 2MB==16000000, 2MiB==16777216
384384
# Algorithm: http://svn.mplayerhq.hu/ffmpeg/trunk/libavcodec/eval.c
385385
def strtod(value):
386-
# pylint: disable=bad-whitespace
387386
prefixes = {'y': -24, 'z': -21, 'a': -18, 'f': -15, 'p': -12,
388387
'n': -9, 'u': -6, 'm': -3, 'c': -2, 'd': -1,
389388
'h': 2, 'k': 3, 'K': 3, 'M': 6, 'G': 9,

metadata.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from datetime import datetime
1111
from xml.dom import minidom
1212
from xml.parsers import expat
13+
1314
try:
1415
import plistlib
1516
except:
@@ -265,7 +266,9 @@ def from_moov(full_path):
265266
# I don't know if the returned data is still in the same format
266267
# AND readPlistFromBytes is deprecated, should use loads, so work
267268
# to do when what this does is better understood and can be tested. -mjl 2017-07-14
268-
data = plistlib.readPlistFromBytes(value)
269+
# 3.9 removed the old api, so w/o any testing, I'm changing this to loads -mjl 2021-02-21
270+
#data = plistlib.readPlistFromBytes(value)
271+
data = plistlib.loads(value)
269272
except:
270273
pass
271274
else:
@@ -275,7 +278,9 @@ def from_moov(full_path):
275278
elif (key == '----:com.pyTivo.pyTivo:tiVoINFO' and
276279
'plistlib' in sys.modules):
277280
try:
278-
data = plistlib.readPlistFromBytes(value)
281+
# 3.9 removed the old api, so w/o any testing, I'm changing this to loads -mjl 2021-02-21
282+
#data = plistlib.readPlistFromBytes(value)
283+
data = plistlib.loads(value)
279284
except:
280285
pass
281286
else:
@@ -354,7 +359,10 @@ def from_eyetv(full_path):
354359
eyetvp = [x for x in os.listdir(path) if x.endswith('.eyetvp')][0]
355360
eyetvp = os.path.join(path, eyetvp)
356361
try:
357-
eyetv = plistlib.readPlist(eyetvp)
362+
# 3.9 removed the old api, so w/o any testing, I'm changing this to load -mjl 2021-02-21
363+
#eyetv = plistlib.readPlist(eyetvp)
364+
with open(eyetvp, 'rb') as eyetvfp:
365+
eyetv = plistlib.load(eyetvfp)
358366
except:
359367
return metadata
360368
if 'epg info' in eyetv:
@@ -597,7 +605,7 @@ def _parse_nfo(nfo_path, nfo_data=None):
597605
try:
598606
xmldoc = minidom.parseString(os.linesep.join(nfo_data))
599607
except expat.ExpatError as err:
600-
if expat.ErrorString(err.code) == expat.errors.XML_ERROR_INVALID_TOKEN:
608+
if err.code == expat.errors.codes[expat.errors.XML_ERROR_INVALID_TOKEN]:
601609
# might be a URL outside the xml
602610
while len(nfo_data) > err.lineno:
603611
if len(nfo_data[-1]) == 0:

plugins/video/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def GetActiveTransferCount(self, handler, query):
106106
json_config['count'] = count
107107
handler.send_json(json.dumps(json_config))
108108

109-
def GetTransferStatus(selfself, handler, query):
109+
def GetTransferStatus(self, handler, query):
110110
"""
111111
HTTP command handler to return the status of current uploads to TiVos
112112
as a json object

showinfo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
# I want to line up the values in dicts, lists and tuples such as
1212
# the ShowInfo.FieldInfo default_val in metafields so:
13-
# pylint: disable=bad-whitespace
1413

1514
# Various TV ratings strings associated with their rating value
1615
TV_RATINGS = {1: ('Y7', 'TV-Y7', 'X1', 'TVY7'),

0 commit comments

Comments
 (0)