1
- #! /usr/bin/python
1
+ #! /usr/bin/python3
2
2
3
3
import os
4
4
import subprocess
13
13
from PIL import Image , ExifTags
14
14
from collections import deque
15
15
16
+ os .environ ["DISPLAY" ] = ":0"
16
17
SHOW_AFTER_SECS = 60
17
18
NEXT_IMAGE_AFTER_SECS = 20
18
- IMAGE_DIR = "/home/volumio/Wallpaper /"
19
+ IMAGE_DIR = "/home/felix/wallpaper /"
19
20
EXTENSIONS = ['.jpg' , '.jpeg' , '.png' ]
20
21
VOLUMIO_STATUS_URL = "http://volumio.local:3000/api/v1/getSystemInfo"
21
22
DISPLAY_ON = False
23
+ MPD_PORT = 6600
22
24
23
25
import signal
24
26
def handler (signum , frame ):
@@ -40,12 +42,12 @@ def __init__(self):
40
42
def run (self ):
41
43
while True :
42
44
try :
43
- with open ("/dev/input/event0" , "r " ) as f :
45
+ with open ("/dev/input/event0" , "rb " ) as f :
44
46
while True :
45
47
f .read (1 )
46
48
self .last_activity = time .time ()
47
49
except Exception as e :
48
- print "Error reading /dev/input/event0" , e
50
+ print ( "Error reading /dev/input/event0" , e )
49
51
continue
50
52
51
53
def get_volumio_status ():
@@ -54,12 +56,22 @@ def get_volumio_status():
54
56
data = json .loads (response .read ())
55
57
return data ['state' ]['status' ] == 'play'
56
58
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
58
70
59
71
def image_list_generator ():
60
72
while True :
61
73
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" )
63
75
for filename in files :
64
76
if os .path .splitext (filename )[1 ].lower () in EXTENSIONS :
65
77
yield os .path .join (root , filename )
@@ -82,7 +94,8 @@ def get_orientation(filename):
82
94
if exif [orientation ] == 8 :
83
95
return 90
84
96
return 0
85
- except (AttributeError , KeyError , IndexError ):
97
+ except (AttributeError , KeyError , IndexError ) as e :
98
+ print ("No orientiation" , filename , e )
86
99
return None
87
100
finally :
88
101
if image :
@@ -92,11 +105,11 @@ def display_next_image(filename):
92
105
screen = display_enable ()
93
106
94
107
angle = get_orientation (filename )
95
- print filename , angle
108
+ print ( filename , angle )
96
109
screen_width = pygame .display .Info ().current_w
97
110
screen_height = pygame .display .Info ().current_h
98
111
picture = pygame .image .load (filename )
99
- if angle > 0 :
112
+ if angle and angle > 0 :
100
113
picture = pygame .transform .rotate (picture , angle )
101
114
102
115
pic_width = picture .get_width ()
@@ -108,9 +121,11 @@ def display_next_image(filename):
108
121
width = width * screen_height / height
109
122
height = screen_height
110
123
111
- picture = pygame .transform .smoothscale (picture , (width , height ))
124
+ picture = pygame .transform .smoothscale (picture , (int ( width ), int ( height ) ))
112
125
113
- position = ((screen_width - width ) / 2 , (screen_height - height ) / 2 )
126
+ position = (
127
+ int ((screen_width - width ) / 2 ),
128
+ int ((screen_height - height ) / 2 ))
114
129
115
130
screen .fill ((0 , 0 , 0 ))
116
131
screen .blit (picture , position )
@@ -154,7 +169,7 @@ def display_off():
154
169
display_off ()
155
170
continue
156
171
157
- is_playing = get_volumio_status ()
172
+ is_playing = get_mpd_status ()
158
173
if is_playing :
159
174
display_off ()
160
175
last_player_activity = time .time ()
0 commit comments