mirror of
https://github.com/LibreELEC/LibreELEC.tv
synced 2025-09-24 19:46:01 +07:00
122 lines
3.6 KiB
Diff
122 lines
3.6 KiB
Diff
commit 0623a601115f5c62d2b30645a85d9496546d5cba
|
|
Author: awiouy <awiouy@gmail.com>
|
|
Date: Tue Dec 3 23:21:35 2019 +0100
|
|
|
|
Notify Kodi
|
|
|
|
diff --git a/core/src/spotify_id.rs b/core/src/spotify_id.rs
|
|
index 1a5fcd2..c670977 100644
|
|
--- a/core/src/spotify_id.rs
|
|
+++ b/core/src/spotify_id.rs
|
|
@@ -8,6 +8,12 @@ pub enum SpotifyAudioType {
|
|
NonPlayable,
|
|
}
|
|
|
|
+impl fmt::Display for SpotifyAudioType {
|
|
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
+ write!(f, "{:?}", self)
|
|
+ }
|
|
+}
|
|
+
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct SpotifyId {
|
|
pub id: u128,
|
|
diff --git a/playback/src/config.rs b/playback/src/config.rs
|
|
index 0f71110..931167d 100644
|
|
--- a/playback/src/config.rs
|
|
+++ b/playback/src/config.rs
|
|
@@ -30,6 +30,7 @@ pub struct PlayerConfig {
|
|
pub bitrate: Bitrate,
|
|
pub normalisation: bool,
|
|
pub normalisation_pregain: f32,
|
|
+ pub notify_kodi: bool,
|
|
}
|
|
|
|
impl Default for PlayerConfig {
|
|
@@ -38,6 +39,7 @@ impl Default for PlayerConfig {
|
|
bitrate: Bitrate::default(),
|
|
normalisation: false,
|
|
normalisation_pregain: 0.0,
|
|
+ notify_kodi: false,
|
|
}
|
|
}
|
|
}
|
|
diff --git a/playback/src/player.rs b/playback/src/player.rs
|
|
index ef7484c..5b56782 100644
|
|
--- a/playback/src/player.rs
|
|
+++ b/playback/src/player.rs
|
|
@@ -4,7 +4,8 @@ use futures::{future, Async, Future, Poll, Stream};
|
|
use std;
|
|
use std::borrow::Cow;
|
|
use std::cmp::max;
|
|
-use std::io::{Read, Result, Seek, SeekFrom};
|
|
+use std::fs::OpenOptions;
|
|
+use std::io::{Read, Result, Seek, SeekFrom, Write};
|
|
use std::mem;
|
|
use std::thread;
|
|
use std::time::{Duration, Instant};
|
|
@@ -1415,6 +1416,12 @@ impl PlayerInternal {
|
|
}
|
|
}
|
|
|
|
+ fn notify_kodi(&mut self, event: String) {
|
|
+ // println!("Librespot fifo = {}", event);
|
|
+ let mut file = OpenOptions::new().write(true).open("/tmp/librespot").unwrap();
|
|
+ writeln!(&mut file, "{}", event).unwrap();
|
|
+ }
|
|
+
|
|
fn send_event(&mut self, event: PlayerEvent) {
|
|
let mut index = 0;
|
|
while index < self.event_senders.len() {
|
|
@@ -1425,6 +1432,17 @@ impl PlayerInternal {
|
|
}
|
|
}
|
|
}
|
|
+ if self.config.notify_kodi {
|
|
+ use PlayerEvent::*;
|
|
+ match event {
|
|
+ Paused { .. } => self.notify_kodi("Paused".to_string()),
|
|
+ Playing {track_id, .. } => self.notify_kodi(["Playing",
|
|
+ &track_id.audio_type.to_string(),
|
|
+ &track_id.to_base62()].join(" ")),
|
|
+ Stopped { .. } => self.notify_kodi("Stopped".to_string()),
|
|
+ _ => ()
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
fn load_track(
|
|
diff --git a/src/main.rs b/src/main.rs
|
|
index 70a2dff..3e63308 100644
|
|
--- a/src/main.rs
|
|
+++ b/src/main.rs
|
|
@@ -171,6 +171,11 @@ fn setup(args: &[String]) -> Setup {
|
|
"Pregain (dB) applied by volume normalisation",
|
|
"PREGAIN",
|
|
)
|
|
+ .optflag(
|
|
+ "",
|
|
+ "notify-kodi",
|
|
+ "Notify Kodi",
|
|
+ )
|
|
.optflag(
|
|
"",
|
|
"linear-volume",
|
|
@@ -277,6 +282,8 @@ fn setup(args: &[String]) -> Setup {
|
|
)
|
|
};
|
|
|
|
+ let notify_kodi = matches.opt_present("notify-kodi");
|
|
+
|
|
let session_config = {
|
|
let device_id = device_id(&name);
|
|
|
|
@@ -320,6 +327,7 @@ fn setup(args: &[String]) -> Setup {
|
|
.opt_str("normalisation-pregain")
|
|
.map(|pregain| pregain.parse::<f32>().expect("Invalid pregain float value"))
|
|
.unwrap_or(PlayerConfig::default().normalisation_pregain),
|
|
+ notify_kodi: notify_kodi,
|
|
}
|
|
};
|
|
|