support ipv6 peers

This commit is contained in:
j 2023-10-12 12:24:32 +01:00
parent e4dd22b0bd
commit df1eb190cb

View file

@ -92,7 +92,10 @@ class Player(Thread):
def ping(self):
data = 'NEXT'
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if ':' in self.peer:
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
logger.debug("ping: %s %s", self.peer, data)
sock.sendto(bytes(data + "\n", "utf-8"), self.peer)
received = str(sock.recv(1024), "utf-8")
@ -105,7 +108,11 @@ class Player(Thread):
def get_position(self):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
if ':' in self.peer:
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(1)
data = 'POS'
sock.sendto(bytes(data + "\n", "utf-8"), self.peer)
@ -122,7 +129,8 @@ def main():
prefix = os.path.expanduser('~/Videos/CDOSEA')
parser = argparse.ArgumentParser(description='play 2 screens in sync')
parser.add_argument('--peer', help='ip[:port] of peer', required=True)
parser.add_argument('--peer', help='ipof peer', required=True)
parser.add_argument('--peer', help='port of peer')
parser.add_argument('--port', type=int, help='local port', default=DEFAULT_PORT)
parser.add_argument('--playlist', help='play.m3u', default=playlist)
parser.add_argument('--prefix', help='video location', default=prefix)
@ -136,6 +144,8 @@ def main():
else:
peer = (args.peer, DEFAULT_PORT)
time.sleep(10)
DEBUG = args.debug
if DEBUG:
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'