Skip to content

Commit

Permalink
fix(jellyfin): re-authentication
Browse files Browse the repository at this point in the history
/Session is now inaccessible without an api_key. this is just a stupid fix, but don't worry a fresh puddler will come
  • Loading branch information
Vernoxvernax committed Apr 12, 2024
1 parent 3c8139c commit 6c4e408
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
draft: false
prerelease: false
name: ${{ github.ref }}
name: ${{ github.ref_name }}
tag_name: ${{ github.ref }}
body_path: RECENT_CHANGES.md
files: puddler, puddler.exe
18 changes: 11 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ pub fn choose_config(server_kind: char, autologin: bool) -> Option<String> {


pub fn read_config(config_path_string: &String, autologin: bool) -> Result<(ConfigFile, ConfigFileRaw), (Option<ConfigFileRaw>, &str)> {
let file = fs::read_to_string(config_path_string).unwrap();
let file = if let Ok(file) = fs::read_to_string(config_path_string) {
file
} else {
return Err((None, "missing"));
};
let local_config_file: Result<ConfigFileRaw, serde_json::Error> = serde_json::from_str::<ConfigFileRaw>(&file);
match local_config_file {
Ok(a) => {
let user: &ConfigFileUser;
let media_server_name: &str = if a.emby {
let media_server_name: &str = if a.emby.unwrap() {
"Emby"
} else {
"Jellyfin"
Expand All @@ -104,7 +108,7 @@ pub fn read_config(config_path_string: &String, autologin: bool) -> Result<(Conf
};
if autologin {
Ok((ConfigFile {
emby: a.emby,
emby: a.emby.unwrap(),
server_name: server_name.to_string(),
ipaddress: a.ipaddress.clone(),
device_id: a.device_id.clone(),
Expand All @@ -119,7 +123,7 @@ pub fn read_config(config_path_string: &String, autologin: bool) -> Result<(Conf
if "yY".contains(input) {
user = a.user.first().unwrap();
Ok((ConfigFile {
emby: a.emby,
emby: a.emby.unwrap(),
server_name: server_name.to_string(),
ipaddress: a.ipaddress.clone(),
device_id: a.device_id.clone(),
Expand Down Expand Up @@ -161,7 +165,7 @@ pub fn read_config(config_path_string: &String, autologin: bool) -> Result<(Conf
println!();
user = a.user.get(index).unwrap();
Ok((ConfigFile {
emby: a.emby,
emby: a.emby.unwrap(),
server_name: server_name.to_string(),
ipaddress: a.ipaddress.clone(),
device_id: a.device_id.clone(),
Expand Down Expand Up @@ -199,14 +203,14 @@ pub fn write_config(config_path_string: String, config_file: &ConfigFile, other_
let mut user_vec: Vec<ConfigFileUser> = [config_file_user].to_vec();
user_vec.append(&mut other_users);
ConfigFileRaw {
emby: config_file.emby,
emby: Some(config_file.emby),
ipaddress: config_file.ipaddress.clone(),
device_id: config_file.device_id.clone(),
user: user_vec
}
} else {
ConfigFileRaw {
emby: config_file.emby,
emby: Some(config_file.emby),
ipaddress: config_file.ipaddress.clone(),
device_id: config_file.device_id.clone(),
user: [config_file_user].to_vec()
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ r" ____ __ ____
'e' | 'E' => {
return ExitCode::SUCCESS;
},
_ => (
)
_ => ()
};
} else {
print!(" [1] Stream from either Emby or Jellyfin\n [2] Change puddlers default settings\n [3] Display current settings\n [E] Exit puddler");
Expand All @@ -215,8 +214,7 @@ r" ____ __ ____
'e' | 'E' => {
return ExitCode::SUCCESS;
},
_ => (
)
_ => ()
};
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/mediaserver_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct ConfigFile {

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ConfigFileRaw {
pub emby: bool,
pub emby: Option<bool>,
pub ipaddress: String,
pub device_id: String,
pub user: Vec<ConfigFileUser>
Expand Down Expand Up @@ -161,6 +161,10 @@ pub fn adv_getch(allowed: &str, any_key: bool, timeout_secs: Option<u64>, messag
disable_raw_mode().unwrap();
println!("{}\n", ch);
return Some(ch);
} else if ch == '\n' && code == KeyCode::Enter {
disable_raw_mode().unwrap();
println!("\n");
return Some(ch);
}
}
writeln!(stdout).unwrap();
Expand Down Expand Up @@ -219,9 +223,13 @@ pub fn validate_settings(settings: &Settings) -> Option<HeadDict> {
'2'
}
},
Err(_no) => {
print!("What kind of server do you want to stream from?\n [1] Emby\n [2] Jellyfin");
getch("12")
Err((_no, "missing")) => {
eprintln!("{}: The default config specified in \"Puddler.toml\" doesn't exist.", "Error".to_string().red());
return None;
},
_ => {
eprintln!("{}: Unkown error.", "Error".to_string().red());
return None;
}
}
};
Expand Down Expand Up @@ -484,7 +492,7 @@ fn configure_new_server(media_server_name: &str) -> (String, String) {
print!("Please specify the IP-Address manually\n(don't forget to add ports if not running on 80/443!)\n: ");
stdout().flush().expect("Failed to flush stdout");
let mut ipaddress2 = String::new();
stdin().read_line( &mut ipaddress2).unwrap();
stdin().read_line(&mut ipaddress2).unwrap();
ipaddress = ipaddress2.trim().parse().unwrap();
print!("\nPlease enter a nickname for your media-server.\n(It's recommended to use a unique one)\n: ");
stdout().flush().expect("Failed to flush stdout");
Expand Down Expand Up @@ -638,7 +646,7 @@ fn reauthenticate(media_server_name: &str, media_server: &str, ipaddress: &Strin
}
} else {
println!("{}", "error!".to_string().red());
Err("This is not a valid emby/jellyfin webpage!".to_string())
Err("exp".to_string())
}
}
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ pub fn play(settings: &Settings, head_dict: &HeadDict, item: &mut Item) -> bool
let total_runtime: f64 = if settings.transcoding {
(item.RunTimeTicks.unwrap() as f64 - item.UserData.PlaybackPositionTicks as f64) / 10000000.0
} else {
if item.RunTimeTicks.is_none() {
eprintln!("Item doesn't have a runtime?");
return false;
}
item.RunTimeTicks.unwrap() as f64 / 10000000.0
};

Expand Down

1 comment on commit 6c4e408

@Vernoxvernax
Copy link
Owner Author

Choose a reason for hiding this comment

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

actually not just for jellyfin I just found out. Active authentication is now required for both types.

Please sign in to comment.