Skip to content

Commit 1ce2d3b

Browse files
committed
Adapted to moode and newer python
1 parent 909211f commit 1ce2d3b

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

install.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3-
apt-get install python-pygame python-pil
3+
apt-get install python-pil
44
cp -v pictureframe.py /opt/
55
cp -v pictureframe.service /etc/systemd/system
6+
systemctl enable pictureframe
7+
systemctl start pictureframe
8+
systemctl status pictureframe

pictureframe.py

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python
1+
#! /usr/bin/python3
22

33
import os
44
import subprocess
@@ -13,12 +13,14 @@
1313
from PIL import Image, ExifTags
1414
from collections import deque
1515

16+
os.environ["DISPLAY"] = ":0"
1617
SHOW_AFTER_SECS=60
1718
NEXT_IMAGE_AFTER_SECS=20
18-
IMAGE_DIR="/home/volumio/Wallpaper/"
19+
IMAGE_DIR="/home/felix/wallpaper/"
1920
EXTENSIONS=['.jpg', '.jpeg', '.png']
2021
VOLUMIO_STATUS_URL="http://volumio.local:3000/api/v1/getSystemInfo"
2122
DISPLAY_ON=False
23+
MPD_PORT=6600
2224

2325
import signal
2426
def handler(signum, frame):
@@ -40,12 +42,12 @@ def __init__(self):
4042
def run(self):
4143
while True:
4244
try:
43-
with open("/dev/input/event0", "r") as f:
45+
with open("/dev/input/event0", "rb") as f:
4446
while True:
4547
f.read(1)
4648
self.last_activity = time.time()
4749
except Exception as e:
48-
print "Error reading /dev/input/event0", e
50+
print("Error reading /dev/input/event0", e)
4951
continue
5052

5153
def get_volumio_status():
@@ -54,12 +56,22 @@ def get_volumio_status():
5456
data = json.loads(response.read())
5557
return data['state']['status'] == 'play'
5658
except Exception as e:
57-
print "Exception on volumio status get", e
59+
print("Exception on volumio status get", e)
60+
61+
def get_mpd_status():
62+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
63+
s.connect(("localhost", MPD_PORT))
64+
hello = socket.SocketIO(s,'rb').readline()
65+
if not hello.startswith(b"OK MPD"):
66+
return False
67+
s.sendall(b"status\n")
68+
data = s.recv(1024)
69+
return b"state: play" in data
5870

5971
def image_list_generator():
6072
while True:
6173
for root, subdirs, files in os.walk(IMAGE_DIR, topdown=False):
62-
print "Showing everything in", root, ", which has", len(files), "files"
74+
print("Showing everything in", root, ", which has", len(files), "files")
6375
for filename in files:
6476
if os.path.splitext(filename)[1].lower() in EXTENSIONS:
6577
yield os.path.join(root, filename)
@@ -82,7 +94,8 @@ def get_orientation(filename):
8294
if exif[orientation] == 8:
8395
return 90
8496
return 0
85-
except (AttributeError, KeyError, IndexError):
97+
except (AttributeError, KeyError, IndexError) as e:
98+
print("No orientiation", filename, e)
8699
return None
87100
finally:
88101
if image:
@@ -92,11 +105,11 @@ def display_next_image(filename):
92105
screen = display_enable()
93106

94107
angle = get_orientation(filename)
95-
print filename, angle
108+
print(filename, angle)
96109
screen_width = pygame.display.Info().current_w
97110
screen_height = pygame.display.Info().current_h
98111
picture = pygame.image.load(filename)
99-
if angle > 0:
112+
if angle and angle > 0:
100113
picture = pygame.transform.rotate(picture, angle)
101114

102115
pic_width = picture.get_width()
@@ -108,9 +121,11 @@ def display_next_image(filename):
108121
width = width * screen_height / height
109122
height = screen_height
110123

111-
picture = pygame.transform.smoothscale(picture, (width, height))
124+
picture = pygame.transform.smoothscale(picture, (int(width), int(height)))
112125

113-
position = ((screen_width - width) / 2, (screen_height - height) / 2)
126+
position = (
127+
int((screen_width - width) / 2),
128+
int((screen_height - height) / 2))
114129

115130
screen.fill((0, 0, 0))
116131
screen.blit(picture, position)
@@ -154,7 +169,7 @@ def display_off():
154169
display_off()
155170
continue
156171

157-
is_playing = get_volumio_status()
172+
is_playing = get_mpd_status()
158173
if is_playing:
159174
display_off()
160175
last_player_activity = time.time()

0 commit comments

Comments
 (0)