[PR #1445] [MERGED] Shuffle tracks in place #1396

Closed
opened 2026-02-27 20:02:17 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/1445
Author: @photovoltex
Created: 1/18/2025
Status: Merged
Merged: 2/2/2025
Merged by: @photovoltex

Base: devHead: shuffle-in-place


📝 Commits (9)

  • c9d7a6d connect: add shuffle_vec.rs
  • 50e1bd5 connect: shuffle in place
  • 9aa806d add shuffle with seed option
  • f933e1d reduce complexity to add new metadata fields
  • 90dd971 add context index to metadata
  • 581e4fb use seed for shuffle
  • f57fdf9 add log for shuffle seed
  • f596b1c connect: use small_rng, derive Default
  • 4ddab70 Apply suggestions from code review

📊 Changes

12 files changed (+315 additions, -171 deletions)

View changed files

📝 connect/Cargo.toml (+1 -1)
📝 connect/src/context_resolver.rs (+11 -14)
📝 connect/src/lib.rs (+1 -0)
connect/src/shuffle_vec.rs (+117 -0)
📝 connect/src/spirc.rs (+10 -17)
📝 connect/src/state.rs (+3 -5)
📝 connect/src/state/context.rs (+51 -42)
📝 connect/src/state/handle.rs (+12 -6)
📝 connect/src/state/metadata.rs (+57 -59)
📝 connect/src/state/options.rs (+22 -17)
📝 connect/src/state/tracks.rs (+8 -9)
📝 connect/src/state/transfer.rs (+22 -1)

📄 Description

Follow up on https://github.com/librespot-org/librespot/pull/1356#issuecomment-2427617758

  • removes duplication of context tracks when shuffling
  • shuffle by a given seed, by that we can restore the shuffle state after a spontaneously disconnect

With the updated protobuf definitions, there is technically a given seed from the side of spotify when transfering playback. The given seed seems to be a hex value which we can convert into a u64 (which we currently use as seed value). But the shuffled queue isn't even similar to what spotify shuffles (which makes sense as they use a more preference base algorithm with less randomness). So when transferring we reshuffle unless we have a previous shuffle seed in the context metadata.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/1445 **Author:** [@photovoltex](https://github.com/photovoltex) **Created:** 1/18/2025 **Status:** ✅ Merged **Merged:** 2/2/2025 **Merged by:** [@photovoltex](https://github.com/photovoltex) **Base:** `dev` ← **Head:** `shuffle-in-place` --- ### 📝 Commits (9) - [`c9d7a6d`](https://github.com/librespot-org/librespot/commit/c9d7a6de471286ecca50972bda1936d93d312394) connect: add shuffle_vec.rs - [`50e1bd5`](https://github.com/librespot-org/librespot/commit/50e1bd537d70a9b61a64c11869a262825f58f3cd) connect: shuffle in place - [`9aa806d`](https://github.com/librespot-org/librespot/commit/9aa806db26829bc21a26cfb2d648153f7eabe5e1) add shuffle with seed option - [`f933e1d`](https://github.com/librespot-org/librespot/commit/f933e1d4a755fa7cd70c07abfbe2ab197fb9cdbe) reduce complexity to add new metadata fields - [`90dd971`](https://github.com/librespot-org/librespot/commit/90dd97103935ccc39e5c88338e72387b1357d079) add context index to metadata - [`581e4fb`](https://github.com/librespot-org/librespot/commit/581e4fb751f69e22173325870510c1b864cc1a5b) use seed for shuffle - [`f57fdf9`](https://github.com/librespot-org/librespot/commit/f57fdf951a0c6fc16f092f53e131c5358c102e7c) add log for shuffle seed - [`f596b1c`](https://github.com/librespot-org/librespot/commit/f596b1cdd211c7faf42cbed441bf1d435177d1c7) connect: use small_rng, derive Default - [`4ddab70`](https://github.com/librespot-org/librespot/commit/4ddab7006b384dd5fc5a5a965dbf8e95065ee047) Apply suggestions from code review ### 📊 Changes **12 files changed** (+315 additions, -171 deletions) <details> <summary>View changed files</summary> 📝 `connect/Cargo.toml` (+1 -1) 📝 `connect/src/context_resolver.rs` (+11 -14) 📝 `connect/src/lib.rs` (+1 -0) ➕ `connect/src/shuffle_vec.rs` (+117 -0) 📝 `connect/src/spirc.rs` (+10 -17) 📝 `connect/src/state.rs` (+3 -5) 📝 `connect/src/state/context.rs` (+51 -42) 📝 `connect/src/state/handle.rs` (+12 -6) 📝 `connect/src/state/metadata.rs` (+57 -59) 📝 `connect/src/state/options.rs` (+22 -17) 📝 `connect/src/state/tracks.rs` (+8 -9) 📝 `connect/src/state/transfer.rs` (+22 -1) </details> ### 📄 Description Follow up on https://github.com/librespot-org/librespot/pull/1356#issuecomment-2427617758 - removes duplication of context tracks when shuffling - shuffle by a given seed, by that we can restore the shuffle state after a spontaneously disconnect With the updated protobuf definitions, there is technically a given seed from the side of spotify when transfering playback. The given seed seems to be a hex value which we can convert into a u64 (which we currently use as seed value). But the shuffled queue isn't even similar to what spotify shuffles (which makes sense as they use a more preference base algorithm with less randomness). So when transferring we reshuffle unless we have a previous shuffle seed in the context metadata. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:02:17 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#1396
No description provided.