Skip to content

Commit

Permalink
adding 'append_track_to_playlist' and 'move_track_within_playlist' fo…
Browse files Browse the repository at this point in the history
…r issue #195
  • Loading branch information
KoljaWindeler committed Jan 15, 2024
1 parent c55f08f commit e8d93fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom_components/ytube_music_player/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
SERIVCE_CALL_DEBUG_AS_ERROR = "debug_as_error"
SERVICE_CALL_LIKE_IN_NAME = "like_in_name"
SERVICE_CALL_GOTO_TRACK = "goto_track"
SERVICE_CALL_MOVE_TRACK = "move_track_within_playlist"
SERVICE_CALL_APPEND_TRACK = "append_track_to_playlist"


CONF_RECEIVERS = 'speakers' # list of speakers (media_players)
Expand Down
23 changes: 23 additions & 0 deletions custom_components/ytube_music_player/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,29 @@ async def async_call_method(self, command=None, parameters=None):
self._shuffle = False # set false, otherwise async_get_track will override next_track
await self.async_get_track()
self._shuffle = prev_shuffle # restore
elif(command == SERVICE_CALL_APPEND_TRACK):
self.log_me('debug', "Adding track " + str(parameters[0]) + " at position " + str(parameters[1]))
if(len(parameters)==2 and parameters[1].isnumeric()):
add_track = await self.hass.async_add_executor_job(lambda: self._api.get_song(parameters[0], self._signatureTimestamp)) # no limit needed
else:
self.log_me('debug', str(parameters[1]) + " is not numeric, or not exactly 2 parameters given")
# how to check
# I don't know why, but the format of get_song is very differnt, so we fix at least author and thumbnail to make it lookalike
add_track['videoDetails']['artists'] = [{'name': add_track['videoDetails']['author'], 'id': ''}]
add_track['videoDetails']['thumbnails'] = add_track['videoDetails']['thumbnail']['thumbnails']
self._tracks.insert(int(parameters[1]),add_track['videoDetails'])

await self._tracks_to_attribute()
elif(command == SERVICE_CALL_MOVE_TRACK):
self.log_me('debug', "Moving track " + str(parameters[0]) + " to position " + str(parameters[1]))
if(parameters[0].isnumeric() and (parameters[1].isnumeric() or parameters[1]=="-1")):
add_track = self._tracks[int(parameters[0])]
self._tracks.remove(add_track)
if(parameters[1].isnumeric()):
self._tracks.insert(int(parameters[1]),add_track)
await self._tracks_to_attribute()
else:
self.log_me('debug', str(parameters[0]) + " or " + str(parameters[1]) + " is not numeric, not moving tracks")
else:
self.log_me('error', "Command " + str(command) + " not implimented")
self.log_me('debug', "[E] async_call_method")
Expand Down

0 comments on commit e8d93fe

Please sign in to comment.