Skip to content

Instantly share code, notes, and snippets.

@nroi
Created September 8, 2016 20:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nroi/0ef6a85d8ec2cbd09960ef0a37cc476e to your computer and use it in GitHub Desktop.
Save nroi/0ef6a85d8ec2cbd09960ef0a37cc476e to your computer and use it in GitHub Desktop.
Demonstrate bug in mpd
#!/usr/bin/env python3
import socket
from time import sleep
import sys
hostname = 'alarm.local'
port = 6600
password = 'secret123'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
print(s.recv(64).decode('ascii'), end="")
s.sendall("password {}\n".format(password).encode('ascii'))
result = s.recv(128)
assert(result == b"OK\n")
for _ in range(0, 30):
s.sendall(b"seekcur 60\n")
result = s.recv(3)
assert(result == b"OK\n")
sleep(.005)
sleep(.5)
s.sendall(b"status\n")
answer = s.recv(1024).decode('ascii')
[elapsed_str] = [x.rstrip() for x in answer.split("\n") if x.startswith("elapsed")]
num_value = float(elapsed_str.split(": ")[1])
print("seeked to position:", num_value)
if num_value < 60:
print("who did that?!")
sys.exit(1)
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment