Skip to content

Commit 2b1e355

Browse files
committed
first completely functional version
1 parent 05f6391 commit 2b1e355

File tree

4 files changed

+16
-69
lines changed

4 files changed

+16
-69
lines changed

amplipi/streams/base_streams.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,8 @@ def on_modified(_, event):
166166
# logger.debug(f'mute timer cancelled for {self.name}')
167167
self.unmute()
168168

169-
self._observer = Observer()
170-
# self._fs_event_handler = FileSystemEventHandler()
171169
self._fs_event_handler = handler()
172-
# self._fs_event_handler.on_modified = lambda _: self._read_info
170+
self._observer = Observer()
173171
self._observer.schedule(self._fs_event_handler, metadata_path)
174172
self._observer.start()
175173

@@ -181,10 +179,11 @@ def _stop_info_watcher(self):
181179

182180
if self._watch_metadata:
183181
if self._observer:
184-
self._observer.stop()
185-
self._observer.join()
182+
logger.debug(f' observer stopped for {self.name}')
183+
del self._observer
186184
self._observer = None
187185
self._fs_event_handler = None
186+
logger.debug(" metadata watcher stopped")
188187

189188
def restart(self):
190189
"""Reset this stream by disconnecting and reconnecting"""

amplipi/streams/file_player.py

-10
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,3 @@ def disconnect(self):
120120
self.bkg_thread.join()
121121
self._disconnect()
122122
self.proc = None
123-
124-
# def info(self) -> models.SourceInfo:
125-
# source = models.SourceInfo(
126-
# name=self.full_name(),
127-
# state=self.state,
128-
# img_url='static/imgs/plexamp.png',
129-
# type=self.stream_type
130-
# )
131-
# source.supported_cmds = self.supported_cmds
132-
# return source

amplipi/streams/pandora.py

+11-53
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,24 @@ def _read_info(self, write_state=False) -> models.SourceInfo:
148148
# HACK skip this read if it doesn't have state and trigger a new one by adding the state
149149
i: dict = {}
150150
with open(f"{self._get_config_folder()}/metadata.json", 'r', encoding='utf-8') as file:
151-
i = json.load(file)
151+
try: # try/catch because the file may be empty due to the way the eventtcmd script is written
152+
i = json.load(file)
153+
except json.JSONDecodeError:
154+
return self._cached_info
152155

153156
if write_state or ("state" in i.keys() and i["state"] == ""):
154157
i["state"] = self.state
155158
with open(f"{self._get_config_folder()}/metadata.json", 'w', encoding='utf-8') as file:
156159
json.dump(i, file)
157160
return self._cached_info
158161

159-
self._cached_info.img_url = self._cached_info.img_url.replace('http:', 'https:') # HACK: hack to just replace with https
160162

161-
return super()._read_info()
163+
super()._read_info()
164+
165+
if self._cached_info.img_url is not None:
166+
self._cached_info.img_url = self._cached_info.img_url.replace('http:', 'https:') # HACK: hack to just replace with https
167+
168+
return self._cached_info
162169

163170
def info(self) -> models.SourceInfo:
164171
i = super().info()
@@ -175,56 +182,7 @@ def info(self) -> models.SourceInfo:
175182
i.rating = models.PandoraRating.DEFAULT
176183

177184
return i
178-
179-
# def info(self) -> models.SourceInfo:
180-
# src_config_folder = f'{utils.get_folder("config")}/srcs/v{self.vsrc}'
181-
# loc = f'{src_config_folder}/.config/pianobar/currentSong'
182-
# source = models.SourceInfo(
183-
# name=self.full_name(),
184-
# state=self.state,
185-
# supported_cmds=list(self.supported_cmds.keys()),
186-
# img_url='static/imgs/pandora.png',
187-
# type=self.stream_type
188-
# )
189-
190-
# if len(self.stations) == 0:
191-
# self.load_stations()
192-
193-
# try:
194-
# with open(loc, 'r', encoding='utf-8') as file:
195-
# for line in file.readlines():
196-
# line = line.strip()
197-
# if line:
198-
# data = line.split(',,,')
199-
# if self.track != data[1]: # When song changes, stop inverting state
200-
# self.invert_liked_state = False
201-
# source.state = self.state
202-
# source.artist = data[0]
203-
# source.track = data[1]
204-
# self.track = data[1]
205-
# source.album = data[2]
206-
# source.img_url = data[3].replace('http:', 'https:') # HACK: kind of a hack to just replace with https
207-
# initial_rating = models.PandoraRating(int(data[4]))
208-
209-
# source.rating = initial_rating
210-
211-
# # Pianobar doesn't update metadata after a song starts playing
212-
# # so when you like a song you have to change the state manually until next song
213-
# if self.invert_liked_state:
214-
# if int(data[4]) == models.PandoraRating.DEFAULT.value:
215-
# source.rating = models.PandoraRating.LIKED
216-
# elif int(data[4]) == models.PandoraRating.LIKED.value:
217-
# source.rating = models.PandoraRating.DEFAULT
218-
219-
# source.station = data[5]
220-
# return source
221-
# except Exception:
222-
# pass
223-
# # logger.error('Failed to get currentSong - it may not exist: {}'.format(e))
224-
# # TODO: report the status of pianobar with station name, playing/paused, song info
225-
# # ie. Playing: "Cameras by Matt and Kim" on "Matt and Kim Radio"
226-
# return source
227-
185+
228186
def send_cmd(self, cmd):
229187
""" Pianobar's commands
230188
cmd: Command string sent to pianobar's control fifo

streams/eventcmd.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ case "$1" in
4343

4444
echo -n "${artist},,,${title},,,${album},,,${coverArt},,,${rating},,,${stationName}" > "$currentSong"
4545
truncate -s 0 $metadata
46-
printf "{\n\"artist\":\"${artist}\",\n\"track\":\"${title}\",\n\"album\":\"${album}\",\n\"img-url\":\"${coverArt}\",\n\"rating\":${rating},\n\"station\":\"${stationName}\",\n\"state\":\"\"\n}" >> "$metadata"
46+
printf "{\n\"artist\":\"${artist}\",\n\"track\":\"${title}\",\n\"album\":\"${album}\",\n\"img_url\":\"${coverArt}\",\n\"rating\":${rating},\n\"station\":\"${stationName}\",\n\"state\":\"\"\n}" >> "$metadata"
4747

4848
stationList
4949
;;

0 commit comments

Comments
 (0)