Skip to content

Commit f3ebfd0

Browse files
committed
feat(graphql): refactor device detection
1 parent b6cc01f commit f3ebfd0

32 files changed

+634
-210
lines changed

Cargo.lock

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,4 @@ futures-channel = "0.3.24"
191191
serde_json = "1.0.85"
192192
dirs = "4.0.0"
193193
spinners = "4.1.0"
194+
anyhow = "1.0.67"

addons/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ authors = ["Tsiry Sandratraina <tsiry.sndr@aol.com>"]
88
description = "The addons for the music player"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

11+
[dependencies.music-player-types]
12+
path = "../types"
13+
version = "0.1.1"
14+
15+
[dependencies.music-player-client]
16+
path = "../client"
17+
version = "0.1.1"
18+
1119
[dependencies]
20+
surf = "2.3.2"
21+
async-trait = "0.1.59"
22+
anyhow = "1.0.67"

addons/src/datpiff.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use anyhow::Error;
2+
13
use super::{Addon, StreamingAddon};
24

35
pub struct DatPiff {
@@ -47,7 +49,7 @@ impl Addon for DatPiff {
4749
}
4850

4951
impl StreamingAddon for DatPiff {
50-
fn stream(&self, url: &str) -> Result<(), Box<dyn std::error::Error>> {
52+
fn stream(&self, url: &str) -> Result<(), Error> {
5153
todo!("Implement DatPiff::stream");
5254
}
5355
}

addons/src/deezer.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use anyhow::Error;
2+
13
use super::{Addon, StreamingAddon};
24

35
pub struct Deezer {
@@ -47,7 +49,7 @@ impl Addon for Deezer {
4749
}
4850

4951
impl StreamingAddon for Deezer {
50-
fn stream(&self, url: &str) -> Result<(), Box<dyn std::error::Error>> {
52+
fn stream(&self, url: &str) -> Result<(), Error> {
5153
todo!("Implement Deezer::stream");
5254
}
5355
}

addons/src/kodi.rs

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
use anyhow::Error;
2+
3+
use async_trait::async_trait;
4+
use music_player_types::types::{Album, Artist, Device, Track};
5+
6+
use super::{Addon, Browseable, Player, StreamingAddon};
7+
8+
pub struct Client {
9+
pub host: String,
10+
pub port: u16,
11+
}
12+
13+
pub struct Kodi {
14+
name: String,
15+
version: String,
16+
author: String,
17+
description: String,
18+
enabled: bool,
19+
client: Option<Client>,
20+
}
21+
22+
impl Kodi {
23+
pub fn new() -> Self {
24+
Self {
25+
name: "Kodi".to_string(),
26+
version: "0.1.0".to_string(),
27+
author: "Tsiry Sandratraina".to_string(),
28+
description: "Kodi addon".to_string(),
29+
enabled: true,
30+
client: None,
31+
}
32+
}
33+
}
34+
35+
impl Addon for Kodi {
36+
fn name(&self) -> &str {
37+
&self.name
38+
}
39+
40+
fn version(&self) -> &str {
41+
&self.version
42+
}
43+
44+
fn author(&self) -> &str {
45+
&self.author
46+
}
47+
48+
fn description(&self) -> &str {
49+
&self.description
50+
}
51+
52+
fn enabled(&self) -> bool {
53+
self.enabled
54+
}
55+
56+
fn set_enabled(&mut self, enabled: bool) {
57+
self.enabled = enabled;
58+
}
59+
}
60+
61+
impl StreamingAddon for Kodi {
62+
fn stream(&self, url: &str) -> Result<(), Error> {
63+
todo!("Implement Kodi::stream");
64+
}
65+
}
66+
67+
#[async_trait]
68+
impl Browseable for Kodi {
69+
async fn albums(&mut self) -> Result<Vec<Album>, Error> {
70+
todo!()
71+
}
72+
73+
async fn artists(&mut self) -> Result<Vec<Artist>, Error> {
74+
todo!()
75+
}
76+
77+
async fn tracks(&mut self) -> Result<Vec<Track>, Error> {
78+
todo!()
79+
}
80+
81+
async fn album(&mut self, id: &str) -> Result<Album, Error> {
82+
todo!()
83+
}
84+
85+
async fn artist(&mut self, id: &str) -> Result<Artist, Error> {
86+
todo!()
87+
}
88+
89+
async fn track(&mut self, id: &str) -> Result<Track, Error> {
90+
todo!()
91+
}
92+
}
93+
94+
#[async_trait]
95+
impl Player for Kodi {
96+
async fn play(&mut self) -> Result<(), Error> {
97+
todo!()
98+
}
99+
100+
async fn pause(&mut self) -> Result<(), Error> {
101+
todo!()
102+
}
103+
104+
async fn stop(&mut self) -> Result<(), Error> {
105+
todo!()
106+
}
107+
108+
async fn next(&mut self) -> Result<(), Error> {
109+
todo!()
110+
}
111+
112+
async fn previous(&mut self) -> Result<(), Error> {
113+
todo!()
114+
}
115+
116+
async fn seek(&mut self, position: u32) -> Result<(), Error> {
117+
todo!()
118+
}
119+
}
120+
121+
impl From<Device> for Kodi {
122+
fn from(device: Device) -> Self {
123+
Self { ..Kodi::new() }
124+
}
125+
}

addons/src/lib.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
pub mod datpiff;
22
pub mod deezer;
33
pub mod genius;
4+
pub mod kodi;
45
pub mod local;
56
pub mod myvazo;
67
pub mod tononkira;
78

9+
use anyhow::Error;
10+
use async_trait::async_trait;
11+
use music_player_types::types::{Album, Artist, Track};
12+
813
pub trait Addon {
914
fn name(&self) -> &str;
1015
fn version(&self) -> &str;
@@ -15,9 +20,29 @@ pub trait Addon {
1520
}
1621

1722
pub trait StreamingAddon {
18-
fn stream(&self, url: &str) -> Result<(), Box<dyn std::error::Error>>;
23+
fn stream(&self, url: &str) -> Result<(), Error>;
1924
}
2025

2126
pub trait LyricsAddon {
2227
fn get_lyrics(&self, artist: &str, title: &str) -> Option<String>;
2328
}
29+
30+
#[async_trait]
31+
pub trait Browseable {
32+
async fn albums(&mut self) -> Result<Vec<Album>, Error>;
33+
async fn artists(&mut self) -> Result<Vec<Artist>, Error>;
34+
async fn tracks(&mut self) -> Result<Vec<Track>, Error>;
35+
async fn album(&mut self, id: &str) -> Result<Album, Error>;
36+
async fn artist(&mut self, id: &str) -> Result<Artist, Error>;
37+
async fn track(&mut self, id: &str) -> Result<Track, Error>;
38+
}
39+
40+
#[async_trait]
41+
pub trait Player {
42+
async fn play(&mut self) -> Result<(), Error>;
43+
async fn pause(&mut self) -> Result<(), Error>;
44+
async fn stop(&mut self) -> Result<(), Error>;
45+
async fn next(&mut self) -> Result<(), Error>;
46+
async fn previous(&mut self) -> Result<(), Error>;
47+
async fn seek(&mut self, position: u32) -> Result<(), Error>;
48+
}

0 commit comments

Comments
 (0)