Skip to content

Commit

Permalink
fix backtype computation
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinaha committed Oct 23, 2024
1 parent 975581f commit a9dd2ec
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
12 changes: 7 additions & 5 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use serde_json::{
Value,
};
use tracing::{
info,
warn,
info, warn
};
use url::Url;
use uuid::Uuid;
Expand Down Expand Up @@ -261,8 +260,11 @@ impl EmbyClient {
let request = self.prepare_request(Method::GET, path, params)?;
let res = self.send_request(request).await?.error_for_status()?;

let json = res.json().await?;
Ok(json)
let res_text = res.text().await?;
match serde_json::from_str(&res_text) {
Ok(json) => Ok(json),
Err(e) => Err(anyhow!("Failed to parse JSON {}: {}", e, res_text)),
}
}

pub async fn request_picture(&self, path: &str, params: &[(&str, &str)]) -> Result<Response> {
Expand Down Expand Up @@ -723,7 +725,7 @@ impl EmbyClient {
BackType::Back => "Sessions/Playing/Progress".to_string(),
};
let params = [("reqformat", "json")];
let body = json!({"VolumeLevel":100,"NowPlayingQueue":[],"IsMuted":false,"IsPaused":false,"MaxStreamingBitrate":2147483647,"RepeatMode":"RepeatNone","PlaybackStartTimeTicks":back.start_tick,"SubtitleOffset":0,"PlaybackRate":1,"PositionTicks":back.tick,"SubtitleStreamIndex":0,"AudioStreamIndex":1,"PlayMethod":"DirectStream","PlaySessionId":back.playsessionid,"MediaSourceId":back.mediasourceid,"PlaylistIndex":0,"PlaylistLength":1,"CanSeek":true,"ItemId":back.id});
let body = json!({"VolumeLevel":100,"NowPlayingQueue":[],"IsMuted":false,"IsPaused":false,"MaxStreamingBitrate":2147483647,"RepeatMode":"RepeatNone","PlaybackStartTimeTicks":back.start_tick,"SubtitleOffset":0,"PlaybackRate":1,"PositionTicks":back.tick,"PlayMethod":"DirectStream","PlaySessionId":back.playsessionid,"MediaSourceId":back.mediasourceid,"PlaylistIndex":0,"PlaylistLength":1,"CanSeek":true,"ItemId":back.id,"Shuffle":false});
self.post(&path, &params, body).await?;
Ok(())
}
Expand Down
14 changes: 11 additions & 3 deletions src/ui/mpv/mpvglarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ use super::tsukimi_mpv::{
use crate::client::client::EMBY_CLIENT;

mod imp {
use std::thread::JoinHandle;

use gtk::{
gdk::GLContext,
glib,
prelude::*,
subclass::prelude::*,
};
use tracing::error;
use once_cell::sync::OnceCell;

use crate::ui::mpv::tsukimi_mpv::{
TsukimiMPV,
Expand All @@ -36,6 +38,7 @@ mod imp {
#[derive(Default)]
pub struct MPVGLArea {
pub mpv: TsukimiMPV,
pub mpv_event_loop: OnceCell<JoinHandle<()>>
}

// The central trait for subclassing a GObject
Expand All @@ -51,6 +54,12 @@ mod imp {
fn constructed(&self) {
self.parent_constructed();
}

fn dispose(&self) {
if let Some(mpv) = self.mpv.mpv.lock().ok() {
drop(mpv);
}
}
}

impl WidgetImpl for MPVGLArea {
Expand All @@ -59,8 +68,7 @@ mod imp {
let obj = self.obj();
obj.make_current();
let Some(gl_context) = self.obj().context() else {
error!("Failed to get GLContext");
return;
panic!("Failed to get GLContext");
};

self.mpv.connect_render_update(gl_context);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/mpv/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl MPVPage {
self.imp().video_version_matcher.replace(matcher);
self.imp().current_video.replace(Some(item));
self.imp().current_episode_list.replace(episode_list);
self.imp().back.replace(back);
spawn_g_timeout(glib::clone!(
#[weak(rename_to = obj)]
self,
Expand All @@ -321,7 +322,6 @@ impl MPVPage {
imp.title_content.set_label(&name);
imp.suburl.replace(suburi.map(|suburi| EMBY_CLIENT.get_streaming_url(&suburi)));
imp.video.play(&url, percentage);
imp.back.replace(back);
}
));
}
Expand Down Expand Up @@ -518,7 +518,7 @@ impl MPVPage {
playsessionid: playback.play_session_id,
mediasourceid: media_source_id.to_string(),
tick: 0,
start_tick: 0,
start_tick: glib::DateTime::now_local().unwrap().to_unix() as u64,
};

self.play(&url, suburi.as_deref(), item.clone(), video_list, Some(back), 0.0, None);
Expand Down Expand Up @@ -932,7 +932,7 @@ impl MPVPage {
let back = self.imp().back.borrow();

// close window when vo=gpu-next will set position to 0, so we need to ignore it
if position < &9.0 && (backtype != BackType::Start || backtype != BackType::Stop) {
if position < &9.0 && (backtype != BackType::Start && backtype != BackType::Stop) {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/ui/mpv/tsukimi_mpv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
atomic::AtomicU32,
Arc,
Mutex,
},
}, thread::JoinHandle,
};

use gtk::gdk::GLContext;
Expand Down Expand Up @@ -350,9 +350,9 @@ impl TsukimiMPV {
}
}

pub fn process_events(&self) {
pub fn process_events(&self) -> JoinHandle<()> {
let Some(mpv) = self.mpv() else {
return;
panic!("Failed to lock MPV for event loop");
};
let mut event_context = EventContext::new(mpv.ctx);
event_context.disable_deprecated_events().expect("failed to disable deprecated events.");
Expand Down Expand Up @@ -443,7 +443,7 @@ impl TsukimiMPV {
None => {}
};
})
.expect("Failed to spawn mpv event loop");
.expect("Failed to spawn mpv event loop")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/provider/tu_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl TuItem {
id: item.id(),
playsessionid: playback.play_session_id,
mediasourceid: playback.media_sources[0].id.clone(),
start_tick: item.playback_position_ticks(),
start_tick: glib::DateTime::now_local().unwrap().to_unix() as u64,
};
window.play_media(
url.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ impl ItemPage {
playsessionid: self.play_session_id(),
mediasourceid: media_source_id.to_string(),
tick: item.playback_position_ticks(),
start_tick: item.playback_position_ticks(),
start_tick: glib::DateTime::now_local().unwrap().to_unix() as u64,
};

let sub_url = if let Some(sub_object) =
Expand Down

0 comments on commit a9dd2ec

Please sign in to comment.