Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/tsukinaha/tsukimi into feat…
Browse files Browse the repository at this point in the history
…ure/win
  • Loading branch information
Kosette committed Apr 15, 2024
2 parents dad0d9b + 572b636 commit f0b45e2
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 31 deletions.
15 changes: 11 additions & 4 deletions resources/ui/item.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@
<property name="valign">fill</property>
<property name="reveal-child">False</property>
<child>
<object class="GtkPicture" id="backdrop">
<object class="AdwCarousel" id="carousel">
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="content-fit">cover</property>
<property name="hexpand">true</property>
<property name="height-request">700</property>
<property name="reveal-duration">3000</property>
<child>
<object class="GtkPicture" id="backdrop">
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="content-fit">cover</property>
<property name="hexpand">true</property>
<property name="height-request">700</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
15 changes: 11 additions & 4 deletions resources/ui/movie.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@
<property name="valign">fill</property>
<property name="reveal-child">False</property>
<child>
<object class="GtkPicture" id="backdrop">
<object class="AdwCarousel" id="carousel">
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="content-fit">cover</property>
<property name="hexpand">true</property>
<property name="height-request">700</property>
<property name="reveal-duration">3000</property>
<child>
<object class="GtkPicture" id="backdrop">
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="content-fit">cover</property>
<property name="hexpand">true</property>
<property name="height-request">700</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
12 changes: 6 additions & 6 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ pub fn remove(account: &Account) -> Result<(), Box<dyn std::error::Error>> {
let mut accounts: Accounts = load_cfgv2()?;
accounts.accounts.retain(|x| {
x.servername != account.servername
&& x.server != account.server
&& x.username != account.username
&& x.password != account.password
&& x.port != account.port
&& x.user_id != account.user_id
&& x.access_token != account.access_token
|| x.server != account.server
|| x.username != account.username
|| x.password != account.password
|| x.port != account.port
|| x.user_id != account.user_id
|| x.access_token != account.access_token
});
let toml = toml::to_string(&accounts).unwrap_or_else(|err| {
eprintln!("Error while serializing accounts: {:?}", err);
Expand Down
9 changes: 5 additions & 4 deletions src/ui/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn setthumbimage(id: String) -> Revealer {
revealer
}

pub fn setbackdropimage(id: String) -> Revealer {
pub fn setbackdropimage(id: String, tag: u8) -> Revealer {
let (sender, receiver) = async_channel::bounded::<String>(1);

let image = gtk::Picture::new();
Expand All @@ -125,7 +125,8 @@ pub fn setbackdropimage(id: String) -> Revealer {
.transition_duration(400)
.build();

let pathbuf = get_cache_dir(env::var("EMBY_NAME").unwrap()).join(format!("b{}.png", id));
let pathbuf =
get_cache_dir(env::var("EMBY_NAME").unwrap()).join(format!("b{}_{}.png", id, tag));
let idfuture = id.clone();
if pathbuf.exists() {
if image.file().is_none() {
Expand All @@ -136,7 +137,7 @@ pub fn setbackdropimage(id: String) -> Revealer {
crate::ui::network::runtime().spawn(async move {
let mut retries = 0;
while retries < 3 {
match crate::ui::network::get_backdropimage(id.clone()).await {
match crate::ui::network::get_backdropimage(id.clone(), tag).await {
Ok(id) => {
sender
.send(id.clone())
Expand All @@ -155,7 +156,7 @@ pub fn setbackdropimage(id: String) -> Revealer {

glib::spawn_future_local(clone!(@weak image,@weak revealer => async move {
while receiver.recv().await.is_ok() {
let path = get_cache_dir(env::var("EMBY_NAME").unwrap()).join(format!("b{}.png",idfuture));
let path = get_cache_dir(env::var("EMBY_NAME").unwrap()).join(format!("b{}_{}.png",idfuture,tag));
let file = gtk::gio::File::for_path(&path);
image.set_file(Some(&file));
revealer.set_reveal_child(true);
Expand Down
12 changes: 7 additions & 5 deletions src/ui/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ pub struct Item {
pub run_time_ticks: Option<u64>,
#[serde(rename = "Taglines")]
pub taglines: Option<Vec<String>>,
#[serde(rename = "BackdropImageTags")]
pub backdrop_image_tags: Option<Vec<String>>,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -553,13 +555,13 @@ pub async fn get_thumbimage(id: String) -> Result<String, Error> {
}
}

pub async fn get_backdropimage(id: String) -> Result<String, Error> {
pub async fn get_backdropimage(id: String,tag:u8) -> Result<String, Error> {
let server_info = config::set_config();

let result = client()
.get(&format!(
"{}:{}/emby/Items/{}/Images/Backdrop?maxHeight=1200",
server_info.domain, server_info.port, id
"{}:{}/emby/Items/{}/Images/Backdrop/{}?maxHeight=1200",
server_info.domain, server_info.port, id, tag
))
.send()
.await;
Expand All @@ -575,11 +577,11 @@ pub async fn get_backdropimage(id: String) -> Result<String, Error> {

let pathbuf = get_cache_dir(env::var("EMBY_NAME").unwrap());
if pathbuf.exists() {
fs::write(pathbuf.join(format!("b{}.png", id)), &bytes).unwrap();
fs::write(pathbuf.join(format!("b{}_{}.png", id, tag)), &bytes).unwrap();
} else {
fs::create_dir_all(&pathbuf).unwrap();

fs::write(pathbuf.join(format!("b{}.png", id)), &bytes).unwrap();
fs::write(pathbuf.join(format!("b{}_{}.png", id, tag)), &bytes).unwrap();
}
Ok(id)
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/widgets/account_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl AccountWindow {
obj.imp().spinner.set_visible(false);
obj.close();
let window = obj.root().and_downcast::<super::window::Window>().unwrap();
window.toast("Account added successfully");
window.set_servers();
}
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod imp {
result.parent_thumb_item_id.as_ref().expect("").clone(),
);
} else if result.resume_type == "Movie" {
imgbox = crate::ui::image::setbackdropimage(result.id.clone());
imgbox = crate::ui::image::setbackdropimage(result.id.clone(),0);
} else if result.parent_thumb_item_id.is_some() {
imgbox = crate::ui::image::setthumbimage(
result.series_id.as_ref().expect("").to_string(),
Expand Down
85 changes: 81 additions & 4 deletions src/ui/widgets/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ mod imp {
pub subdropdown: TemplateChild<gtk::DropDown>,
#[template_child]
pub backrevealer: TemplateChild<gtk::Revealer>,
#[template_child]
pub carousel: TemplateChild<adw::Carousel>,
pub selection: gtk::SingleSelection,
pub seasonselection: gtk::SingleSelection,
pub actorselection: gtk::SingleSelection,
Expand Down Expand Up @@ -221,7 +223,7 @@ impl ItemPage {
.nth(2)
.unwrap()
.join(format!(
"cache/{}/b{}.png",
"cache/{}/b{}_0.png",
env::var("EMBY_NAME").unwrap(),
id1
));
Expand All @@ -237,7 +239,7 @@ impl ItemPage {
}));
} else {
crate::ui::network::runtime().spawn(async move {
let id = crate::ui::network::get_backdropimage(id1)
let id = crate::ui::network::get_backdropimage(id1, 0)
.await
.expect("msg");
sender
Expand All @@ -254,8 +256,7 @@ impl ItemPage {
.ancestors()
.nth(2)
.unwrap()
.join(format!("cache/{}/b{}.png",env::var("EMBY_NAME").unwrap(), id2));

.join(format!("cache/{}/b{}_0.png",env::var("EMBY_NAME").unwrap(), id2));
if pathbuf.exists() {
let file = gtk::gio::File::for_path(&pathbuf);
backdrop.set_file(Some(&file));
Expand All @@ -267,6 +268,79 @@ impl ItemPage {
}));
}

pub fn add_backdrops(&self, image_tags: Vec<String>) {
println!("{:?}", image_tags);
let imp = self.imp();
let id = self.id();
let tags = image_tags.len();
let carousel = imp.carousel.get();
for tag_num in 1..=tags {
let id = id.clone();
let pathbuf = env::current_exe()
.unwrap()
.ancestors()
.nth(2)
.unwrap()
.join(format!(
"cache/{}/b{}_{}.png",
env::var("EMBY_NAME").unwrap(),
id,
tag_num
));
let (sender, receiver) = async_channel::bounded::<String>(1);
let id2 = id.clone();
if pathbuf.exists() {
glib::spawn_future_local(glib::clone!(@weak carousel =>async move {
let file = gtk::gio::File::for_path(&pathbuf);
let picture = gtk::Picture::builder()
.file(&file)
.halign(gtk::Align::Fill)
.valign(gtk::Align::Fill)
.content_fit(gtk::ContentFit::Cover)
.height_request(SETTINGS.background_height())
.build();
carousel.append(&picture);
}));
} else {
crate::ui::network::runtime().spawn(async move {
let id = crate::ui::network::get_backdropimage(id, tag_num as u8)
.await
.expect("msg");
sender
.send(id)
.await
.expect("The channel needs to be open.");
});
}
glib::spawn_future_local(glib::clone!(@weak carousel=>async move {
while receiver.recv().await.is_ok() {
let pathbuf = env::current_exe()
.unwrap()
.ancestors()
.nth(2)
.unwrap()
.join(format!(
"cache/{}/b{}_{}.png",
env::var("EMBY_NAME").unwrap(),
id2,
tag_num
));
if pathbuf.exists() {
let file = gtk::gio::File::for_path(&pathbuf);
let picture = gtk::Picture::builder()
.halign(gtk::Align::Fill)
.valign(gtk::Align::Fill)
.content_fit(gtk::ContentFit::Cover)
.height_request(SETTINGS.background_height())
.file(&file)
.build();
carousel.append(&picture);
}
}
}));
}
}

pub async fn setup_seasons(&self) {
let imp = self.imp();
let itemrevealer = imp.itemrevealer.get();
Expand Down Expand Up @@ -613,6 +687,9 @@ impl ItemPage {
obj.set_genres(genres);
}
overviewrevealer.set_reveal_child(true);
if let Some(image_tags) = item.backdrop_image_tags {
obj.add_backdrops(image_tags);
}
}
}));
}
Expand Down

0 comments on commit f0b45e2

Please sign in to comment.