@@ -148,17 +148,24 @@ def _read_info(self, write_state=False) -> models.SourceInfo:
148
148
# HACK skip this read if it doesn't have state and trigger a new one by adding the state
149
149
i : dict = {}
150
150
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
152
155
153
156
if write_state or ("state" in i .keys () and i ["state" ] == "" ):
154
157
i ["state" ] = self .state
155
158
with open (f"{ self ._get_config_folder ()} /metadata.json" , 'w' , encoding = 'utf-8' ) as file :
156
159
json .dump (i , file )
157
160
return self ._cached_info
158
161
159
- self ._cached_info .img_url = self ._cached_info .img_url .replace ('http:' , 'https:' ) # HACK: hack to just replace with https
160
162
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
162
169
163
170
def info (self ) -> models .SourceInfo :
164
171
i = super ().info ()
@@ -175,56 +182,7 @@ def info(self) -> models.SourceInfo:
175
182
i .rating = models .PandoraRating .DEFAULT
176
183
177
184
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
+
228
186
def send_cmd (self , cmd ):
229
187
""" Pianobar's commands
230
188
cmd: Command string sent to pianobar's control fifo
0 commit comments