mirror of
https://github.com/LibreELEC/LibreELEC.tv
synced 2025-09-24 19:46:01 +07:00
109 lines
3.1 KiB
Diff
109 lines
3.1 KiB
Diff
commit 10489ef0b9de4241eb8e007596f3d62616120545
|
|
Author: awiouy <awiouy@gmail.com>
|
|
Date: Fri May 29 07:40:19 2020 +0200
|
|
|
|
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 9d65042..6d098db 100644
|
|
--- a/playback/src/config.rs
|
|
+++ b/playback/src/config.rs
|
|
@@ -31,6 +31,7 @@ pub struct PlayerConfig {
|
|
pub normalisation: bool,
|
|
pub normalisation_pregain: f32,
|
|
pub gapless: bool,
|
|
+ pub notify_kodi: bool,
|
|
}
|
|
|
|
impl Default for PlayerConfig {
|
|
@@ -40,6 +41,7 @@ impl Default for PlayerConfig {
|
|
normalisation: false,
|
|
normalisation_pregain: 0.0,
|
|
gapless: true,
|
|
+ notify_kodi: false,
|
|
}
|
|
}
|
|
}
|
|
diff --git a/playback/src/player.rs b/playback/src/player.rs
|
|
index 2dd8f3b..67b3b28 100644
|
|
--- a/playback/src/player.rs
|
|
+++ b/playback/src/player.rs
|
|
@@ -1442,6 +1442,10 @@ impl PlayerInternal {
|
|
}
|
|
}
|
|
|
|
+ fn notify_kodi(&mut self, event: String) {
|
|
+ eprintln!("@{}", event);
|
|
+ }
|
|
+
|
|
fn send_event(&mut self, event: PlayerEvent) {
|
|
let mut index = 0;
|
|
while index < self.event_senders.len() {
|
|
@@ -1452,6 +1456,16 @@ impl PlayerInternal {
|
|
}
|
|
}
|
|
}
|
|
+ if self.config.notify_kodi {
|
|
+ use PlayerEvent::*;
|
|
+ match event {
|
|
+ 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 2efd62b..ecee2ff 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",
|
|
@@ -282,6 +287,8 @@ fn setup(args: &[String]) -> Setup {
|
|
)
|
|
};
|
|
|
|
+ let notify_kodi = matches.opt_present("notify-kodi");
|
|
+
|
|
let session_config = {
|
|
let device_id = device_id(&name);
|
|
|
|
@@ -325,6 +332,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,
|
|
}
|
|
};
|
|
|