Skip to content
Snippets Groups Projects
Commit 0fe7879b authored by Robert Goldmann's avatar Robert Goldmann
Browse files

SpotifyRecorder: handle unplayable songs

parent aeb63f39
Branches
Tags
No related merge requests found
...@@ -111,7 +111,7 @@ class SpotifyRecorder: ...@@ -111,7 +111,7 @@ class SpotifyRecorder:
recorder = SpotifyAudioRecorder(self._audioDeviceName, filePath) recorder = SpotifyAudioRecorder(self._audioDeviceName, filePath)
with recorder.record(): with recorder.record():
self.__play_track(deviceId, track['track']['uri']) self.__play_track(deviceId, track['track']['uri'])
timeWaitedForPlaying = self.__wait_for_track_playing() timeWaitedForPlaying = self.__wait_for_track_playing(track['track']['id'])
self.__wait_for_track_end(track, timeWaitedForPlaying) self.__wait_for_track_end(track, timeWaitedForPlaying)
recordedTracks.append(track['track']['name']) recordedTracks.append(track['track']['name'])
...@@ -182,15 +182,19 @@ class SpotifyRecorder: ...@@ -182,15 +182,19 @@ class SpotifyRecorder:
def __play_track(self, deviceId: str, trackUri: str): def __play_track(self, deviceId: str, trackUri: str):
self._spotify.start_playback(device_id=deviceId, uris=[trackUri]) self._spotify.start_playback(device_id=deviceId, uris=[trackUri])
def __wait_for_track_playing(self) -> float: def __wait_for_track_playing(self, expectedTrackId: str) -> float:
LOGGER.debug(f'\t\tWait for track to start playing...') LOGGER.debug(f'\t\tWait for track to start playing...')
startTime = time.time() startTime = time.time()
duration = 0 duration = 0
while time.time() - startTime < self._MAX_WAIT_TIME_TRACK_STARTING_IN_S: while time.time() - startTime < self._MAX_WAIT_TIME_TRACK_STARTING_IN_S:
if self._spotify.current_playback()['is_playing']: currentPlayback = self._spotify.current_playback()
if currentPlayback['is_playing']:
duration = time.time() - startTime duration = time.time() - startTime
LOGGER.debug(f'\t\tTrack started playing after {duration:.1f}s') if currentPlayback['item']['id'] == expectedTrackId:
break LOGGER.debug(f'\t\tTrack started playing after {duration:.1f}s')
break
else:
raise RuntimeError('Wrong track started playing')
time.sleep(1) time.sleep(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment