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

feat: formatting activity text #155

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions 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 jellyfin-rpc-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ serde_json = "1.0"

[dependencies.jellyfin-rpc]
version = "1.3.0"
#path = "../jellyfin-rpc"
path = "../jellyfin-rpc"

[dependencies.clap]
features = ["derive"]
Expand Down
79 changes: 24 additions & 55 deletions jellyfin-rpc-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ pub struct Jellyfin {
}

/// Contains configuration for Music/Movie display.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct DisplayOptions {
/// Display is where you tell the program what should be displayed.
pub display: Option<Vec<String>>,
/// Separator is what should be between the artist(s) and the `display` options.
pub separator: Option<String>,
pub state_text: Option<String>,
pub details_text: Option<String>,
pub image_text: Option<String>,
}
Comment on lines 46 to 52
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have doc lines /// and image_text should probably be large_image_text, there is another one called small_image_text that gets used when you pause content


/// Discord configuration
Expand Down Expand Up @@ -90,8 +90,8 @@ pub struct JellyfinBuilder {
pub url: String,
pub api_key: String,
pub username: Username,
pub music: Option<DisplayOptionsBuilder>,
pub movies: Option<DisplayOptionsBuilder>,
pub music: Option<DisplayOptions>,
pub movies: Option<DisplayOptions>,
pub blacklist: Option<Blacklist>,
pub self_signed_cert: Option<bool>,
pub show_simple: Option<bool>,
Expand All @@ -108,21 +108,6 @@ pub enum Username {
String(String),
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct DisplayOptionsBuilder {
pub display: Option<Display>,
pub separator: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum Display {
/// If the Display is a `Vec<String>`.
Vec(Vec<String>),
/// If the Display is a comma separated `String`.
String(String),
}

/// Blacklist MediaTypes and libraries.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Blacklist {
Expand Down Expand Up @@ -238,42 +223,24 @@ impl ConfigBuilder {
Username::String(username) => username.split(',').map(|u| u.to_string()).collect(),
};

let music_display;
let music_separator;
let mut music_state_text = None;
let mut music_details_text = None;
let mut music_image_text = None;

if let Some(music) = self.jellyfin.music {
if let Some(disp) = music.display {
music_display = Some(match disp {
Display::Vec(display) => display,
Display::String(display) => display.split(',').map(|d| d.to_string()).collect(),
})
} else {
music_display = None;
}

music_separator = music.separator;
} else {
music_display = None;
music_separator = None;
music_state_text = music.state_text;
music_details_text = music.details_text;
music_image_text = music.image_text;
}

let movie_display;
let movie_separator;
let mut movies_state_text = None;
let mut movies_details_text = None;
let mut movies_image_text = None;

if let Some(movies) = self.jellyfin.movies {
if let Some(disp) = movies.display {
movie_display = Some(match disp {
Display::Vec(display) => display,
Display::String(display) => display.split(',').map(|d| d.to_string()).collect(),
})
} else {
movie_display = None;
}

movie_separator = movies.separator;
} else {
movie_display = None;
movie_separator = None;
movies_state_text = movies.state_text;
movies_details_text = movies.details_text;
movies_image_text = movies.image_text;
}

let media_types;
Expand Down Expand Up @@ -326,12 +293,14 @@ impl ConfigBuilder {
api_key: self.jellyfin.api_key,
username,
music: DisplayOptions {
display: music_display,
separator: music_separator,
state_text: music_state_text,
details_text: music_details_text,
image_text: music_image_text,
},
movies: DisplayOptions {
display: movie_display,
separator: movie_separator,
state_text: movies_state_text,
details_text: movies_details_text,
image_text: movies_image_text,
},
blacklist: Blacklist {
media_types,
Expand Down
38 changes: 24 additions & 14 deletions jellyfin-rpc-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,34 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.large_image_text(format!("Jellyfin-RPC v{}", VERSION.unwrap_or("UNKNOWN")))
.imgur_urls_file_location(args.image_urls.unwrap_or(get_urls_path()?));

if let Some(display) = conf.jellyfin.music.display {
debug!("Found config.jellyfin.music.display");
builder.music_display(display);
if let Some(state_text) = conf.jellyfin.music.state_text {
debug!("Found config.jellyfin.music.state_text");
builder.music_state_text(state_text);
}

if let Some(separator) = conf.jellyfin.music.separator {
debug!("Found config.jellyfin.music.separator");
builder.music_separator(separator);
if let Some(details_text) = conf.jellyfin.music.details_text {
debug!("Found config.jellyfin.music.details_text");
builder.music_details_text(details_text);
}

if let Some(display) = conf.jellyfin.movies.display {
debug!("Found config.jellyfin.music.display");
builder.movies_display(display);
if let Some(image_text) = conf.jellyfin.music.image_text {
debug!("Found config.jellyfin.music.image_text");
builder.music_image_text(image_text);
}

if let Some(separator) = conf.jellyfin.movies.separator {
debug!("Found config.jellyfin.music.separator");
builder.movies_separator(separator);
if let Some(state_text) = conf.jellyfin.movies.state_text {
debug!("Found config.jellyfin.movies.state_text");
builder.movies_state_text(state_text);
}

if let Some(details_text) = conf.jellyfin.movies.details_text {
debug!("Found config.jellyfin.movies.details_text");
builder.movies_details_text(details_text);
}

if let Some(image_text) = conf.jellyfin.movies.image_text {
debug!("Found config.jellyfin.movies.image_text");
builder.movies_image_text(image_text);
}

if let Some(media_types) = conf.jellyfin.blacklist.media_types {
Expand Down Expand Up @@ -162,8 +172,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut currently_playing = String::new();

loop {
sleep(Duration::from_secs(args.wait_time as u64));

match client.set_activity() {
Ok(activity) => {
if activity.is_empty() && !currently_playing.is_empty() {
Expand Down Expand Up @@ -202,5 +210,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Reconnected!");
}
}

sleep(Duration::from_secs(args.wait_time as u64));
}
}
Loading
Loading