Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort songs in playlist by the time they were added #1576

Open
jacobvd0 opened this issue Nov 7, 2022 · 12 comments
Open

Sort songs in playlist by the time they were added #1576

jacobvd0 opened this issue Nov 7, 2022 · 12 comments

Comments

@jacobvd0
Copy link

jacobvd0 commented Nov 7, 2022

Description
Sorting playlists in order of the time they were added (like spotify).

Example
Spotify has this with playlists.

@phanan
Copy link
Member

phanan commented Nov 7, 2022

Apart from "Spotify has it," what would be a reason for this "feature"?

@jacobvd0
Copy link
Author

jacobvd0 commented Nov 7, 2022 via email

@phanan
Copy link
Member

phanan commented Nov 7, 2022

I think the better way (which Spotify supports btw) is to be able to re-order the songs in playlists. This, however, isn't too high on my list.

@jacobvd0
Copy link
Author

jacobvd0 commented Nov 7, 2022 via email

@bilogic
Copy link

bilogic commented Jul 2, 2023

Is there a way to rearrange the order of songs in a playlist?

@Mark-Shternberg
Copy link

Mark-Shternberg commented Aug 15, 2023

This is really a very important thing that greatly affects on the UI convenience

@TylerCode
Copy link

For now I've been using "Shuffle" on the Favorites, but I would like this feature since usually the songs I've just added to the favorites are the current "fire" I'm listening to so I want to listen to them either shuffled or in the order they were added.

@eylvisaker
Copy link

Apart from "Spotify has it," what would be a reason for this "feature"?

DJ'ing. From time to time, I DJ dance events. In this scenario, being able to replay a playlist in the order that I curated it is critical. I've been doing it in iTunes, and I want to get rid of it for obvious reasons. So I wrote some code to parse my iTunes library and upload it to my Koel instance, but since Koel doesn't preserve the ordering of songs, it's not fit for this purpose.

@phanan
Copy link
Member

phanan commented Jan 17, 2024 via email

@caendesilva
Copy link

Good point. I will include it in a future version.

So surprised to find that there is no way to order songs! The way Spotify has it is perfect, default to sort by date added, but allow reorder (so implementation-wise, the song order would default to an int based on the count songs in the playlist).

@phanan
Copy link
Member

phanan commented Feb 5, 2024 via email

@caendesilva
Copy link

This feature will land in the next version :)

Awesome! I made an embarrassingly crude patch for myself until then, if anyone dares to use it

public function index(Playlist $playlist)
   {
       $this->authorize('own', $playlist);

       // Get the raw songs data from the playlist as an array
       $rawSongsData = DB::table('songs')
           ->select('songs.*', 'playlist_song.order')
           ->join('playlist_song', 'songs.id', '=', 'playlist_song.song_id')
           ->join('playlists', 'playlists.id', '=', 'playlist_song.playlist_id')
           ->where('playlists.id', $playlist->id)
           ->orderBy('playlist_song.order')
           ->orderBy('songs.title')
           ->get()
           ->toArray();

       // Transform raw data into Song model instances
       $rawSongs = collect($rawSongsData)->map(function ($rawSong) {
           return new Song((array) $rawSong);
       });
   
       // Reorder the raw songs collection based on the 'order' value
       $orderedSongs = $rawSongs->sortBy('order');

       // Override the track value with the 'order' value
       $orderedSongs->each(function ($song, $index) {
           $song->track = $index + 1; // Assuming 1-based track numbering
       });

       // Transform the ordered collection into SongResource
       $return = SongResource::collection($orderedSongs);

       return $return;
   }
Schema::table('playlist_song', function (Blueprint $table) {
      $table->integer('order')->default(0);
  });

Still needs to have the priority set when adding to playlist, and also support reorder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants