Skip to content

Commit

Permalink
Fix sorting issues with unplayed tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
nledford committed Jun 23, 2024
1 parent 7563a49 commit 8d83baa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hitomi"
version = "0.3.4"
version = "0.3.5"
description = "Builds and updates custom playlists on a Plex server"
authors = ["Nathaniel Ledford <nate@nateledford.com>"]
homepage = "https://github.com/nledford/hitomi"
Expand Down
6 changes: 5 additions & 1 deletion src/plex/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct Track {
pub index: Option<i32>,
pub parent_index: i32,
// rating_count: Option<i32>,
// user_rating: f32,
user_rating: f32,
view_count: Option<i32>,
last_viewed_at: Option<i64>,
// pub last_rated_at: Option<i64>,
Expand Down Expand Up @@ -149,6 +149,10 @@ impl Track {
pub fn never_played(&self) -> bool {
self.plays() == 0 || self.last_played() == 0
}

pub fn rating(&self) -> i32 {
(self.user_rating / 2_f32).floor() as i32
}
}

impl Display for Track {
Expand Down
8 changes: 7 additions & 1 deletion src/profiles/profile_section.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::Reverse;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};

Expand Down Expand Up @@ -331,9 +332,14 @@ impl ProfileSection {
}

fn sort_tracks(&mut self) {
if self.is_unplayed() {
self.tracks
.sort_by_key(|t| (Reverse(t.rating()), t.plays(), t.last_played()))
}
if self.is_least_played() {
self.tracks.sort_by_key(|t| (t.plays(), t.last_played()))
} else if self.is_oldest() {
}
if self.is_oldest() {
self.tracks.sort_by_key(|t| (t.last_played(), t.plays()))
}
}
Expand Down

0 comments on commit 8d83baa

Please sign in to comment.